mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
feat(FE-62,63,65): add document_path field to deliveries in MovementForm
This commit is contained in:
@@ -14,6 +14,7 @@ export type DeliverySchema = {
|
||||
delivery_cost?: number | undefined;
|
||||
delivery_cost_per_item?: number | undefined;
|
||||
document?: File | string | null;
|
||||
document_path?: string | null;
|
||||
driver_name: string;
|
||||
vehicle_plate: string;
|
||||
supplier: {
|
||||
@@ -86,6 +87,7 @@ const DeliveryObjectSchema: Yup.ObjectSchema<DeliverySchema> = Yup.object({
|
||||
);
|
||||
}
|
||||
),
|
||||
document_path: Yup.string().optional(),
|
||||
document_index: Yup.number().optional(),
|
||||
document: Yup.mixed<File | string>()
|
||||
.nullable()
|
||||
@@ -161,8 +163,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,
|
||||
area: initialValues.source_warehouse.area?.name ?? undefined,
|
||||
location: initialValues.source_warehouse.location?.name ?? undefined,
|
||||
}
|
||||
: null,
|
||||
source_warehouse_id: initialValues?.source_warehouse?.id ?? 0,
|
||||
@@ -170,8 +172,9 @@ 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,
|
||||
area: initialValues.destination_warehouse.area?.name ?? undefined,
|
||||
location:
|
||||
initialValues.destination_warehouse.location?.name ?? undefined,
|
||||
}
|
||||
: null,
|
||||
destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0,
|
||||
@@ -185,19 +188,20 @@ export const getMovementFormInitialValues = (
|
||||
product_qty: detail.quantity,
|
||||
})) ?? [],
|
||||
deliveries:
|
||||
initialValues?.deliveries?.map((d) => {
|
||||
return {
|
||||
delivery_cost: d.shipping_cost_total,
|
||||
delivery_cost_per_item: d.shipping_cost_item,
|
||||
document_index: 0,
|
||||
document: d.document_path || null,
|
||||
driver_name: d.driver_name,
|
||||
vehicle_plate: d.vehicle_plate,
|
||||
supplier: d.supplier
|
||||
? { value: d.supplier.id, label: d.supplier.name }
|
||||
: null,
|
||||
supplier_id: d.supplier?.id ?? 0,
|
||||
products: d.items.map((item) => {
|
||||
initialValues?.deliveries?.map((d) => ({
|
||||
delivery_cost: d.shipping_cost_total ?? undefined,
|
||||
delivery_cost_per_item: d.shipping_cost_item ?? undefined,
|
||||
document_number: d.document_number ?? '',
|
||||
document: d.document_path ?? null,
|
||||
document_path: d.document_path ?? null,
|
||||
driver_name: d.driver_name ?? '',
|
||||
vehicle_plate: d.vehicle_plate ?? '',
|
||||
supplier: d.supplier
|
||||
? { value: d.supplier.id, label: d.supplier.name }
|
||||
: null,
|
||||
supplier_id: d.supplier?.id ?? 0,
|
||||
products:
|
||||
d.items?.map((item) => {
|
||||
const productData = detailIdToProductId.get(
|
||||
item.stock_transfer_detail_id
|
||||
);
|
||||
@@ -208,8 +212,7 @@ export const getMovementFormInitialValues = (
|
||||
product_id: productData?.id ?? 0,
|
||||
product_qty: item.quantity,
|
||||
};
|
||||
}),
|
||||
};
|
||||
}) ?? [],
|
||||
}) ?? [],
|
||||
})) ?? [],
|
||||
};
|
||||
};
|
||||
|
||||
@@ -83,6 +83,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
delivery_cost: d.delivery_cost ?? 0,
|
||||
delivery_cost_per_item: d.delivery_cost_per_item ?? 0,
|
||||
document_index: documentIndex,
|
||||
document_path: d.document_path,
|
||||
driver_name: d.driver_name,
|
||||
vehicle_plate: d.vehicle_plate,
|
||||
supplier_id: d.supplier_id,
|
||||
@@ -1156,32 +1157,44 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<FileInput
|
||||
name={`deliveries.${idx}.document`}
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) {
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
toast.error('Ukuran dokumen maksimal 2 MB!');
|
||||
return;
|
||||
{type === 'detail' ? (
|
||||
<TextInput
|
||||
readOnly
|
||||
value={delivery.document_path || '-'}
|
||||
className={{
|
||||
wrapper: 'w-full min-w-52 md:w-72 lg:w-80',
|
||||
}}
|
||||
name={`deliveries.${idx}.document_path`}
|
||||
/>
|
||||
) : (
|
||||
<FileInput
|
||||
name={`deliveries.${idx}.document`}
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) {
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
toast.error(
|
||||
'Ukuran dokumen maksimal 2 MB!'
|
||||
);
|
||||
return;
|
||||
}
|
||||
formik.setFieldValue(
|
||||
`deliveries.${idx}.document`,
|
||||
file
|
||||
);
|
||||
}
|
||||
formik.setFieldValue(
|
||||
`deliveries.${idx}.document`,
|
||||
file
|
||||
);
|
||||
}
|
||||
}}
|
||||
{...isRepeaterInputError(
|
||||
'deliveries',
|
||||
'document',
|
||||
idx
|
||||
)}
|
||||
readOnly={type === 'detail'}
|
||||
className={{
|
||||
wrapper:
|
||||
'w-full min-w-72 md:w-min-80 lg:w-min-96',
|
||||
}}
|
||||
/>
|
||||
}}
|
||||
{...isRepeaterInputError(
|
||||
'deliveries',
|
||||
'document',
|
||||
idx
|
||||
)}
|
||||
className={{
|
||||
wrapper:
|
||||
'w-full min-w-72 md:w-min-80 lg:w-min-96',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<TextInput
|
||||
|
||||
Reference in New Issue
Block a user