From 7abe9b7dc6ac11f806dd5a8aeebd42f1acec643e Mon Sep 17 00:00:00 2001 From: rstubryan Date: Fri, 17 Oct 2025 16:48:35 +0700 Subject: [PATCH] refactor(FE-63,65): update Movement types and schema to include area and location for warehouses --- .../movement/form/MovementForm.schema.ts | 42 ++++++++++++------- src/types/api/inventory/movement.d.ts | 24 ++++++++--- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/components/pages/inventory/movement/form/MovementForm.schema.ts b/src/components/pages/inventory/movement/form/MovementForm.schema.ts index f33888e2..11404782 100644 --- a/src/components/pages/inventory/movement/form/MovementForm.schema.ts +++ b/src/components/pages/inventory/movement/form/MovementForm.schema.ts @@ -92,6 +92,8 @@ export const MovementFormSchema = Yup.object({ source_warehouse: Yup.object({ value: Yup.number().min(1).required(), label: Yup.string().required(), + area: Yup.string().optional(), + location: Yup.string().optional(), }).nullable(), source_warehouse_id: Yup.number() .required('Gudang asal wajib diisi!') @@ -99,6 +101,8 @@ export const MovementFormSchema = Yup.object({ destination_warehouse: Yup.object({ value: Yup.number().min(1).required(), label: Yup.string().required(), + area: Yup.string().optional(), + location: Yup.string().optional(), }).nullable(), destination_warehouse_id: Yup.number() .required('Gudang tujuan wajib diisi!') @@ -120,9 +124,12 @@ export type MovementFormValues = Yup.InferType; export const getMovementFormInitialValues = ( initialValues?: Movement ): MovementFormValues => { - const detailIdToProductId = new Map(); + const detailIdToProductId = new Map(); initialValues?.details?.forEach((detail) => { - detailIdToProductId.set(detail.id, detail.product_id); + detailIdToProductId.set(detail.id, { + id: detail.product.id, + name: detail.product.name, + }); }); return { @@ -132,6 +139,8 @@ export const getMovementFormInitialValues = ( ? { value: initialValues.source_warehouse.id, label: initialValues.source_warehouse.name, + area: initialValues.source_warehouse.area?.name, + location: initialValues.source_warehouse.location?.name, } : null, source_warehouse_id: initialValues?.source_warehouse?.id ?? 0, @@ -139,14 +148,19 @@ export const getMovementFormInitialValues = ( ? { value: initialValues.destination_warehouse.id, label: initialValues.destination_warehouse.name, + area: initialValues.destination_warehouse.area?.name, + location: initialValues.destination_warehouse.location?.name, } : null, destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0, products: - initialValues?.details?.map((p) => ({ - product: { value: p.product_id, label: `Product ID: ${p.product_id}` }, - product_id: p.product_id, - product_qty: p.quantity, + initialValues?.details?.map((detail) => ({ + product: { + value: detail.product.id, + label: detail.product.name, + }, + product_id: detail.product.id, + product_qty: detail.quantity, })) ?? [], deliveries: initialValues?.deliveries?.map((d) => { @@ -160,16 +174,16 @@ export const getMovementFormInitialValues = ( supplier: d.supplier ? { value: d.supplier.id, label: d.supplier.name } : null, - supplier_id: d.supplier_id, + supplier_id: d.supplier?.id ?? 0, products: d.items.map((item) => { - const productId = - detailIdToProductId.get(item.stock_transfer_detail_id) ?? 0; + const productData = detailIdToProductId.get( + item.stock_transfer_detail_id + ); return { - product: - productId > 0 - ? { value: productId, label: `Product ID: ${productId}` } - : null, - product_id: productId, + product: productData + ? { value: productData.id, label: productData.name } + : null, + product_id: productData?.id ?? 0, product_qty: item.quantity, }; }), diff --git a/src/types/api/inventory/movement.d.ts b/src/types/api/inventory/movement.d.ts index 9e156a1e..87a03f95 100644 --- a/src/types/api/inventory/movement.d.ts +++ b/src/types/api/inventory/movement.d.ts @@ -1,23 +1,37 @@ import { BaseMetadata } from '@/types/api/api-general'; import { Supplier } from '@/types/api/master-data/supplier'; -import { Warehouse } from '@/types/api/master-data/warehouse'; + +type MovementWarehouse = { + id: number; + name: string; + location: { + id: number; + name: string; + } | null; + area: { + id: number; + name: string; + }; +}; export type BaseMovement = { id: number; transfer_reason: string; transfer_date: string; - source_warehouse: Warehouse; - destination_warehouse: Warehouse; + source_warehouse: MovementWarehouse; + destination_warehouse: MovementWarehouse; details: { id: number; - product_id: number; + product: { + id: number; + name: string; + }; quantity: number; before_quantity: number; after_quantity: number; }[]; deliveries: { id: number; - supplier_id: number; supplier: Supplier; vehicle_plate: string; driver_name: string;