From 65afcbe2a99c268d023d3e1d0d34b09036030b7e Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 7 Mar 2023 11:51:11 +0100 Subject: [PATCH] (quality) use EditDestroyButtons in product list --- .../components/store/product-item.tsx | 33 +++++++------------ .../javascript/components/store/products.tsx | 12 +++---- config/locales/app.admin.en.yml | 3 +- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/app/frontend/src/javascript/components/store/product-item.tsx b/app/frontend/src/javascript/components/store/product-item.tsx index a8e252304..3f2d38bab 100644 --- a/app/frontend/src/javascript/components/store/product-item.tsx +++ b/app/frontend/src/javascript/components/store/product-item.tsx @@ -1,22 +1,23 @@ import * as React from 'react'; import { useTranslation } from 'react-i18next'; -import { FabButton } from '../base/fab-button'; import { Product } from '../../models/product'; -import { PencilSimple, Trash } from 'phosphor-react'; import noImage from '../../../../images/no_image.png'; import { FabStateLabel } from '../base/fab-state-label'; import { ProductPrice } from './product-price'; +import { EditDestroyButtons } from '../base/edit-destroy-buttons'; +import ProductAPI from '../../api/product'; interface ProductItemProps { product: Product, onEdit: (product: Product) => void, - onDelete: (productId: number) => void, + onDelete: (message: string) => void, + onError: (message: string) => void, } /** * This component shows a product item in the admin view */ -export const ProductItem: React.FC = ({ product, onEdit, onDelete }) => { +export const ProductItem: React.FC = ({ product, onEdit, onDelete, onError }) => { const { t } = useTranslation('admin'); /** @@ -34,15 +35,6 @@ export const ProductItem: React.FC = ({ product, onEdit, onDel }; }; - /** - * Init the process of delete the given product - */ - const deleteProduct = (productId: number): () => void => { - return (): void => { - onDelete(productId); - }; - }; - /** * Returns CSS class from stock status */ @@ -80,14 +72,13 @@ export const ProductItem: React.FC = ({ product, onEdit, onDel
-
- - - - - - -
+
); diff --git a/app/frontend/src/javascript/components/store/products.tsx b/app/frontend/src/javascript/components/store/products.tsx index 2f94b9367..1f55aa2c5 100644 --- a/app/frontend/src/javascript/components/store/products.tsx +++ b/app/frontend/src/javascript/components/store/products.tsx @@ -111,14 +111,9 @@ const Products: React.FC = ({ onSuccess, onError, uiRouter }) => }; /** Delete a product */ - const deleteProduct = async (productId: number): Promise => { - try { - await ProductAPI.destroy(productId); - await fetchProducts(); - onSuccess(t('app.admin.store.products.successfully_deleted')); - } catch (e) { - onError(t('app.admin.store.products.unable_to_delete') + e); - } + const deleteProduct = async (message: string): Promise => { + await fetchProducts(); + onSuccess(message); }; /** Goto new product page */ @@ -244,6 +239,7 @@ const Products: React.FC = ({ onSuccess, onError, uiRouter }) => diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 6a3bd13e8..17bb94082 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -2244,8 +2244,6 @@ en: unexpected_error_occurred: "An unexpected error occurred. Please try again later." all_products: "All products" create_a_product: "Create a product" - successfully_deleted: "The product has been successfully deleted" - unable_to_delete: "Unable to delete the product: " filter: "Filter" filter_clear: "Clear all" filter_apply: "Apply" @@ -2267,6 +2265,7 @@ en: sort: "Sort:" visible_only: "Visible products only" product_item: + product: "product" visible: "visible" hidden: "hidden" stock: