mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-63,65): update Movement types and schema to include area and location for warehouses
This commit is contained in:
@@ -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<typeof MovementFormSchema>;
|
||||
export const getMovementFormInitialValues = (
|
||||
initialValues?: Movement
|
||||
): MovementFormValues => {
|
||||
const detailIdToProductId = new Map<number, number>();
|
||||
const detailIdToProductId = new Map<number, { id: number; name: string }>();
|
||||
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,
|
||||
};
|
||||
}),
|
||||
|
||||
+19
-5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user