mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
Merge branch 'fix/adjustment-transfer-stock-form' into 'development'
[HOTFIX/FE] Require Delivery Fields if Supplier Chosen See merge request mbugroup/lti-web-client!280
This commit is contained in:
@@ -123,23 +123,61 @@ const DeliveryObjectSchema: Yup.ObjectSchema<DeliverySchema> = Yup.object({
|
||||
.transform((value) =>
|
||||
isNaN(value) || value === '' || value === null ? undefined : value
|
||||
)
|
||||
.optional()
|
||||
.nullable()
|
||||
.min(1, 'Biaya minimal 1!')
|
||||
.typeError('Biaya harus berupa angka!'),
|
||||
.when('supplier_id', {
|
||||
is: (supplier_id: number | null | undefined) =>
|
||||
supplier_id !== null && supplier_id !== undefined && supplier_id > 0,
|
||||
then: (schema) =>
|
||||
schema
|
||||
.required('Biaya pengiriman wajib diisi!')
|
||||
.min(1, 'Biaya minimal 1!')
|
||||
.typeError('Biaya harus berupa angka!'),
|
||||
otherwise: (schema) =>
|
||||
schema
|
||||
.optional()
|
||||
.nullable()
|
||||
.min(1, 'Biaya minimal 1!')
|
||||
.typeError('Biaya harus berupa angka!'),
|
||||
}),
|
||||
delivery_cost_per_item: Yup.number()
|
||||
.transform((value) =>
|
||||
isNaN(value) || value === '' || value === null ? undefined : value
|
||||
)
|
||||
.optional()
|
||||
.nullable()
|
||||
.min(1, 'Biaya per item minimal 1!')
|
||||
.typeError('Biaya per item harus berupa angka!'),
|
||||
.when('supplier_id', {
|
||||
is: (supplier_id: number | null | undefined) =>
|
||||
supplier_id !== null && supplier_id !== undefined && supplier_id > 0,
|
||||
then: (schema) =>
|
||||
schema
|
||||
.required('Biaya per item wajib diisi!')
|
||||
.min(1, 'Biaya per item minimal 1!')
|
||||
.typeError('Biaya per item harus berupa angka!'),
|
||||
otherwise: (schema) =>
|
||||
schema
|
||||
.optional()
|
||||
.nullable()
|
||||
.min(1, 'Biaya per item minimal 1!')
|
||||
.typeError('Biaya per item harus berupa angka!'),
|
||||
}),
|
||||
document_path: Yup.string().nullable().optional(),
|
||||
document_index: Yup.number().optional(),
|
||||
document: DeliveryDocumentSchema,
|
||||
driver_name: Yup.string().optional().nullable(),
|
||||
vehicle_plate: Yup.string().optional().nullable(),
|
||||
driver_name: Yup.string().when('supplier_id', {
|
||||
is: (supplier_id: number | null | undefined) =>
|
||||
supplier_id !== null && supplier_id !== undefined && supplier_id > 0,
|
||||
then: (schema) =>
|
||||
schema
|
||||
.required('Nama sopir wajib diisi!')
|
||||
.min(1, 'Nama sopir wajib diisi!'),
|
||||
otherwise: (schema) => schema.optional().nullable(),
|
||||
}),
|
||||
vehicle_plate: Yup.string().when('supplier_id', {
|
||||
is: (supplier_id: number | null | undefined) =>
|
||||
supplier_id !== null && supplier_id !== undefined && supplier_id > 0,
|
||||
then: (schema) =>
|
||||
schema
|
||||
.required('Plat nomor wajib diisi!')
|
||||
.min(1, 'Plat nomor wajib diisi!'),
|
||||
otherwise: (schema) => schema.optional().nullable(),
|
||||
}),
|
||||
supplier: Yup.object({
|
||||
value: Yup.number().min(1).required(),
|
||||
label: Yup.string().required(),
|
||||
|
||||
@@ -984,6 +984,28 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
[formik.values.deliveries, formik.values.products, type]
|
||||
);
|
||||
|
||||
const isSupplierSelected = useCallback(
|
||||
(deliveryIdx: number) => {
|
||||
const delivery = formik.values.deliveries?.[deliveryIdx];
|
||||
return (
|
||||
delivery &&
|
||||
delivery.supplier_id !== null &&
|
||||
delivery.supplier_id !== undefined &&
|
||||
delivery.supplier_id > 0
|
||||
);
|
||||
},
|
||||
[formik.values.deliveries]
|
||||
);
|
||||
|
||||
const hasAnySupplierSelected = useMemo(() => {
|
||||
return formik.values.deliveries?.some(
|
||||
(delivery) =>
|
||||
delivery.supplier_id !== null &&
|
||||
delivery.supplier_id !== undefined &&
|
||||
delivery.supplier_id > 0
|
||||
);
|
||||
}, [formik.values.deliveries]);
|
||||
|
||||
// ===== COMPUTED VALUES =====
|
||||
const invalidQtyRows = useMemo(
|
||||
() =>
|
||||
@@ -1659,12 +1681,62 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
<span className='text-error'>*</span>
|
||||
</span>
|
||||
</th>
|
||||
<th>Supplier</th>
|
||||
<th>Plat Nomor</th>
|
||||
<th>
|
||||
Supplier
|
||||
{hasAnySupplierSelected && (
|
||||
<span
|
||||
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||
data-tip='required jika supplier dipilih'
|
||||
>
|
||||
<span className='text-error'>*</span>
|
||||
</span>
|
||||
)}
|
||||
</th>
|
||||
<th>
|
||||
Plat Nomor
|
||||
{hasAnySupplierSelected && (
|
||||
<span
|
||||
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||
data-tip='required jika supplier dipilih'
|
||||
>
|
||||
<span className='text-error'>*</span>
|
||||
</span>
|
||||
)}
|
||||
</th>
|
||||
<th>Dokumen</th>
|
||||
<th>Biaya Pengiriman (Rp.)</th>
|
||||
<th>Biaya Per Item (Rp.)</th>
|
||||
<th>Nama Sopir</th>
|
||||
<th>
|
||||
Biaya Pengiriman (Rp.)
|
||||
{hasAnySupplierSelected && (
|
||||
<span
|
||||
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||
data-tip='required jika supplier dipilih'
|
||||
>
|
||||
<span className='text-error'>*</span>
|
||||
</span>
|
||||
)}
|
||||
</th>
|
||||
<th>
|
||||
Biaya Per Item (Rp.)
|
||||
{hasAnySupplierSelected && (
|
||||
<span
|
||||
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||
data-tip='required jika supplier dipilih'
|
||||
>
|
||||
<span className='text-error'>*</span>
|
||||
</span>
|
||||
)}
|
||||
</th>
|
||||
<th>
|
||||
Nama Sopir
|
||||
{hasAnySupplierSelected && (
|
||||
<span
|
||||
className='tooltip tooltip-error tooltip-bottom z-9999'
|
||||
data-tip='required jika supplier dipilih'
|
||||
>
|
||||
<span className='text-error'>*</span>
|
||||
</span>
|
||||
)}
|
||||
</th>
|
||||
{type !== 'detail' && <th>Aksi</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -1772,6 +1844,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
idx
|
||||
)}
|
||||
readOnly={type === 'detail'}
|
||||
required={isSupplierSelected(idx)}
|
||||
className={{
|
||||
wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
||||
}}
|
||||
@@ -1867,6 +1940,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
idx
|
||||
)}
|
||||
readOnly={type === 'detail'}
|
||||
required={isSupplierSelected(idx)}
|
||||
className={{
|
||||
wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
||||
}}
|
||||
@@ -1890,6 +1964,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
idx
|
||||
)}
|
||||
readOnly={type === 'detail'}
|
||||
required={isSupplierSelected(idx)}
|
||||
className={{
|
||||
wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
||||
}}
|
||||
@@ -1908,6 +1983,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
idx
|
||||
)}
|
||||
readOnly={type === 'detail'}
|
||||
required={isSupplierSelected(idx)}
|
||||
className={{
|
||||
wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user