mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
refactor(FE-207,212): update PurchaseRequestForm schema and validation, enforce required fields and improve data handling for purchase items
This commit is contained in:
@@ -142,19 +142,32 @@ const PurchaseRequestForm = ({
|
||||
validateOnBlur: true,
|
||||
onSubmit: async (values) => {
|
||||
const payload: CreatePurchaseRequestPayload = {
|
||||
supplier_id: values.supplier_id || 0,
|
||||
credit_term: values.credit_term || 0,
|
||||
supplier_id:
|
||||
typeof values.supplier_id === 'string'
|
||||
? parseInt(values.supplier_id) || 0
|
||||
: values.supplier_id || 0,
|
||||
credit_term:
|
||||
typeof values.credit_term === 'string'
|
||||
? parseInt(values.credit_term) || 0
|
||||
: values.credit_term || 0,
|
||||
notes: values.notes || '',
|
||||
purchase_items: (values.purchase_items || []).map((item) => ({
|
||||
warehouse_id: item.warehouse_id || 0,
|
||||
product_id: item.product_id || 0,
|
||||
product_warehouse_id: item.product_warehouse_id || undefined,
|
||||
sub_qty: item.sub_qty || 0,
|
||||
total_qty: item.total_qty || 0,
|
||||
price:
|
||||
typeof item.price === 'number'
|
||||
? item.price
|
||||
: parseFloat(item.price) || 0,
|
||||
warehouse_id:
|
||||
typeof item.warehouse_id === 'string'
|
||||
? parseInt(item.warehouse_id) || 0
|
||||
: item.warehouse_id || 0,
|
||||
product_id:
|
||||
typeof item.product_id === 'string'
|
||||
? parseInt(item.product_id) || 0
|
||||
: item.product_id || 0,
|
||||
product_warehouse_id:
|
||||
typeof item.product_warehouse_id === 'string'
|
||||
? parseInt(item.product_warehouse_id) || 0
|
||||
: item.product_warehouse_id || 0,
|
||||
sub_qty:
|
||||
typeof item.sub_qty === 'string'
|
||||
? parseFloat(item.sub_qty) || 0
|
||||
: item.sub_qty || 0,
|
||||
})),
|
||||
};
|
||||
|
||||
@@ -193,14 +206,12 @@ const PurchaseRequestForm = ({
|
||||
...(formik.values.purchase_items || []),
|
||||
{
|
||||
warehouse: null,
|
||||
warehouse_id: 0,
|
||||
warehouse_id: '',
|
||||
product: null,
|
||||
product_id: 0,
|
||||
product_id: '',
|
||||
product_warehouse: null,
|
||||
product_warehouse_id: null,
|
||||
sub_qty: 0,
|
||||
total_qty: 0,
|
||||
price: 0,
|
||||
sub_qty: '',
|
||||
},
|
||||
];
|
||||
formik.setFieldValue('purchase_items', newPurchaseItems);
|
||||
@@ -285,12 +296,11 @@ const PurchaseRequestForm = ({
|
||||
type='number'
|
||||
placeholder='Masukkan Supplier ID'
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
required
|
||||
label='Jatuh tempo (hari)'
|
||||
name='credit_term'
|
||||
value={formik.values.credit_term}
|
||||
value={formik.values.credit_term || ''}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur}
|
||||
isError={
|
||||
@@ -303,6 +313,28 @@ const PurchaseRequestForm = ({
|
||||
placeholder='Masukkan Credit Term'
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
required
|
||||
label='Area'
|
||||
name='area_id'
|
||||
onChange={(e) => {}}
|
||||
onBlur={formik.handleBlur}
|
||||
readOnly={type === 'detail'}
|
||||
type='number'
|
||||
placeholder='Pilih Area'
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
required
|
||||
label='Lokasi'
|
||||
name='location_id'
|
||||
onChange={(e) => {}}
|
||||
onBlur={formik.handleBlur}
|
||||
readOnly={type === 'detail'}
|
||||
type='number'
|
||||
placeholder='Pilih Lokasi'
|
||||
/>
|
||||
|
||||
<div className={type === 'detail' ? 'col-span-1' : 'col-span-2'}>
|
||||
<TextInput
|
||||
label='Notes'
|
||||
@@ -356,29 +388,19 @@ const PurchaseRequestForm = ({
|
||||
</th>
|
||||
)}
|
||||
<th>
|
||||
Warehouse ID
|
||||
Gudang
|
||||
<span className='text-error'>*</span>
|
||||
</th>
|
||||
<th>
|
||||
Product ID
|
||||
Item
|
||||
<span className='text-error'>*</span>
|
||||
</th>
|
||||
<th>
|
||||
Product Warehouse ID
|
||||
<span className='text-error'>*</span>
|
||||
</th>
|
||||
<th>
|
||||
Sub Qty
|
||||
<span className='text-error'>*</span>
|
||||
</th>
|
||||
<th>
|
||||
Total Qty
|
||||
<span className='text-error'>*</span>
|
||||
</th>
|
||||
<th>
|
||||
Price
|
||||
Jumlah
|
||||
<span className='text-error'>*</span>
|
||||
</th>
|
||||
<th>Estimasi Harga</th>
|
||||
<th>Satuan</th>
|
||||
{type !== 'detail' && <th>Action</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -410,7 +432,7 @@ const PurchaseRequestForm = ({
|
||||
<TextInput
|
||||
required
|
||||
name={`purchase_items.${idx}.warehouse_id`}
|
||||
value={item.warehouse_id}
|
||||
value={item.warehouse_id || ''}
|
||||
onChange={(e) =>
|
||||
handlePurchaseItemChange(
|
||||
idx,
|
||||
@@ -420,28 +442,7 @@ const PurchaseRequestForm = ({
|
||||
}
|
||||
onBlur={formik.handleBlur}
|
||||
type='number'
|
||||
placeholder='Warehouse ID'
|
||||
readOnly={type === 'detail'}
|
||||
className={{
|
||||
wrapper: 'min-w-24',
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<TextInput
|
||||
required
|
||||
name={`purchase_items.${idx}.product_id`}
|
||||
value={item.product_id}
|
||||
onChange={(e) =>
|
||||
handlePurchaseItemChange(
|
||||
idx,
|
||||
'product_id',
|
||||
e.target.value
|
||||
)
|
||||
}
|
||||
onBlur={formik.handleBlur}
|
||||
type='number'
|
||||
placeholder='Product ID'
|
||||
placeholder='Masukkan Warehouse ID'
|
||||
readOnly={type === 'detail'}
|
||||
className={{
|
||||
wrapper: 'min-w-24',
|
||||
@@ -472,7 +473,7 @@ const PurchaseRequestForm = ({
|
||||
<TextInput
|
||||
required
|
||||
name={`purchase_items.${idx}.sub_qty`}
|
||||
value={item.sub_qty}
|
||||
value={item.sub_qty || ''}
|
||||
onChange={(e) =>
|
||||
handlePurchaseItemChange(
|
||||
idx,
|
||||
@@ -482,28 +483,7 @@ const PurchaseRequestForm = ({
|
||||
}
|
||||
onBlur={formik.handleBlur}
|
||||
type='number'
|
||||
placeholder='Sub Qty'
|
||||
readOnly={type === 'detail'}
|
||||
className={{
|
||||
wrapper: 'min-w-24',
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<TextInput
|
||||
required
|
||||
name={`purchase_items.${idx}.total_qty`}
|
||||
value={item.total_qty}
|
||||
onChange={(e) =>
|
||||
handlePurchaseItemChange(
|
||||
idx,
|
||||
'total_qty',
|
||||
e.target.value
|
||||
)
|
||||
}
|
||||
onBlur={formik.handleBlur}
|
||||
type='number'
|
||||
placeholder='Total Qty'
|
||||
placeholder='Masukkan kuantitas'
|
||||
readOnly={type === 'detail'}
|
||||
className={{
|
||||
wrapper: 'min-w-24',
|
||||
@@ -514,7 +494,6 @@ const PurchaseRequestForm = ({
|
||||
<TextInput
|
||||
required
|
||||
name={`purchase_items.${idx}.price`}
|
||||
value={item.price}
|
||||
onChange={(e) =>
|
||||
handlePurchaseItemChange(
|
||||
idx,
|
||||
@@ -524,8 +503,22 @@ const PurchaseRequestForm = ({
|
||||
}
|
||||
onBlur={formik.handleBlur}
|
||||
type='number'
|
||||
placeholder='Price'
|
||||
readOnly={type === 'detail'}
|
||||
className={{
|
||||
wrapper: 'min-w-24',
|
||||
}}
|
||||
disabled={true}
|
||||
readOnly={true}
|
||||
inputPrefix={'Rp'}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<TextInput
|
||||
required
|
||||
name={`purchase_items.${idx}.uom`}
|
||||
onBlur={formik.handleBlur}
|
||||
type='number'
|
||||
readOnly={true}
|
||||
disabled={true}
|
||||
className={{
|
||||
wrapper: 'min-w-24',
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user