From d5d8a972cfc19e5869d4d9e93fffcabb12e1a24d Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 8 Sep 2022 12:04:37 +0200 Subject: [PATCH] (quality) Refacto orders views --- .../components/store/show-order.tsx | 82 +++++++++++-------- .../javascript/controllers/admin/orders.js | 52 ++++++++++++ .../src/javascript/controllers/orders.js | 2 +- app/frontend/src/javascript/router.js | 2 +- .../stylesheets/modules/store/order-item.scss | 1 + app/frontend/templates/admin/orders/show.html | 4 +- .../templates/admin/store/product_edit.html | 2 +- .../templates/admin/store/product_new.html | 2 +- app/frontend/templates/orders/show.html | 17 ++++ config/locales/app.admin.en.yml | 17 +--- config/locales/app.shared.en.yml | 26 ++++++ 11 files changed, 150 insertions(+), 57 deletions(-) create mode 100644 app/frontend/src/javascript/controllers/admin/orders.js create mode 100644 app/frontend/templates/orders/show.html diff --git a/app/frontend/src/javascript/components/store/show-order.tsx b/app/frontend/src/javascript/components/store/show-order.tsx index 252b55036..b2aaac940 100644 --- a/app/frontend/src/javascript/components/store/show-order.tsx +++ b/app/frontend/src/javascript/components/store/show-order.tsx @@ -1,7 +1,7 @@ -/* eslint-disable fabmanager/scoped-translation */ import React from 'react'; import { useTranslation } from 'react-i18next'; import { IApplication } from '../../models/application'; +import { User } from '../../models/user'; import { react2angular } from 'react2angular'; import { Loader } from '../base/loader'; import noImage from '../../../../images/no_image.png'; @@ -12,6 +12,7 @@ declare const Application: IApplication; interface ShowOrderProps { orderRef: string, + currentUser?: User, onError: (message: string) => void, onSuccess: (message: string) => void } @@ -26,22 +27,29 @@ type selectOption = { value: number, label: string }; */ // TODO: delete next eslint disable // eslint-disable-next-line @typescript-eslint/no-unused-vars -export const ShowOrder: React.FC = ({ orderRef, onError, onSuccess }) => { - const { t } = useTranslation('admin'); +export const ShowOrder: React.FC = ({ orderRef, currentUser, onError, onSuccess }) => { + const { t } = useTranslation('shared'); + + /** + * Check if the current operator has administrative rights or is a normal member + */ + const isPrivileged = (): boolean => { + return (currentUser?.role === 'admin' || currentUser?.role === 'manager'); + }; /** * Creates sorting options to the react-select format */ const buildOptions = (): Array => { return [ - { value: 0, label: t('app.admin.store.orders.status.error') }, - { value: 1, label: t('app.admin.store.orders.status.canceled') }, - { value: 2, label: t('app.admin.store.orders.status.pending') }, - { value: 3, label: t('app.admin.store.orders.status.under_preparation') }, - { value: 4, label: t('app.admin.store.orders.status.paid') }, - { value: 5, label: t('app.admin.store.orders.status.ready') }, - { value: 6, label: t('app.admin.store.orders.status.collected') }, - { value: 7, label: t('app.admin.store.orders.status.refunded') } + { value: 0, label: t('app.shared.store.show_order.status.error') }, + { value: 1, label: t('app.shared.store.show_order.status.canceled') }, + { value: 2, label: t('app.shared.store.show_order.status.pending') }, + { value: 3, label: t('app.shared.store.show_order.status.under_preparation') }, + { value: 4, label: t('app.shared.store.show_order.status.paid') }, + { value: 5, label: t('app.shared.store.show_order.status.ready') }, + { value: 6, label: t('app.shared.store.show_order.status.collected') }, + { value: 7, label: t('app.shared.store.show_order.status.refunded') } ]; }; @@ -85,33 +93,37 @@ export const ShowOrder: React.FC = ({ orderRef, onError, onSucce

[order.ref]

- handleAction(option)} + styles={customStyles} + /> + } - {t('app.admin.store.show_order.see_invoice')} + {t('app.shared.store.show_order.see_invoice')}
- +
+ {isPrivileged() && +
+ {t('app.shared.store.show_order.client')} +

order.user.name

+
+ }
- {t('app.admin.store.show_order.client')} -

order.user.name

-
-
- {t('app.admin.store.show_order.created_at')} + {t('app.shared.store.show_order.created_at')}

order.created_at

- {t('app.admin.store.show_order.last_update')} + {t('app.shared.store.show_order.last_update')}

order.???

@@ -121,7 +133,7 @@ export const ShowOrder: React.FC = ({ orderRef, onError, onSucce
- +
{/* loop sur les articles du panier */}
@@ -129,19 +141,19 @@ export const ShowOrder: React.FC = ({ orderRef, onError, onSucce
- {t('app.admin.store.show_order.reference_short')} orderable_id? + {t('app.shared.store.show_order.reference_short')} orderable_id?

o.orderable_name

o.amount

- / {t('app.admin.store.show_order.unit')} + / {t('app.shared.store.show_order.unit')}
o.quantity
- {t('app.admin.store.show_order.item_total')} + {t('app.shared.store.show_order.item_total')}

o.quantity * o.amount

@@ -151,15 +163,15 @@ export const ShowOrder: React.FC = ({ orderRef, onError, onSucce
- +

Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum rerum commodi quaerat possimus! Odit, harum.

- -

{t('app.admin.store.show_order.products_total')}order.amount

-

{t('app.admin.store.show_order.gift_total')}-order.amount

-

{t('app.admin.store.show_order.coupon')}order.amount

-

{t('app.admin.store.show_order.total')} order.total

+ +

{t('app.shared.store.show_order.products_total')}order.amount

+

{t('app.shared.store.show_order.gift_total')}-order.amount

+

{t('app.shared.store.show_order.coupon')}order.amount

+

{t('app.shared.store.show_order.cart_total')} order.total

@@ -174,4 +186,4 @@ const ShowOrderWrapper: React.FC = (props) => { ); }; -Application.Components.component('showOrder', react2angular(ShowOrderWrapper, ['orderRef', 'onError', 'onSuccess'])); +Application.Components.component('showOrder', react2angular(ShowOrderWrapper, ['orderRef', 'currentUser', 'onError', 'onSuccess'])); diff --git a/app/frontend/src/javascript/controllers/admin/orders.js b/app/frontend/src/javascript/controllers/admin/orders.js new file mode 100644 index 000000000..ba2b00cce --- /dev/null +++ b/app/frontend/src/javascript/controllers/admin/orders.js @@ -0,0 +1,52 @@ +/* eslint-disable + no-return-assign, + no-undef, +*/ +'use strict'; + +Application.Controllers.controller('AdminShowOrdersController', ['$rootScope', '$scope', 'CSRF', 'growl', '$state', '$transition$', + function ($rootScope, $scope, CSRF, growl, $state, $transition$) { + /* PRIVATE SCOPE */ + + /* PUBLIC SCOPE */ + $scope.orderToken = $transition$.params().token; + + /** + * Callback triggered in case of error + */ + $scope.onError = (message) => { + growl.error(message); + }; + + /** + * Callback triggered in case of success + */ + $scope.onSuccess = (message) => { + growl.success(message); + }; + + /** + * Click Callback triggered in case of back products list + */ + $scope.backProductsList = () => { + $state.go('app.admin.store.orders'); + }; + + // currently logged-in user + $scope.currentUser = $rootScope.currentUser; + + /* PRIVATE SCOPE */ + + /** + * Kind of constructor: these actions will be realized first when the controller is loaded + */ + const initialize = function () { + // set the authenticity tokens in the forms + CSRF.setMetaTags(); + }; + + // init the controller (call at the end !) + return initialize(); + } + +]); diff --git a/app/frontend/src/javascript/controllers/orders.js b/app/frontend/src/javascript/controllers/orders.js index 4cace0dd9..d4df174cd 100644 --- a/app/frontend/src/javascript/controllers/orders.js +++ b/app/frontend/src/javascript/controllers/orders.js @@ -29,7 +29,7 @@ Application.Controllers.controller('ShowOrdersController', ['$rootScope', '$scop * Click Callback triggered in case of back products list */ $scope.backProductsList = () => { - $state.go('app.admin.store.orders'); + $state.go('app.logged.dashboard.orders'); }; // currently logged-in user diff --git a/app/frontend/src/javascript/router.js b/app/frontend/src/javascript/router.js index 6cd676c76..8dc6ebf8a 100644 --- a/app/frontend/src/javascript/router.js +++ b/app/frontend/src/javascript/router.js @@ -930,7 +930,7 @@ angular.module('application.router', ['ui.router']) views: { 'main@': { templateUrl: '/admin/orders/show.html', - controller: 'ShowOrdersController' + controller: 'AdminShowOrdersController' } } }) diff --git a/app/frontend/src/stylesheets/modules/store/order-item.scss b/app/frontend/src/stylesheets/modules/store/order-item.scss index dc91b15bc..75b5a9201 100644 --- a/app/frontend/src/stylesheets/modules/store/order-item.scss +++ b/app/frontend/src/stylesheets/modules/store/order-item.scss @@ -35,6 +35,7 @@ } .date { @include text-sm; } .price { + flex: 0 1 30%; display: flex; flex-direction: column; justify-self: flex-end; diff --git a/app/frontend/templates/admin/orders/show.html b/app/frontend/templates/admin/orders/show.html index eaf7f0feb..e2274ce0c 100644 --- a/app/frontend/templates/admin/orders/show.html +++ b/app/frontend/templates/admin/orders/show.html @@ -12,8 +12,8 @@ - + \ No newline at end of file diff --git a/app/frontend/templates/admin/store/product_edit.html b/app/frontend/templates/admin/store/product_edit.html index 02e9df374..71d6c1f1d 100644 --- a/app/frontend/templates/admin/store/product_edit.html +++ b/app/frontend/templates/admin/store/product_edit.html @@ -12,7 +12,7 @@ diff --git a/app/frontend/templates/admin/store/product_new.html b/app/frontend/templates/admin/store/product_new.html index 1af8e51f6..e72a6b162 100644 --- a/app/frontend/templates/admin/store/product_new.html +++ b/app/frontend/templates/admin/store/product_new.html @@ -12,7 +12,7 @@ diff --git a/app/frontend/templates/orders/show.html b/app/frontend/templates/orders/show.html new file mode 100644 index 000000000..b6a3fe056 --- /dev/null +++ b/app/frontend/templates/orders/show.html @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index cd5f9474c..100ff4db4 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -1899,7 +1899,7 @@ en: all_products: "All products" categories_of_store: "Store's categories" the_orders: "Orders" - back_products_list: "Back to products list" + back_to_list: "Back to list" product_categories: title: "Categories" info: "Information:
Find below all the categories created. The categories are arranged on two levels maximum, you can arrange them with a drag and drop. The order of the categories will be identical on the public view and the list below. Please note that you can delete a category or a sub-category even if they are associated with products. The latter will be left without categories. If you delete a category that contains sub-categories, the latter will also be deleted. Make sure that your categories are well arranged and save your choice." @@ -2050,21 +2050,6 @@ en: sort: newest: "Newest first" oldest: "Oldest first" - show_order: - see_invoice: "See invoice" - client: "Client" - created_at: "Creation date" - last_update: "Last update" - cart: "Cart" - reference_short: "ref:" - unit: "Unit" - item_total: "Total" - payment_informations : "Payment informations" - amount: "Amount" - products_total: "Products total" - gift_total: "Discount total" - coupon: "Coupon" - cart_total: "Cart total" store_settings: title: 'Settings' withdrawal_instructions: 'Product withdrawal instructions' diff --git a/config/locales/app.shared.en.yml b/config/locales/app.shared.en.yml index 6042d68c3..b5709dcff 100644 --- a/config/locales/app.shared.en.yml +++ b/config/locales/app.shared.en.yml @@ -564,3 +564,29 @@ en: order_item: total: "Total" client: "Client" + show_order: + back_to_list: "Back to list" + see_invoice: "See invoice" + tracking: "Order tracking" + client: "Client" + created_at: "Creation date" + last_update: "Last update" + cart: "Cart" + reference_short: "ref:" + unit: "Unit" + item_total: "Total" + payment_informations : "Payment informations" + amount: "Amount" + products_total: "Products total" + gift_total: "Discount total" + coupon: "Coupon" + cart_total: "Cart total" + status: + error: "Payment error" + canceled: "Canceled" + pending: "Pending payment" + under_preparation: "Under preparation" + paid: "Paid" + ready: "Ready" + collected: "Collected" + refunded: "Refunded"