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?: number | undefined;
delivery_cost_per_item?: number | undefined; delivery_cost_per_item?: number | undefined;
document?: File | string | null; document?: File | string | null;
document_path?: string | null;
driver_name: string; driver_name: string;
vehicle_plate: string; vehicle_plate: string;
supplier: { supplier: {
@@ -86,6 +87,7 @@ const DeliveryObjectSchema: Yup.ObjectSchema<DeliverySchema> = Yup.object({
); );
} }
), ),
document_path: Yup.string().optional(),
document_index: Yup.number().optional(), document_index: Yup.number().optional(),
document: Yup.mixed<File | string>() document: Yup.mixed<File | string>()
.nullable() .nullable()
@@ -161,8 +163,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, area: initialValues.source_warehouse.area?.name ?? undefined,
location: initialValues.source_warehouse.location?.name, location: initialValues.source_warehouse.location?.name ?? undefined,
} }
: null, : null,
source_warehouse_id: initialValues?.source_warehouse?.id ?? 0, source_warehouse_id: initialValues?.source_warehouse?.id ?? 0,
@@ -170,8 +172,9 @@ 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, area: initialValues.destination_warehouse.area?.name ?? undefined,
location: initialValues.destination_warehouse.location?.name, location:
initialValues.destination_warehouse.location?.name ?? undefined,
} }
: null, : null,
destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0, destination_warehouse_id: initialValues?.destination_warehouse?.id ?? 0,
@@ -185,19 +188,20 @@ export const getMovementFormInitialValues = (
product_qty: detail.quantity, product_qty: detail.quantity,
})) ?? [], })) ?? [],
deliveries: deliveries:
initialValues?.deliveries?.map((d) => { initialValues?.deliveries?.map((d) => ({
return { delivery_cost: d.shipping_cost_total ?? undefined,
delivery_cost: d.shipping_cost_total, delivery_cost_per_item: d.shipping_cost_item ?? undefined,
delivery_cost_per_item: d.shipping_cost_item, document_number: d.document_number ?? '',
document_index: 0, document: d.document_path ?? null,
document: d.document_path || null, document_path: d.document_path ?? null,
driver_name: d.driver_name, driver_name: d.driver_name ?? '',
vehicle_plate: d.vehicle_plate, vehicle_plate: d.vehicle_plate ?? '',
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 ?? 0, supplier_id: d.supplier?.id ?? 0,
products: d.items.map((item) => { products:
d.items?.map((item) => {
const productData = detailIdToProductId.get( const productData = detailIdToProductId.get(
item.stock_transfer_detail_id item.stock_transfer_detail_id
); );
@@ -208,8 +212,7 @@ export const getMovementFormInitialValues = (
product_id: productData?.id ?? 0, product_id: productData?.id ?? 0,
product_qty: item.quantity, product_qty: item.quantity,
}; };
}), }) ?? [],
}; })) ?? [],
}) ?? [],
}; };
}; };
@@ -83,6 +83,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
delivery_cost: d.delivery_cost ?? 0, delivery_cost: d.delivery_cost ?? 0,
delivery_cost_per_item: d.delivery_cost_per_item ?? 0, delivery_cost_per_item: d.delivery_cost_per_item ?? 0,
document_index: documentIndex, document_index: documentIndex,
document_path: d.document_path,
driver_name: d.driver_name, driver_name: d.driver_name,
vehicle_plate: d.vehicle_plate, vehicle_plate: d.vehicle_plate,
supplier_id: d.supplier_id, supplier_id: d.supplier_id,
@@ -913,6 +914,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
'product', 'product',
idx idx
)} )}
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/> />
</td> </td>
<td> <td>
@@ -942,7 +947,8 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
} }
readOnly={type === 'detail'} readOnly={type === 'detail'}
className={{ className={{
wrapper: 'w-full min-w-48', wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}} }}
/> />
</td> </td>
@@ -1081,6 +1087,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
options={getFilteredProductWarehouseOptions()} options={getFilteredProductWarehouseOptions()}
isDisabled={type === 'detail'} isDisabled={type === 'detail'}
isClearable isClearable
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/> />
</td> </td>
<td> <td>
@@ -1103,7 +1113,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
} }
readOnly={type === 'detail'} readOnly={type === 'detail'}
className={{ className={{
wrapper: 'w-full min-w-24', wrapper: 'w-full min-w-48',
}} }}
/> />
</td> </td>
@@ -1126,6 +1136,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
isLoading={isLoadingSuppliers} isLoading={isLoadingSuppliers}
isDisabled={type === 'detail'} isDisabled={type === 'detail'}
isClearable isClearable
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/> />
</td> </td>
<td> <td>
@@ -1141,31 +1155,51 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
idx idx
)} )}
readOnly={type === 'detail'} readOnly={type === 'detail'}
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/> />
</td> </td>
<td> <td>
<FileInput {type === 'detail' ? (
name={`deliveries.${idx}.document`} <TextInput
onChange={(e) => { readOnly
const file = e.target.files?.[0]; value={delivery.document_path || '-'}
if (file) { className={{
if (file.size > 2 * 1024 * 1024) { wrapper: 'w-full min-w-52 md:w-72 lg:w-80',
toast.error('Ukuran dokumen maksimal 2 MB!'); }}
return; 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`, {...isRepeaterInputError(
file 'deliveries',
); 'document',
} idx
}} )}
{...isRepeaterInputError( className={{
'deliveries', wrapper:
'document', 'w-full min-w-72 md:w-min-80 lg:w-min-96',
idx }}
)} />
readOnly={type === 'detail'} )}
/>
</td> </td>
<td> <td>
<TextInput <TextInput
@@ -1183,6 +1217,9 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
idx idx
)} )}
readOnly={type === 'detail'} readOnly={type === 'detail'}
className={{
wrapper: 'w-full min-w-48',
}}
/> />
</td> </td>
<td> <td>
@@ -1204,6 +1241,9 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
idx idx
)} )}
readOnly={type === 'detail'} readOnly={type === 'detail'}
className={{
wrapper: 'w-full min-w-48',
}}
/> />
</td> </td>
<td> <td>
@@ -1219,6 +1259,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
idx idx
)} )}
readOnly={type === 'detail'} readOnly={type === 'detail'}
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/> />
</td> </td>
{type !== 'detail' && ( {type !== 'detail' && (
@@ -1276,12 +1320,6 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
<FormActions<MovementFormValues> <FormActions<MovementFormValues>
type={type} type={type}
formik={formik} formik={formik}
editUrl={
initialValues
? `/inventory/movement/detail/edit/?movementId=${initialValues.id}`
: undefined
}
onDelete={deleteMovementClickHandler}
disableSubmit={hasInvalidQty || hasExceededStock} disableSubmit={hasInvalidQty || hasExceededStock}
/> />
@@ -1297,23 +1335,6 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
)} )}
</form> </form>
</section> </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,
}}
/>
)}
</> </>
); );
}; };