diff --git a/backend.dockerfile b/backend.dockerfile index 177094a..285710c 100644 --- a/backend.dockerfile +++ b/backend.dockerfile @@ -65,4 +65,4 @@ COPY docker/php/.htaccess /var/www/html/ RUN chown -R www-data:www-data /var/www/html -CMD /init-scripts/setup.sh \ No newline at end of file +CMD /init-scripts/setup.sh diff --git a/backend/.htaccess b/backend/.htaccess new file mode 100644 index 0000000..9308912 --- /dev/null +++ b/backend/.htaccess @@ -0,0 +1,13 @@ +# BEGIN WordPress + +RewriteEngine On +RewriteBase / +RewriteRule ^index\.php$ - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . /index.php [L] +RewriteCond %{HTTP:Authorization} ^(.*) +RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1] + +SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 +# END WordPress diff --git a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php index 461a51d..5a8d493 100644 --- a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php +++ b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-delivery-process-api.php @@ -51,10 +51,10 @@ class Wiass_REST_Delivery_Process_API { foreach ($entries as $entry) { $step = gravity_flow()->get_step( $entry['workflow_step'] ); $data[] = array( - 'idOrder' => $entry['wiaas_delivery_order_id'], - 'orderNumber' => $entry['wiaas_delivery_order_id'], + 'order_id' => $entry['wiaas_delivery_order_id'], + 'order_number' => $entry['wiaas_delivery_order_id'], 'status' => $entry['workflow_final_status'], - 'stepAction' => $step->get_name(), + 'step_action' => $step->get_name(), ); } diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-customer.php b/backend/app/plugins/wiaas/includes/class-wiaas-customer.php deleted file mode 100644 index 3fc2635..0000000 --- a/backend/app/plugins/wiaas/includes/class-wiaas-customer.php +++ /dev/null @@ -1,25 +0,0 @@ - 'wiaas_db_update_enable_product_by_user_role', '20180801222206' => 'wiaas_db_update_setup_gravity', '20180802222206' => 'wiaas_db_update_add_delivery_process_forms', - '20180808222206' => 'wiaas_db_update_setup_customer_capabilities' + '20180807222206' => 'wiaas_db_update_setup_customer_capabilities' ); public static function execute() { diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php b/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php index 7c4c9e3..c3a526c 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php @@ -159,4 +159,4 @@ class Wiaas_Delivery_Process { } } -add_action( 'gravityflow_loaded', array('Wiaas_Delivery_Process', 'init') ); \ No newline at end of file +add_action( 'gravityflow_loaded', array('Wiaas_Delivery_Process', 'init') ); diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-order.php b/backend/app/plugins/wiaas/includes/class-wiaas-order.php index fcf8db7..e3c5c9a 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-order.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-order.php @@ -10,18 +10,27 @@ class Wiaas_Order { private static $object_order_type = 'shop_order'; - private static $wiaas_order_status = array( - - ); - public static function init() { - add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 10, 3); - add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' )); add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4); + + add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 10, 3); + + add_filter('woocommerce_rest_orders_prepare_object_query', array( __CLASS__, 'wiaas_prepare_rest_orders_query'), 10, 2); + + add_filter('wc_order_statuses', array( __CLASS__, 'wiaas_order_statuses')); } + /** + * Assignees order to corresponding user organization when order is created. + * + * @param $order_id + */ + public static function assign_order_to_organization($order_id) { + $user = wp_get_current_user(); + Wiaas_User_Organization::assign_post_to_user_organization($order_id, $user->ID); + } /** * Checks if current user has access to requested order/{orderId} via woocommerce REST API. @@ -37,25 +46,36 @@ class Wiaas_Order { * @return bool */ public static function check_order_access($permission, $context, $object_id, $post_type) { - if ($post_type === 'shop_order' && $object_id !== 0) { + if ($post_type === self::$object_order_type && $object_id !== 0) { return Groups_Post_Access::user_can_read_post($object_id); } - #return Groups_Post_Access::user_can_read_post($object_id); return $permission; } /** - * Assignees order to corresponding user organization when order is created. + * Handles custom wiaas arguments to woocommerce orders api endpoint `wc/v2/orders` + * @param $args + * @param $request * - * @param $order_id + * @return mixed */ - public static function assign_order_to_organization($order_id) { - $user = wp_get_current_user(); - Wiaas_User_Organization::assign_post_to_user_organization($order_id, $user->ID); + public static function wiaas_prepare_rest_orders_query($args, $request) { + + # Handle wiaas_is_active flag + if (isset($request['wiaas_is_active'])) { + if ($request['wiaas_is_active'] === '1') { + $args['post_status'] = array('wc-open', 'wc-processing'); + } + if ($request['wiaas_is_active'] === '0') { + $args['post_status'] = array('wc-completed', 'wc-cancelled'); + } + } + + return $args; } /** - * Apply wiaas custome tranformation on retrieved JSON order object + * Apply wiaas custom transformation on retrieved JSON order object * * @param $response * @param $order @@ -66,15 +86,6 @@ class Wiaas_Order { public static function transform_rest_order($response, $order, $request) { $data = $response->get_data(); - $is_customer = wcj_is_user_role('customer'); - - if ($is_customer || true) { - // Format date values. - $data['date_created'] = self::_format_order_date($order->get_date_created()); - $data['date_modified'] = self::_format_order_date($order->get_date_modified()); - $data['date_completed'] = self::_format_order_date($order->get_date_completed()); - } - # apply overrides $data = self::_append_products_info($data, $order, $request); @@ -89,6 +100,18 @@ class Wiaas_Order { return $response; } + /** + * PRIVATE + */ + + /** + * Appends additional wiaas customer lead info to order json response + * @param $data + * @param $order + * @param $request + * + * @return mixed + */ private static function _append_commercial_lead_info($data, $order, $request) { $data['commercial_lead'] = array( @@ -100,20 +123,40 @@ class Wiaas_Order { return $data; } + /** + * Appends additional wiaas customer info to order json response + * @param $data + * @param $order + * @param $request + * + * @return mixed + */ private static function _append_customer_info($data, $order, $request) { + $current_user = wp_get_current_user(); + $customer_id = $data['customer_id']; $customer_user = get_user_by('id', $customer_id); $data['customer'] = array( 'email' => $customer_user->user_email, 'name' => $customer_user->display_name, - 'phone' => get_user_meta($customer_id, 'wiaas_customer_phone', true) + 'phone' => '+46 (10) 5595148' ); + $data['is_my_order'] = $customer_id === $current_user->ID; + return $data; } + /** + * Appends additional wiaas products info to order json response + * @param $data + * @param $order + * @param $request + * + * @return mixed + */ private static function _append_products_info($data, $order, $request) { foreach ($data['line_items'] as $index => $product_line) { # lock all products to `Purchase` payment type @@ -130,7 +173,13 @@ class Wiaas_Order { $product_line['pay_period'] = 0; # collect status from order - $product_line['status'] = $data['status']; + if ($data['status'] === 'completed') { + $product_line['status'] = 'production'; + } else if ($data['status'] === 'cancelled') { + $product_line['status'] = 'cancelled'; + } else { + $product_line['status'] = 'processing'; + } $product_line['short_desc'] = $product_line['status']; # collect completion data from order @@ -158,12 +207,6 @@ class Wiaas_Order { return $data; } - - private static function _format_order_date($date) { - $date = new WC_DateTime( $date, new DateTimeZone( 'UTC' ) ); - $date->setTimezone( new DateTimeZone( wc_timezone_string() ) ); - return gmdate('jS F, Y', $date->getTimestamp()); - } } Wiaas_Order::init(); \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-user.php b/backend/app/plugins/wiaas/includes/class-wiaas-user.php index bada6dd..710ecd7 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-user.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-user.php @@ -1,19 +1,29 @@ add_cap('read_private_shop_orders'); - $customer_role->add_cap('read_shop_order'); + $customer_role->add_cap('read_private_shop_orders'); + $customer_role->add_cap('read_shop_order'); } \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php index ce887a1..e4497c7 100644 --- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php +++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php @@ -246,4 +246,4 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { return absint($value); } -} \ No newline at end of file +} diff --git a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-rest-delivery-process-api.php b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-rest-delivery-process-api.php index 72a0976..c2cf204 100644 --- a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-rest-delivery-process-api.php +++ b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-rest-delivery-process-api.php @@ -42,14 +42,14 @@ class Wiass_REST_Delivery_Process_Api_Test extends Wiaas_Unit_Test_Case { $this->assertTrue(is_array($pending_step)); - $this->assertArrayHasKey('idOrder', $pending_step); - $this->assertArrayHasKey('orderNumber', $pending_step); + $this->assertArrayHasKey('order_id', $pending_step); + $this->assertArrayHasKey('order_number', $pending_step); $this->assertArrayHasKey('status', $pending_step); - $this->assertArrayHasKey('stepAction', $pending_step); + $this->assertArrayHasKey('step_action', $pending_step); - $this->assertEquals($pending_step['idOrder'], $this->order_id); - $this->assertEquals($pending_step['orderNumber'], $this->order_id); + $this->assertEquals($pending_step['order_id'], $this->order_id); + $this->assertEquals($pending_step['order_number'], $this->order_id); $this->assertEquals($pending_step['status'], 'pending'); - $this->assertNotEmpty($pending_step['stepAction']); + $this->assertNotEmpty($pending_step['step_action']); } } diff --git a/backend/app/plugins/wiaas/wiaas.php b/backend/app/plugins/wiaas/wiaas.php index 2dda5d7..7adfec6 100644 --- a/backend/app/plugins/wiaas/wiaas.php +++ b/backend/app/plugins/wiaas/wiaas.php @@ -26,8 +26,6 @@ include_once WIAAS_DIR . '/includes/class-wiaas-delivery-process.php'; include_once WIAAS_DIR . '/includes/class-wiaas-order.php'; -include_once WIAAS_DIR . '/includes/class-wiaas-customer.php'; - include_once WIAAS_DIR . '/includes/class-wiaas-user.php'; include_once WIAAS_DIR . '/includes/class-wiaas-api.php'; diff --git a/backend/composer.json b/backend/composer.json index 621d8a0..c79d66b 100644 --- a/backend/composer.json +++ b/backend/composer.json @@ -29,18 +29,6 @@ "reference": "origin/master" } } - }, - { - "type": "package", - "package": { - "name": "3rdparty/woocommerce-product-vendors", - "type": "wordpress-plugin", - "version": "2.0.27", - "dist": { - "url": "https://github.com/wp-premium/woocommerce-product-vendors/archive/2.0.27.zip", - "type": "zip" - } - } } ], "require": { @@ -59,10 +47,8 @@ "wpackagist-plugin/mailchimp-for-woocommerce": "2.1.7", "wpackagist-plugin/woocommerce-gateway-paypal-express-checkout": "1.5.6", "wpackagist-plugin/jwt-authentication-for-wp-rest-api": "1.2.4", - "wpackagist-plugin/woo-product-bundle": "3.1.2", "wpackagist-plugin/capability-manager-enhanced": "1.5.9", "wpackagist-plugin/wp-user-groups": "2.2.0", - "3rdparty/woocommerce-product-vendors": "*", "3rdparty/gravityforms": "*", "3rdparty/gravityflow": "*" @@ -91,8 +77,8 @@ "wp plugin activate jwt-authentication-for-wp-rest-api", "wp plugin activate gravityforms", "wp plugin activate gravityflow", - "wp plugin activate woo-product-bundle", "wp plugin activate capability-manager-enhanced", + "wp plugin activate groups", "wp plugin activate wp-user-groups", "wp plugin activate wiaas" ], diff --git a/backend/composer.lock b/backend/composer.lock index 12e0018..bb5efa2 100644 --- a/backend/composer.lock +++ b/backend/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "21ce04695bffdbca2f33154b291dd1dd", + "content-hash": "798e9b8b675248e2b8dbc2bc7dcab511", "packages": [ { "name": "3rdparty/gravityflow", @@ -26,17 +26,6 @@ }, "type": "wordpress-plugin" }, - { - "name": "3rdparty/woocommerce-product-vendors", - "version": "2.0.27", - "dist": { - "type": "zip", - "url": "https://github.com/wp-premium/woocommerce-product-vendors/archive/2.0.27.zip", - "reference": null, - "shasum": null - }, - "type": "wordpress-plugin" - }, { "name": "composer/installers", "version": "v1.5.0", @@ -568,26 +557,6 @@ "type": "wordpress-plugin", "homepage": "https://wordpress.org/plugins/mailchimp-for-woocommerce/" }, - { - "name": "wpackagist-plugin/woo-product-bundle", - "version": "3.1.2", - "source": { - "type": "svn", - "url": "https://plugins.svn.wordpress.org/woo-product-bundle/", - "reference": "trunk" - }, - "dist": { - "type": "zip", - "url": "https://downloads.wordpress.org/plugin/woo-product-bundle.zip?timestamp=1533003376", - "reference": null, - "shasum": null - }, - "require": { - "composer/installers": "~1.0" - }, - "type": "wordpress-plugin", - "homepage": "https://wordpress.org/plugins/woo-product-bundle/" - }, { "name": "wpackagist-plugin/woocommerce-gateway-paypal-express-checkout", "version": "1.5.6", diff --git a/backend/config/application.php b/backend/config/application.php index 3903cf3..e12625e 100644 --- a/backend/config/application.php +++ b/backend/config/application.php @@ -23,16 +23,6 @@ if (file_exists($env_config)) { require_once $env_config; } -/** - * Stops redirect loop on login page - */ -define('FORCE_SSL_ADMIN', true); -// in some setups HTTP_X_FORWARDED_PROTO might contain -// a comma-separated list e.g. http,https -// so check for https existence -if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) - $_SERVER['HTTPS']='on'; - /** * URLs */ diff --git a/backend/config/environments/production.php b/backend/config/environments/production.php index 162c71c..5c39f79 100644 --- a/backend/config/environments/production.php +++ b/backend/config/environments/production.php @@ -5,3 +5,13 @@ define('WP_DEBUG_DISPLAY', false); define('SCRIPT_DEBUG', false); /** Disable all file modifications including updates and update notifications */ define('DISALLOW_FILE_MODS', true); + +/** + * Stops redirect loop on login page + */ +define('FORCE_SSL_ADMIN', true); +// in some setups HTTP_X_FORWARDED_PROTO might contain +// a comma-separated list e.g. http,https +// so check for https existence +if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) + $_SERVER['HTTPS']='on'; \ No newline at end of file diff --git a/backend/config/environments/staging.php b/backend/config/environments/staging.php index 528be4a..55fa1c7 100644 --- a/backend/config/environments/staging.php +++ b/backend/config/environments/staging.php @@ -5,3 +5,13 @@ define('WP_DEBUG_DISPLAY', false); define('SCRIPT_DEBUG', false); /** Disable all file modifications including updates and update notifications */ define('DISALLOW_FILE_MODS', true); + +/** + * Stops redirect loop on login page + */ +define('FORCE_SSL_ADMIN', true); +// in some setups HTTP_X_FORWARDED_PROTO might contain +// a comma-separated list e.g. http,https +// so check for https existence +if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) + $_SERVER['HTTPS']='on'; diff --git a/backend/wp-config.php b/backend/wp-config.php index e557ed4..5e5ec6b 100644 --- a/backend/wp-config.php +++ b/backend/wp-config.php @@ -1,9 +1,9 @@ - ({ export const fetchCartCount = () => { return dispatch => { + dispatch(requestShopCartCount()); + //TODO : fetch cart count from woocommerce (requires plugin) dispatch(receiveShopCartCount(0)); - /*return client.fetch({url: `${API_SERVER}/cart/api/getCartCount`}).then(response => { + /* + return client.fetch({url: `${API_SERVER}/cart/api/getCartCount`}).then(response => { if (typeof response.data !== 'undefined' && 'cartItemsCount' in response.data) { dispatch(receiveShopCartCount(response.data.cartItemsCount)); } }).catch(error => { client.onError(error, dispatch); - });*/ + }); + */ } } diff --git a/frontend/src/actions/dashboard/dashboardActions.js b/frontend/src/actions/dashboard/dashboardActions.js index 8e6c26e..18330a4 100644 --- a/frontend/src/actions/dashboard/dashboardActions.js +++ b/frontend/src/actions/dashboard/dashboardActions.js @@ -1,7 +1,4 @@ -import {API_SERVER} from '../../config'; -import HtmlClient from '../../helpers/HtmlClient'; import {REQUEST_GADGETS, RECIEVE_GADGETS} from '../../constants/dashboardConstants'; -const htmlClient = new HtmlClient(); const requestGadgets = () => ({type: REQUEST_GADGETS}); const recieveGadgets = (json) => ({ @@ -12,7 +9,30 @@ const recieveGadgets = (json) => ({ export const fetchGadgets = () => { return dispatch => { dispatch(requestGadgets()); - const data = {"info":{"idDashboard":"23","name":"Customer Basic Dashboard","isOwner":"0"},"gadgets":[{"idGadget":"3","name":"Customer Order Central","module":"gadget-order-central","position":"1"},{"idGadget":"5","name":"Customer Next Actions","module":"gadget-next-actions","position":"2"}]}; - dispatch(recieveGadgets(data.gadgets)) + //TODO : check how to solve gadgets, don't use hardcoded values + const gadgets = [ + { + name: 'CustomerOrderCentral', + idGadget: 0, + }, + { + name: 'CustomerNextActions', + idGadget: 1, + } + ] + dispatch(recieveGadgets(gadgets)); + /* + return htmlClient.fetch({ + url: `${API_SERVER}/dashboards/api/getMyDashboard` + }) + .then(response => { + if(response.data && response.data.gadgets){ + dispatch(recieveGadgets(response.data.gadgets)) + } + }) + .catch(error => { + htmlClient.onError(error, dispatch); + }); + */ } } diff --git a/frontend/src/actions/dashboard/nextActionsActions.js b/frontend/src/actions/dashboard/nextActionsActions.js index e9e6edf..cfaff25 100644 --- a/frontend/src/actions/dashboard/nextActionsActions.js +++ b/frontend/src/actions/dashboard/nextActionsActions.js @@ -1,6 +1,7 @@ -import {API_SERVER} from '../../config'; -import HtmlClient from '../../helpers/HtmlClient'; import {REQUEST_NEXT_ACTIONS, RECIEVE_NEXT_ACTIONS} from '../../constants/dashboardConstants'; +import { API_SERVER } from '../../config'; +import HtmlClient from '../../helpers/HtmlClient'; + const client = new HtmlClient(); export const requestNextActions = () => ({ @@ -23,6 +24,6 @@ export const fetchNextActions = () => { .then(response => dispatch(recieveNextActions(response.data))) .catch(error => { client.onError(error, dispatch); - }); + }); } } diff --git a/frontend/src/actions/dashboard/ordersActions.js b/frontend/src/actions/dashboard/ordersActions.js index 9a6419e..7b03bbc 100644 --- a/frontend/src/actions/dashboard/ordersActions.js +++ b/frontend/src/actions/dashboard/ordersActions.js @@ -4,6 +4,8 @@ import { REQUEST_ORDERS, RECEIVE_ORDERS } from '../../constants/dashboardConstants'; +import {fromWCOrder} from '../../helpers/OrderHelper'; +import { MAX_ORDER_COUNT } from '../../constants/ordersConstants'; const htmlClient = new HtmlClient(); export const requestOrders = () => ({ @@ -19,17 +21,16 @@ export const recieveOrders = (json) => ({ export const fetchOrders = (viewAllOrders) => { return dispatch => { - dispatch(recieveOrders([])); - /*return htmlClient.fetch({ - url: `${API_SERVER}/dashboards/api/getOrderCentralInfo`, - method: 'post', - data: { - viewAllOrders - } + dispatch(requestOrders()); + return htmlClient.fetch({ + url: `${API_SERVER}/wp-json/wc/v2/orders?per_page=${MAX_ORDER_COUNT}&wiaas_is_active=1`, + method: 'get', + }) + .then(response => { + dispatch(recieveOrders(response.data.map(wcOrder => fromWCOrder(wcOrder)))); }) - .then(response => dispatch(recieveOrders(response.data))) .catch(error => { htmlClient.onError(error, dispatch); - });*/ + }); } } diff --git a/frontend/src/actions/login/authActions.js b/frontend/src/actions/login/authActions.js index 9a1a937..fc2a41d 100644 --- a/frontend/src/actions/login/authActions.js +++ b/frontend/src/actions/login/authActions.js @@ -160,68 +160,70 @@ const validateRefreshToken = () => { export const getModules = () => { return dispatch => { - const data = { - "modules": { - "modules": [ + dispatch(requestModules()); + //TODO : check how to solve modules, don't hardocde values + const modules={ + modules:{ + modules:[ { - "id": "14", - "name": "ProfileSettings", - "menuName": "ProfileSettings", - "url": "profileSettings", - "isInMenu": "0" + id:"19", + isInMenu:"0", + menuName:"Cart", + name:"Cart", + url:"cart", + }, { - "id": "23", - "name": "OrderProjects", - "menuName": "OrderProjects", - "url": "orderProjects", - "isInMenu": "0" + id:"14", + isInMenu:"0", + menuName:"ProfileSettings", + name:"ProfileSettings", + url:"profileSettings", }, { - "id": "15", - "name": "Terms", - "menuName": "Terms", - "url": "terms", - "isInMenu": "0" + id:"23", + isInMenu:"0", + menuName:"OrderProjects", + name:"OrderProjects", + url:"orderProjects", }, { - "id": "19", - "name": "Cart", - "menuName": "Cart", - "url": "cart", - "isInMenu": "0" + id:"15", + isInMenu:"0", + menuName:"Terms", + name:"Terms", + url:"terms", }, { - "id": "1", - "name": "Dashboards", - "menuName": "Overview", - "url": "dashboards", - "isInMenu": "1" + id:"1", + isInMenu:"1", + menuName:"Overview", + name:"Dashboards", + url:"dashboards", }, { - "id": "18", - "name": "CoMarket", - "menuName": "Co-Market", - "url": "co-market", - "isInMenu": "1" + id:"18", + isInMenu:"1", + menuName:"Co-Market", + name:"CoMarket", + url:"co-market", } ], - "subModules": { - "co-market": [ + subModules:{ + "co-market":[ { - "moduleUrl": "co-market", - "menuName": "Orders", - "name": "Orders", - "url": "orders" + menuName:"Orders", + name:"Orders", + url:"orders", + moduleUrl:"co-market", } ] } } - }; - dispatch(recieveModules(data)); - - dispatch(requestModules()); - /**return htmlClient.fetch({ + } + dispatch(recieveModules(modules)); + /* + return htmlClient.fetch({ url: `${API_SERVER}/login/api/getModules`, }) .then(response => { @@ -229,7 +231,8 @@ export const getModules = () => { }) .catch(error => { htmlClient.onError(error, dispatch); - });**/ + }); + */ } } diff --git a/frontend/src/actions/orders/ordersActions.js b/frontend/src/actions/orders/ordersActions.js index 02dd0c0..d9c7ef5 100644 --- a/frontend/src/actions/orders/ordersActions.js +++ b/frontend/src/actions/orders/ordersActions.js @@ -7,13 +7,14 @@ import { RECEIVE_HISTORY_ORDERS, SET_VIEW_ALL_ORDERS } from '../../constants/ordersConstants'; +import {fromWCOrder} from '../../helpers/OrderHelper'; const htmlClient = new HtmlClient(); const requestActiveOrders = () => ({ type: REQUEST_ACTIVE_ORDERS, isLoading: true }); -const recieveActiveOrders = (json) => ({ +const receiveActiveOrders = (json) => ({ type: RECEIVE_ACTIVE_ORDERS, isLoading: false, activeOrders: json @@ -23,10 +24,10 @@ export const getActiveOrders = () => { return dispatch => { dispatch(requestActiveOrders()); return htmlClient.fetch({ - url: `${API_SERVER}/wp-json/wc/v2/orders?status=processing` + url: `${API_SERVER}/wp-json/wc/v2/orders?wiaas_is_active=1` }) .then(response => { - dispatch(recieveActiveOrders(response.data)); + dispatch(receiveActiveOrders(response.data.map(wcOrder => fromWCOrder(wcOrder)))); }) .catch(error => { htmlClient.onError(error, dispatch); @@ -48,10 +49,10 @@ export const getHistoryOrders = () => { return dispatch => { dispatch(requestHistoryOrders()); return htmlClient.fetch({ - url: `${API_SERVER}/wp-json/wc/v2/orders?status=completed` + url: `${API_SERVER}/wp-json/wc/v2/orders?wiaas_is_active=0` }) .then(response => { - dispatch(recieveHistoryOrders(response.data)); + dispatch(recieveHistoryOrders(response.data.map(wcOrder => fromWCOrder(wcOrder)))); }) .catch(error => { htmlClient.onError(error, dispatch); diff --git a/frontend/src/config.js b/frontend/src/config.js index 3bca27e..efbfbe8 100644 --- a/frontend/src/config.js +++ b/frontend/src/config.js @@ -3,5 +3,6 @@ const API_VERSION = 'v2'; const API_SERVER_BASE = process.env.REACT_APP_API_URL; const API_SERVER = API_SERVER_BASE; +const API_SERVER_LOGIN = API_SERVER + "/wp-admin"; -export {API_SERVER_BASE, API_SERVER, APPLICATION_NAME} +export {API_SERVER_BASE, API_SERVER, APPLICATION_NAME, API_SERVER_LOGIN} diff --git a/frontend/src/constants/authConstants.js b/frontend/src/constants/authConstants.js index d70bd8f..f02b48a 100644 --- a/frontend/src/constants/authConstants.js +++ b/frontend/src/constants/authConstants.js @@ -1,4 +1,4 @@ -import {API_SERVER_BASE} from '../config.js'; +import {API_SERVER_LOGIN} from '../config.js'; const MODULE = 'AUTH_'; @@ -36,7 +36,7 @@ export const loginMessages = { CHANGE_LATER: 'You can change your password in 5 minutes!', INVALID_REFRESH_TOKEN: 'Your session has expired!', EXPIRED_SESSION : 'Your session has expired!', - INVALID_USER_TYPE: 'Users with other roles than "customer" must use this url for login: ' + API_SERVER_BASE, + INVALID_USER_TYPE: 'Users with other roles than "customer" must use this url for login: ' + API_SERVER_LOGIN, INVALID_CHANGE_TOKEN: 'Invalid change token value!', PASSWORDS_MISSING: 'Password can not be empty', WRONG_USERNAME: 'Invalid username!', diff --git a/frontend/src/constants/dashboardConstants.js b/frontend/src/constants/dashboardConstants.js index 36fea0b..aaff788 100644 --- a/frontend/src/constants/dashboardConstants.js +++ b/frontend/src/constants/dashboardConstants.js @@ -30,10 +30,10 @@ export const dashboardTexts = { }, statuses: { open: 'Open', - 'in-progress': 'In Progress', - production: 'Production', + processing: 'In Progress', + completed: 'Production', 'end-of-life': 'End Of Life', - canceled: 'Canceled', + cancelled: 'Cancelled', 'not-accepted': 'Not Accepted', invalid: 'Invalid', pending: 'Pending' diff --git a/frontend/src/constants/ordersConstants.js b/frontend/src/constants/ordersConstants.js index 474cdcf..6eaaeee 100644 --- a/frontend/src/constants/ordersConstants.js +++ b/frontend/src/constants/ordersConstants.js @@ -186,7 +186,7 @@ export const orderTexts = { }, statuses: { open: 'Open', - 'processing': 'Processing', + 'processing': 'In progress', completed: 'Completed', 'end-of-life': 'Completed', cancelled: 'Cancelled', @@ -207,3 +207,5 @@ export const orderTexts = { PLACED_BY: 'Placed by' } }; + +export const MAX_ORDER_COUNT = 5; diff --git a/frontend/src/containers/dashboard/NextActions.scss b/frontend/src/containers/dashboard/NextActions.scss index f3c8ff4..16e4b70 100644 --- a/frontend/src/containers/dashboard/NextActions.scss +++ b/frontend/src/containers/dashboard/NextActions.scss @@ -36,8 +36,8 @@ background: $not-accepted-status-color; } - .in-progress { - background: $in-progress-status-color; + .processing { + background: $processing-status-color; } .next-action-details{ diff --git a/frontend/src/containers/dashboard/OrderCentral.scss b/frontend/src/containers/dashboard/OrderCentral.scss index d24da32..639d8c1 100644 --- a/frontend/src/containers/dashboard/OrderCentral.scss +++ b/frontend/src/containers/dashboard/OrderCentral.scss @@ -31,15 +31,15 @@ background: $open-status-color; } - .in-progress { - background: $in-progress-status-color; + .processing { + background: $processing-status-color; } .line-open { border-left: 3px $open-status-color solid; } - .line-in-progress { - border-left: 3px $in-progress-status-color solid; + .line-processing { + border-left: 3px $processing-status-color solid; } } diff --git a/frontend/src/containers/dashboard/components/NextActionItem.jsx b/frontend/src/containers/dashboard/components/NextActionItem.jsx index f307a46..3d0a455 100644 --- a/frontend/src/containers/dashboard/components/NextActionItem.jsx +++ b/frontend/src/containers/dashboard/components/NextActionItem.jsx @@ -10,10 +10,10 @@ class NextActionItem extends Component { return ( - {nextAction.stepAction} + {nextAction.step_action} - +
{dashboardTexts.statuses[nextAction.status]}
diff --git a/frontend/src/containers/dashboard/components/NextActionsList.jsx b/frontend/src/containers/dashboard/components/NextActionsList.jsx index e5ed86b..7995a9a 100644 --- a/frontend/src/containers/dashboard/components/NextActionsList.jsx +++ b/frontend/src/containers/dashboard/components/NextActionsList.jsx @@ -14,7 +14,7 @@ class NextActionsList extends Component { { nextActions && nextActions.map((nextAction, index) => - + ) } diff --git a/frontend/src/containers/dashboard/components/OrderItem.jsx b/frontend/src/containers/dashboard/components/OrderItem.jsx index 072df85..627ba86 100644 --- a/frontend/src/containers/dashboard/components/OrderItem.jsx +++ b/frontend/src/containers/dashboard/components/OrderItem.jsx @@ -12,12 +12,12 @@ class OrderItem extends Component {