From 27a3bdc308a0763d8d28988e61439210158b05cc Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 1 Sep 2022 16:08:37 +0200 Subject: [PATCH] Admin orders (tmp) --- .../javascript/components/cart/store-cart.tsx | 2 +- .../components/store/order-item.tsx | 40 +++++ .../javascript/components/store/orders.tsx | 111 ++++++++++--- .../javascript/components/store/products.tsx | 4 +- .../components/store/show-order.tsx | 125 +++++++++++++++ .../src/javascript/components/store/store.tsx | 4 +- .../src/javascript/controllers/orders.js | 49 ++++++ app/frontend/src/javascript/router.js | 11 ++ .../stylesheets/modules/cart/store-cart.scss | 10 +- .../src/stylesheets/modules/store/orders.scss | 146 +++++++++++++++++- .../stylesheets/modules/store/products.scss | 1 + app/frontend/templates/admin/orders/show.html | 19 +++ app/frontend/templates/admin/store/index.html | 22 +-- .../templates/admin/store/product_edit.html | 22 +-- .../templates/admin/store/product_new.html | 24 ++- config/locales/app.admin.en.yml | 16 ++ config/locales/app.public.en.yml | 5 +- 17 files changed, 534 insertions(+), 77 deletions(-) create mode 100644 app/frontend/src/javascript/components/store/order-item.tsx create mode 100644 app/frontend/src/javascript/components/store/show-order.tsx create mode 100644 app/frontend/src/javascript/controllers/orders.js create mode 100644 app/frontend/templates/admin/orders/show.html diff --git a/app/frontend/src/javascript/components/cart/store-cart.tsx b/app/frontend/src/javascript/components/cart/store-cart.tsx index 163471d59..fac4abb2f 100644 --- a/app/frontend/src/javascript/components/cart/store-cart.tsx +++ b/app/frontend/src/javascript/components/cart/store-cart.tsx @@ -141,7 +141,7 @@ const StoreCart: React.FC = ({ onSuccess, onError, currentUser,
- ref: + {t('app.public.store_cart.reference_short')}

{item.orderable_name}

diff --git a/app/frontend/src/javascript/components/store/order-item.tsx b/app/frontend/src/javascript/components/store/order-item.tsx new file mode 100644 index 000000000..ecf50222b --- /dev/null +++ b/app/frontend/src/javascript/components/store/order-item.tsx @@ -0,0 +1,40 @@ +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import { Order } from '../../models/order'; +import FormatLib from '../../lib/format'; +import { FabButton } from '../base/fab-button'; + +interface OrderItemProps { + order?: Order + statusColor: string +} + +/** + * List item for an order + */ +export const OrderItem: React.FC = ({ order, statusColor }) => { + const { t } = useTranslation('admin'); + /** + * Go to order page + */ + const showOrder = (token: string) => { + window.location.href = `/#!/admin/store/o/${token}`; + }; + + return ( +
+

order.token

+ order.state +
+ {t('app.admin.store.order_item.client')} +

order.user.name

+
+

order.created_at

+
+ {t('app.admin.store.order_item.total')} +

{FormatLib.price(order?.total)}

+
+ showOrder('orderToken')} icon={} className="is-black" /> +
+ ); +}; diff --git a/app/frontend/src/javascript/components/store/orders.tsx b/app/frontend/src/javascript/components/store/orders.tsx index 45c0dc3e8..25d0a0ea3 100644 --- a/app/frontend/src/javascript/components/store/orders.tsx +++ b/app/frontend/src/javascript/components/store/orders.tsx @@ -7,6 +7,8 @@ import { IApplication } from '../../models/application'; import { FabButton } from '../base/fab-button'; import { StoreListHeader } from './store-list-header'; import { AccordionItem } from './accordion-item'; +import { OrderItem } from './order-item'; +import { MemberSelect } from '../user/member-select'; declare const Application: IApplication; @@ -15,24 +17,15 @@ interface OrdersProps { onError: (message: string) => void, } /** - * Option format, expected by react-select - * @see https://github.com/JedWatson/react-select - */ - type selectOption = { value: number, label: string }; - /** - * Option format, expected by checklist - */ +* Option format, expected by react-select +* @see https://github.com/JedWatson/react-select +*/ +type selectOption = { value: number, label: string }; + +/** +* Option format, expected by checklist +*/ type checklistOption = { value: number, label: string }; -const statusOptions: checklistOption[] = [ - { value: 0, label: 'cart' }, - { value: 1, label: 'paid by credit card' }, - { value: 2, label: 'paid in cash' }, - { value: 3, label: 'being processed' }, - { value: 4, label: 'ready' }, - { value: 5, label: 'delivered' }, - { value: 6, label: 'canceled' }, - { value: 7, label: 'refunded' } -]; /** * Admin list of orders @@ -56,6 +49,17 @@ const Orders: React.FC = ({ onSuccess, onError }) => { console.log('Create new order'); }; + const statusOptions: checklistOption[] = [ + { 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') } + ]; + /** * Apply filters */ @@ -101,6 +105,15 @@ const Orders: React.FC = ({ onSuccess, onError }) => { }); }; + /** + * Filter: by member + */ + const handleSelectMember = (userId: number) => { + setFilters(draft => { + return { ...draft, memberId: userId }; + }); + }; + /** * Open/close accordion items */ @@ -108,13 +121,31 @@ const Orders: React.FC = ({ onSuccess, onError }) => { setAccordion({ ...accordion, [id]: state }); }; + /** + * Returns a className according to the status + */ + const statusColor = (status: string) => { + switch (status) { + case 'error': + return 'error'; + case 'canceled': + return 'canceled'; + case 'pending' || 'under_preparation': + return 'pending'; + default: + return 'normal'; + } + }; + return (

{t('app.admin.store.orders.heading')}

-
- {t('app.admin.store.orders.create_order')} -
+ {false && +
+ {t('app.admin.store.orders.create_order')} +
+ }
@@ -128,13 +159,25 @@ const Orders: React.FC = ({ onSuccess, onError }) => { +
+
+ + {t('app.admin.store.orders.filter_apply')} +
+
+
+
-
+
{statusOptions.map(s => ( ))} @@ -142,6 +185,18 @@ const Orders: React.FC = ({ onSuccess, onError }) => { {t('app.admin.store.orders.filter_apply')}
+ +
+
+ + {t('app.admin.store.orders.filter_apply')} +
+
+
@@ -151,6 +206,12 @@ const Orders: React.FC = ({ onSuccess, onError }) => { selectOptions={buildOptions()} onSelectOptionsChange={handleSorting} /> +
+ + + + +
); @@ -168,10 +229,12 @@ Application.Components.component('orders', react2angular(OrdersWrapper, ['onSucc interface Filters { reference: string, - status: checklistOption[] + status: checklistOption[], + memberId: number } const initFilters: Filters = { reference: '', - status: [] + status: [], + memberId: null }; diff --git a/app/frontend/src/javascript/components/store/products.tsx b/app/frontend/src/javascript/components/store/products.tsx index 19240f032..8c2da31fa 100644 --- a/app/frontend/src/javascript/components/store/products.tsx +++ b/app/frontend/src/javascript/components/store/products.tsx @@ -243,7 +243,7 @@ const Products: React.FC = ({ onSuccess, onError }) => { label={t('app.admin.store.products.filter_categories')} >
-
+
{productCategories.map(pc => (