diff --git a/frontend/src/modules/products/components/EditProductForm.tsx b/frontend/src/modules/products/components/EditProductForm.tsx index f988bce..749ec6f 100644 --- a/frontend/src/modules/products/components/EditProductForm.tsx +++ b/frontend/src/modules/products/components/EditProductForm.tsx @@ -4,6 +4,8 @@ import { CreateProductDTO, ProductDTO } from 'generated-api'; import { Input } from '../../../shared/components/form/Input/Input'; import { useEditProduct } from '../hooks/useEditProduct'; import { productFormValidationSchema } from './ProductForm'; +import { useGlobalStore } from '../../../shared/stores'; +import { CompanyDTOTypeEnum } from 'generated-api'; interface EditProductFormProps { product: ProductDTO; @@ -25,6 +27,19 @@ export const EditProductForm: React.FC = ({ }, }); }; + const getUser = useGlobalStore((state) => state.getUser); + const companyType = getUser()?.company?.type; + + const isSuppManu = () => { + if ( + companyType === CompanyDTOTypeEnum.Supplier || + CompanyDTOTypeEnum.Manufacturer + ) { + return true; + } else { + return false; + } + }; return ( = ({ /> )} - - {(fieldProps: FieldProps) => ( - - )} - - {props.values.bulk && ( + {isSuppManu() && ( {(fieldProps: FieldProps) => ( = ({ const initialValues: CreateProductDTO = { name: '', price: 0, - bulk: false, - bulkQuantity: 0, + bulk: true, + bulkQuantity: undefined, + }; + const getUser = useGlobalStore((state) => state.getUser); + const companyType = getUser()?.company?.type; + + const isSuppManu = () => { + if ( + companyType === CompanyDTOTypeEnum.Supplier || + CompanyDTOTypeEnum.Manufacturer + ) { + return true; + } else { + return false; + } }; const onSubmit = (dto: CreateProductDTO) => { @@ -81,21 +96,7 @@ export const ProductForm: React.FC = ({ /> )} - - {(fieldProps: FieldProps) => ( - - )} - - {props.values.bulk && ( + {isSuppManu() && ( {(fieldProps: FieldProps) => ( = ({ product }) => { {product.name} {product.price} - - - {product.bulkQuantity ?? 'n/a'} diff --git a/frontend/src/pages/products/index.tsx b/frontend/src/pages/products/index.tsx index df412e2..8d9dd2b 100644 --- a/frontend/src/pages/products/index.tsx +++ b/frontend/src/pages/products/index.tsx @@ -53,7 +53,6 @@ const Products = () => { Product name Price - Bulk Bulk Quantity Actions