refactor(FE-208,213): streamline PurchaseOrderAcceptApprovalForm by removing hardcoded warehouse options and utilizing initialValues for dynamic data

This commit is contained in:
rstubryan
2025-11-18 18:31:49 +07:00
parent 8c3cd3bc53
commit 0d025ba34c
3 changed files with 28 additions and 72 deletions
@@ -220,77 +220,32 @@ const PurchaseOrderAcceptApprovalForm = ({
})); }));
} }
return [ return [];
{ }, [initialValues?.items]);
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]);
const warehouses: WarehouseOptionType[] = useMemo( const warehouses: WarehouseOptionType[] = useMemo(() => {
() => [ if (initialValues?.items) {
{ value: 1, label: 'GUDANG CIANGSANA 1 (ARCA P15)', id: 1 }, const uniqueWarehouses = new Map();
{ 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 expeditionVendors: ExpeditionVendorOptionType[] = useMemo( initialValues.items.forEach((item) => {
() => [ if (item.warehouse && !uniqueWarehouses.has(item.warehouse.id)) {
{ value: 1, label: 'JNE Express', id: 1 }, uniqueWarehouses.set(item.warehouse.id, {
{ value: 2, label: 'J&T Express', id: 2 }, value: item.warehouse.id,
{ value: 3, label: 'SiCepat Express', id: 3 }, label: item.warehouse.name,
{ value: 4, label: 'Anteraja', id: 4 }, id: item.warehouse.id,
], });
[] }
); });
return Array.from(uniqueWarehouses.values());
}
return [];
}, [initialValues?.items]);
const expeditionVendors: ExpeditionVendorOptionType[] = useMemo(() => {
return [];
}, []);
const getPurchaseItemOptions = useCallback(() => { const getPurchaseItemOptions = useCallback(() => {
return purchaseItems; return purchaseItems;
@@ -773,6 +773,7 @@ const PurchaseOrderDetail = ({
> >
<PurchaseOrderAcceptApprovalForm <PurchaseOrderAcceptApprovalForm
type='add' type='add'
initialValues={purchaseData}
onCancel={acceptApprovalModal.closeModal} onCancel={acceptApprovalModal.closeModal}
/> />
</Modal> </Modal>
@@ -41,7 +41,7 @@ const pdfStyles = StyleSheet.create({
fontSize: 12, fontSize: 12,
fontWeight: 'bold', fontWeight: 'bold',
marginBottom: 4, marginBottom: 4,
color: '#1f74bf', // Primary color from globals.css color: '#1f74bf',
}, },
address: { address: {
fontSize: 8, fontSize: 8,
@@ -65,7 +65,7 @@ const pdfStyles = StyleSheet.create({
fontSize: 18, fontSize: 18,
fontWeight: 'bold', fontWeight: 'bold',
flex: 3, flex: 3,
color: '#1f74bf', // Primary color color: '#1f74bf',
}, },
poInfo: { poInfo: {
flex: 1, flex: 1,
@@ -76,7 +76,7 @@ const pdfStyles = StyleSheet.create({
fontSize: 12, fontSize: 12,
fontWeight: 'bold', fontWeight: 'bold',
marginBottom: 8, marginBottom: 8,
color: '#1f74bf', // Primary color color: '#1f74bf',
}, },
table: { table: {
borderWidth: 1, borderWidth: 1,