mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
fix(FE): Require delivery fields if supplier chosen
This commit is contained in:
@@ -123,23 +123,61 @@ const DeliveryObjectSchema: Yup.ObjectSchema<DeliverySchema> = Yup.object({
|
|||||||
.transform((value) =>
|
.transform((value) =>
|
||||||
isNaN(value) || value === '' || value === null ? undefined : value
|
isNaN(value) || value === '' || value === null ? undefined : value
|
||||||
)
|
)
|
||||||
.optional()
|
.when('supplier_id', {
|
||||||
.nullable()
|
is: (supplier_id: number | null | undefined) =>
|
||||||
.min(1, 'Biaya minimal 1!')
|
supplier_id !== null && supplier_id !== undefined && supplier_id > 0,
|
||||||
.typeError('Biaya harus berupa angka!'),
|
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()
|
delivery_cost_per_item: Yup.number()
|
||||||
.transform((value) =>
|
.transform((value) =>
|
||||||
isNaN(value) || value === '' || value === null ? undefined : value
|
isNaN(value) || value === '' || value === null ? undefined : value
|
||||||
)
|
)
|
||||||
.optional()
|
.when('supplier_id', {
|
||||||
.nullable()
|
is: (supplier_id: number | null | undefined) =>
|
||||||
.min(1, 'Biaya per item minimal 1!')
|
supplier_id !== null && supplier_id !== undefined && supplier_id > 0,
|
||||||
.typeError('Biaya per item harus berupa angka!'),
|
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_path: Yup.string().nullable().optional(),
|
||||||
document_index: Yup.number().optional(),
|
document_index: Yup.number().optional(),
|
||||||
document: DeliveryDocumentSchema,
|
document: DeliveryDocumentSchema,
|
||||||
driver_name: Yup.string().optional().nullable(),
|
driver_name: Yup.string().when('supplier_id', {
|
||||||
vehicle_plate: Yup.string().optional().nullable(),
|
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({
|
supplier: Yup.object({
|
||||||
value: Yup.number().min(1).required(),
|
value: Yup.number().min(1).required(),
|
||||||
label: Yup.string().required(),
|
label: Yup.string().required(),
|
||||||
|
|||||||
@@ -984,6 +984,28 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
[formik.values.deliveries, formik.values.products, type]
|
[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 =====
|
// ===== COMPUTED VALUES =====
|
||||||
const invalidQtyRows = useMemo(
|
const invalidQtyRows = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -1659,12 +1681,62 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
<span className='text-error'>*</span>
|
<span className='text-error'>*</span>
|
||||||
</span>
|
</span>
|
||||||
</th>
|
</th>
|
||||||
<th>Supplier</th>
|
<th>
|
||||||
<th>Plat Nomor</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>Dokumen</th>
|
||||||
<th>Biaya Pengiriman (Rp.)</th>
|
<th>
|
||||||
<th>Biaya Per Item (Rp.)</th>
|
Biaya Pengiriman (Rp.)
|
||||||
<th>Nama Sopir</th>
|
{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>}
|
{type !== 'detail' && <th>Aksi</th>}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -1772,6 +1844,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
|||||||
idx
|
idx
|
||||||
)}
|
)}
|
||||||
readOnly={type === 'detail'}
|
readOnly={type === 'detail'}
|
||||||
|
required={isSupplierSelected(idx)}
|
||||||
className={{
|
className={{
|
||||||
wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
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
|
idx
|
||||||
)}
|
)}
|
||||||
readOnly={type === 'detail'}
|
readOnly={type === 'detail'}
|
||||||
|
required={isSupplierSelected(idx)}
|
||||||
className={{
|
className={{
|
||||||
wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
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
|
idx
|
||||||
)}
|
)}
|
||||||
readOnly={type === 'detail'}
|
readOnly={type === 'detail'}
|
||||||
|
required={isSupplierSelected(idx)}
|
||||||
className={{
|
className={{
|
||||||
wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
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
|
idx
|
||||||
)}
|
)}
|
||||||
readOnly={type === 'detail'}
|
readOnly={type === 'detail'}
|
||||||
|
required={isSupplierSelected(idx)}
|
||||||
className={{
|
className={{
|
||||||
wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user