mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
(quality) use EditDestroyButtons in product list
This commit is contained in:
parent
3f1f267e42
commit
65afcbe2a9
@ -1,22 +1,23 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { FabButton } from '../base/fab-button';
|
|
||||||
import { Product } from '../../models/product';
|
import { Product } from '../../models/product';
|
||||||
import { PencilSimple, Trash } from 'phosphor-react';
|
|
||||||
import noImage from '../../../../images/no_image.png';
|
import noImage from '../../../../images/no_image.png';
|
||||||
import { FabStateLabel } from '../base/fab-state-label';
|
import { FabStateLabel } from '../base/fab-state-label';
|
||||||
import { ProductPrice } from './product-price';
|
import { ProductPrice } from './product-price';
|
||||||
|
import { EditDestroyButtons } from '../base/edit-destroy-buttons';
|
||||||
|
import ProductAPI from '../../api/product';
|
||||||
|
|
||||||
interface ProductItemProps {
|
interface ProductItemProps {
|
||||||
product: Product,
|
product: Product,
|
||||||
onEdit: (product: Product) => void,
|
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
|
* This component shows a product item in the admin view
|
||||||
*/
|
*/
|
||||||
export const ProductItem: React.FC<ProductItemProps> = ({ product, onEdit, onDelete }) => {
|
export const ProductItem: React.FC<ProductItemProps> = ({ product, onEdit, onDelete, onError }) => {
|
||||||
const { t } = useTranslation('admin');
|
const { t } = useTranslation('admin');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,15 +35,6 @@ export const ProductItem: React.FC<ProductItemProps> = ({ 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
|
* Returns CSS class from stock status
|
||||||
*/
|
*/
|
||||||
@ -80,14 +72,13 @@ export const ProductItem: React.FC<ProductItemProps> = ({ product, onEdit, onDel
|
|||||||
<ProductPrice product={product} className="price" />
|
<ProductPrice product={product} className="price" />
|
||||||
</div>
|
</div>
|
||||||
<div className='actions'>
|
<div className='actions'>
|
||||||
<div className='manage'>
|
<EditDestroyButtons onDeleteSuccess={onDelete}
|
||||||
<FabButton className='edit-btn' onClick={editProduct(product)}>
|
className="manage"
|
||||||
<PencilSimple size={20} weight="fill" />
|
onError={onError}
|
||||||
</FabButton>
|
onEdit={editProduct(product)}
|
||||||
<FabButton className='delete-btn' onClick={deleteProduct(product.id)}>
|
itemId={product.id}
|
||||||
<Trash size={20} weight="fill" />
|
itemType={t('app.admin.store.product_item.product')}
|
||||||
</FabButton>
|
apiDestroy={ProductAPI.destroy} />
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -111,14 +111,9 @@ const Products: React.FC<ProductsProps> = ({ onSuccess, onError, uiRouter }) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** Delete a product */
|
/** Delete a product */
|
||||||
const deleteProduct = async (productId: number): Promise<void> => {
|
const deleteProduct = async (message: string): Promise<void> => {
|
||||||
try {
|
await fetchProducts();
|
||||||
await ProductAPI.destroy(productId);
|
onSuccess(message);
|
||||||
await fetchProducts();
|
|
||||||
onSuccess(t('app.admin.store.products.successfully_deleted'));
|
|
||||||
} catch (e) {
|
|
||||||
onError(t('app.admin.store.products.unable_to_delete') + e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Goto new product page */
|
/** Goto new product page */
|
||||||
@ -244,6 +239,7 @@ const Products: React.FC<ProductsProps> = ({ onSuccess, onError, uiRouter }) =>
|
|||||||
<ProductItem
|
<ProductItem
|
||||||
key={product.id}
|
key={product.id}
|
||||||
product={product}
|
product={product}
|
||||||
|
onError={onError}
|
||||||
onEdit={editProduct}
|
onEdit={editProduct}
|
||||||
onDelete={deleteProduct}
|
onDelete={deleteProduct}
|
||||||
/>
|
/>
|
||||||
|
@ -2244,8 +2244,6 @@ en:
|
|||||||
unexpected_error_occurred: "An unexpected error occurred. Please try again later."
|
unexpected_error_occurred: "An unexpected error occurred. Please try again later."
|
||||||
all_products: "All products"
|
all_products: "All products"
|
||||||
create_a_product: "Create a product"
|
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: "Filter"
|
||||||
filter_clear: "Clear all"
|
filter_clear: "Clear all"
|
||||||
filter_apply: "Apply"
|
filter_apply: "Apply"
|
||||||
@ -2267,6 +2265,7 @@ en:
|
|||||||
sort: "Sort:"
|
sort: "Sort:"
|
||||||
visible_only: "Visible products only"
|
visible_only: "Visible products only"
|
||||||
product_item:
|
product_item:
|
||||||
|
product: "product"
|
||||||
visible: "visible"
|
visible: "visible"
|
||||||
hidden: "hidden"
|
hidden: "hidden"
|
||||||
stock:
|
stock:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user