From 0d025ba34c5d740b1f0771b9518de91f1f070219 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Tue, 18 Nov 2025 18:31:49 +0700 Subject: [PATCH] refactor(FE-208,213): streamline PurchaseOrderAcceptApprovalForm by removing hardcoded warehouse options and utilizing initialValues for dynamic data --- .../order/PurchaseOrderAcceptApprovalForm.tsx | 93 +++++-------------- .../purchase/order/PurchaseOrderDetail.tsx | 1 + .../purchase/order/PurchaseOrderInvoice.tsx | 6 +- 3 files changed, 28 insertions(+), 72 deletions(-) diff --git a/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx b/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx index 256ffed3..cfe52d8a 100644 --- a/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx +++ b/src/components/pages/purchase/form/order/PurchaseOrderAcceptApprovalForm.tsx @@ -220,77 +220,32 @@ const PurchaseOrderAcceptApprovalForm = ({ })); } - return [ - { - value: 1, - label: 'SEALYTE SPARK 1 x 87 gr (14 SACHET)', - id: 1, - quantity: 14, - product: { - name: 'SEALYTE SPARK 1 x 87 gr', - product_category: 'Bahan Baku', - uom: { - name: 'SACHET', - }, - }, - warehouse: { - name: 'GUDANG CIANGSANA 1 (ARCA P15)', - }, - }, - { - value: 2, - label: 'CID-2000 @ 5 KG (2 KILOGRAM)', - id: 2, - quantity: 2, - product: { - name: 'CID-2000 @ 5 KG', - product_category: 'Bahan Baku', - uom: { - name: 'Kilogram', - }, - }, - warehouse: { - name: 'GUDANG CIANGSANA 2 (ARCA P15)', - }, - }, - { - value: 3, - label: 'VITAMIN AYAM (10 DOSIS)', - id: 3, - quantity: 10, - product: { - name: 'VITAMIN AYAM', - product_category: 'Bahan Baku', - uom: { - name: 'DOSIS', - }, - }, - warehouse: { - name: 'GUDANG CIANGSANA 3 (ARCA P15)', - }, - }, - ]; - }, [initialValues?.items, searchParams]); + return []; + }, [initialValues?.items]); - const warehouses: WarehouseOptionType[] = useMemo( - () => [ - { value: 1, label: 'GUDANG CIANGSANA 1 (ARCA P15)', id: 1 }, - { value: 2, label: 'GUDANG CIANGSANA 2 (ARCA P15)', id: 2 }, - { value: 3, label: 'GUDANG CIANGSANA 3 (ARCA P15)', id: 3 }, - { value: 7, label: 'GUDANG UTAMA', id: 7 }, - ], - [] - ); + const warehouses: WarehouseOptionType[] = useMemo(() => { + if (initialValues?.items) { + const uniqueWarehouses = new Map(); - const expeditionVendors: ExpeditionVendorOptionType[] = useMemo( - () => [ - { value: 1, label: 'JNE Express', id: 1 }, - { value: 2, label: 'J&T Express', id: 2 }, - { value: 3, label: 'SiCepat Express', id: 3 }, - { value: 4, label: 'Anteraja', id: 4 }, - ], - [] - ); + initialValues.items.forEach((item) => { + if (item.warehouse && !uniqueWarehouses.has(item.warehouse.id)) { + uniqueWarehouses.set(item.warehouse.id, { + value: item.warehouse.id, + label: item.warehouse.name, + id: item.warehouse.id, + }); + } + }); + + return Array.from(uniqueWarehouses.values()); + } + + return []; + }, [initialValues?.items]); + + const expeditionVendors: ExpeditionVendorOptionType[] = useMemo(() => { + return []; + }, []); const getPurchaseItemOptions = useCallback(() => { return purchaseItems; diff --git a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx index 8de2f322..0f3d9372 100644 --- a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx +++ b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx @@ -773,6 +773,7 @@ const PurchaseOrderDetail = ({ > diff --git a/src/components/pages/purchase/order/PurchaseOrderInvoice.tsx b/src/components/pages/purchase/order/PurchaseOrderInvoice.tsx index c9485f96..4e6cd75d 100644 --- a/src/components/pages/purchase/order/PurchaseOrderInvoice.tsx +++ b/src/components/pages/purchase/order/PurchaseOrderInvoice.tsx @@ -41,7 +41,7 @@ const pdfStyles = StyleSheet.create({ fontSize: 12, fontWeight: 'bold', marginBottom: 4, - color: '#1f74bf', // Primary color from globals.css + color: '#1f74bf', }, address: { fontSize: 8, @@ -65,7 +65,7 @@ const pdfStyles = StyleSheet.create({ fontSize: 18, fontWeight: 'bold', flex: 3, - color: '#1f74bf', // Primary color + color: '#1f74bf', }, poInfo: { flex: 1, @@ -76,7 +76,7 @@ const pdfStyles = StyleSheet.create({ fontSize: 12, fontWeight: 'bold', marginBottom: 8, - color: '#1f74bf', // Primary color + color: '#1f74bf', }, table: { borderWidth: 1,