mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +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({
|
source_warehouse: Yup.object({
|
||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
|
area: Yup.string().optional(),
|
||||||
|
location: Yup.string().optional(),
|
||||||
}).nullable(),
|
}).nullable(),
|
||||||
source_warehouse_id: Yup.number()
|
source_warehouse_id: Yup.number()
|
||||||
.required('Gudang asal wajib diisi!')
|
.required('Gudang asal wajib diisi!')
|
||||||
@@ -99,6 +101,8 @@ export const MovementFormSchema = Yup.object({
|
|||||||
destination_warehouse: Yup.object({
|
destination_warehouse: Yup.object({
|
||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
|
area: Yup.string().optional(),
|
||||||
|
location: Yup.string().optional(),
|
||||||
}).nullable(),
|
}).nullable(),
|
||||||
destination_warehouse_id: Yup.number()
|
destination_warehouse_id: Yup.number()
|
||||||
.required('Gudang tujuan wajib diisi!')
|
.required('Gudang tujuan wajib diisi!')
|
||||||
@@ -120,9 +124,12 @@ export type MovementFormValues = Yup.InferType<typeof MovementFormSchema>;
|
|||||||
export const getMovementFormInitialValues = (
|
export const getMovementFormInitialValues = (
|
||||||
initialValues?: Movement
|
initialValues?: Movement
|
||||||
): MovementFormValues => {
|
): MovementFormValues => {
|
||||||
const detailIdToProductId = new Map<number, number>();
|
const detailIdToProductId = new Map<number, { id: number; name: string }>();
|
||||||
initialValues?.details?.forEach((detail) => {
|
initialValues?.details?.forEach((detail) => {
|
||||||
detailIdToProductId.set(detail.id, detail.product_id);
|
detailIdToProductId.set(detail.id, {
|
||||||
|
id: detail.product.id,
|
||||||
|
name: detail.product.name,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -132,6 +139,8 @@ export const getMovementFormInitialValues = (
|
|||||||
? {
|
? {
|
||||||
value: initialValues.source_warehouse.id,
|
value: initialValues.source_warehouse.id,
|
||||||
label: initialValues.source_warehouse.name,
|
label: initialValues.source_warehouse.name,
|
||||||
|
area: initialValues.source_warehouse.area?.name,
|
||||||
|
location: initialValues.source_warehouse.location?.name,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
source_warehouse_id: initialValues?.source_warehouse?.id ?? 0,
|
source_warehouse_id: initialValues?.source_warehouse?.id ?? 0,
|
||||||
@@ -139,14 +148,19 @@ export const getMovementFormInitialValues = (
|
|||||||
? {
|
? {
|
||||||
value: initialValues.destination_warehouse.id,
|
value: initialValues.destination_warehouse.id,
|
||||||
label: initialValues.destination_warehouse.name,
|
label: initialValues.destination_warehouse.name,
|
||||||
|
area: initialValues.destination_warehouse.area?.name,
|
||||||
|
location: initialValues.destination_warehouse.location?.name,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0,
|
destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0,
|
||||||
products:
|
products:
|
||||||
initialValues?.details?.map((p) => ({
|
initialValues?.details?.map((detail) => ({
|
||||||
product: { value: p.product_id, label: `Product ID: ${p.product_id}` },
|
product: {
|
||||||
product_id: p.product_id,
|
value: detail.product.id,
|
||||||
product_qty: p.quantity,
|
label: detail.product.name,
|
||||||
|
},
|
||||||
|
product_id: detail.product.id,
|
||||||
|
product_qty: detail.quantity,
|
||||||
})) ?? [],
|
})) ?? [],
|
||||||
deliveries:
|
deliveries:
|
||||||
initialValues?.deliveries?.map((d) => {
|
initialValues?.deliveries?.map((d) => {
|
||||||
@@ -160,16 +174,16 @@ export const getMovementFormInitialValues = (
|
|||||||
supplier: d.supplier
|
supplier: d.supplier
|
||||||
? { value: d.supplier.id, label: d.supplier.name }
|
? { value: d.supplier.id, label: d.supplier.name }
|
||||||
: null,
|
: null,
|
||||||
supplier_id: d.supplier_id,
|
supplier_id: d.supplier?.id ?? 0,
|
||||||
products: d.items.map((item) => {
|
products: d.items.map((item) => {
|
||||||
const productId =
|
const productData = detailIdToProductId.get(
|
||||||
detailIdToProductId.get(item.stock_transfer_detail_id) ?? 0;
|
item.stock_transfer_detail_id
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
product:
|
product: productData
|
||||||
productId > 0
|
? { value: productData.id, label: productData.name }
|
||||||
? { value: productId, label: `Product ID: ${productId}` }
|
: null,
|
||||||
: null,
|
product_id: productData?.id ?? 0,
|
||||||
product_id: productId,
|
|
||||||
product_qty: item.quantity,
|
product_qty: item.quantity,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|||||||
+19
-5
@@ -1,23 +1,37 @@
|
|||||||
import { BaseMetadata } from '@/types/api/api-general';
|
import { BaseMetadata } from '@/types/api/api-general';
|
||||||
import { Supplier } from '@/types/api/master-data/supplier';
|
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 = {
|
export type BaseMovement = {
|
||||||
id: number;
|
id: number;
|
||||||
transfer_reason: string;
|
transfer_reason: string;
|
||||||
transfer_date: string;
|
transfer_date: string;
|
||||||
source_warehouse: Warehouse;
|
source_warehouse: MovementWarehouse;
|
||||||
destination_warehouse: Warehouse;
|
destination_warehouse: MovementWarehouse;
|
||||||
details: {
|
details: {
|
||||||
id: number;
|
id: number;
|
||||||
product_id: number;
|
product: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
quantity: number;
|
quantity: number;
|
||||||
before_quantity: number;
|
before_quantity: number;
|
||||||
after_quantity: number;
|
after_quantity: number;
|
||||||
}[];
|
}[];
|
||||||
deliveries: {
|
deliveries: {
|
||||||
id: number;
|
id: number;
|
||||||
supplier_id: number;
|
|
||||||
supplier: Supplier;
|
supplier: Supplier;
|
||||||
vehicle_plate: string;
|
vehicle_plate: string;
|
||||||
driver_name: string;
|
driver_name: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user