From f1e5692f8f49f06890dedf8bfc13c4e2e6709769 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Thu, 20 Nov 2025 14:50:36 +0700 Subject: [PATCH] refactor(FE-208,212): initialize items in PurchaseRequestForm with initial values --- .../request/PurchaseRequestForm.schema.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/components/pages/purchase/form/request/PurchaseRequestForm.schema.ts b/src/components/pages/purchase/form/request/PurchaseRequestForm.schema.ts index 39e9a879..af84c68b 100644 --- a/src/components/pages/purchase/form/request/PurchaseRequestForm.schema.ts +++ b/src/components/pages/purchase/form/request/PurchaseRequestForm.schema.ts @@ -140,5 +140,29 @@ export const getPurchaseRequestFormInitialValues = ( : null, location_id: initialValues?.location?.id ?? undefined, notes: initialValues?.notes ?? null, - items: [], + items: initialValues?.items?.length ? initialValues.items.map((item) => ({ + warehouse: item.warehouse + ? { + value: item.warehouse.id, + label: item.warehouse.name, + } + : null, + warehouse_id: item.warehouse?.id ?? 0, + product: item.product + ? { + value: item.product.id, + label: item.product.name, + } + : null, + product_id: item.product?.id ?? 0, + qty: item.qty ?? 0, + })) : [ + { + warehouse: null, + warehouse_id: 0, + product: null, + product_id: 0, + qty: 0, + }, + ], });