Merge branch 'dev/restu' of gitlab.com:mbugroup/lti-web-client into feat/FE/US-76/TASK-114-129-136-slicing-ui-and-validation-create-edit-daily-recording-growing-form

This commit is contained in:
rstubryan
2025-10-20 12:56:43 +07:00
2 changed files with 90 additions and 66 deletions
@@ -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,
@@ -913,6 +914,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
'product',
idx
)}
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/>
</td>
<td>
@@ -942,7 +947,8 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
}
readOnly={type === 'detail'}
className={{
wrapper: 'w-full min-w-48',
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/>
</td>
@@ -1081,6 +1087,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
options={getFilteredProductWarehouseOptions()}
isDisabled={type === 'detail'}
isClearable
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/>
</td>
<td>
@@ -1103,7 +1113,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
}
readOnly={type === 'detail'}
className={{
wrapper: 'w-full min-w-24',
wrapper: 'w-full min-w-48',
}}
/>
</td>
@@ -1126,6 +1136,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
isLoading={isLoadingSuppliers}
isDisabled={type === 'detail'}
isClearable
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/>
</td>
<td>
@@ -1141,31 +1155,51 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
idx
)}
readOnly={type === 'detail'}
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/>
</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'}
/>
}}
{...isRepeaterInputError(
'deliveries',
'document',
idx
)}
className={{
wrapper:
'w-full min-w-72 md:w-min-80 lg:w-min-96',
}}
/>
)}
</td>
<td>
<TextInput
@@ -1183,6 +1217,9 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
idx
)}
readOnly={type === 'detail'}
className={{
wrapper: 'w-full min-w-48',
}}
/>
</td>
<td>
@@ -1204,6 +1241,9 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
idx
)}
readOnly={type === 'detail'}
className={{
wrapper: 'w-full min-w-48',
}}
/>
</td>
<td>
@@ -1219,6 +1259,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
idx
)}
readOnly={type === 'detail'}
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/>
</td>
{type !== 'detail' && (
@@ -1276,12 +1320,6 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
<FormActions<MovementFormValues>
type={type}
formik={formik}
editUrl={
initialValues
? `/inventory/movement/detail/edit/?movementId=${initialValues.id}`
: undefined
}
onDelete={deleteMovementClickHandler}
disableSubmit={hasInvalidQty || hasExceededStock}
/>
@@ -1297,23 +1335,6 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
)}
</form>
</section>
{type !== 'add' && (
<ConfirmationModal
ref={deleteModal.ref}
type='error'
text={`Apakah anda yakin ingin menghapus data Movement ini?`}
secondaryButton={{
text: 'Tidak',
}}
primaryButton={{
text: 'Ya',
color: 'error',
isLoading: isDeleteLoading,
onClick: confirmationModalDeleteClickHandler,
}}
/>
)}
</>
);
};