mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Support add/edit type and use ProductPrice for add
This commit is contained in:
@@ -312,7 +312,8 @@ export const PurchaseRequestStaffApprovalFormInitialValues: PurchaseRequestStaff
|
||||
};
|
||||
|
||||
export const PurchaseRequestStaffApprovalFormDefaultValues = (
|
||||
purchase?: Purchase
|
||||
purchase?: Purchase,
|
||||
type?: 'add' | 'edit'
|
||||
): PurchaseRequestStaffApprovalFormSchemaType => {
|
||||
return {
|
||||
action: 'APPROVED',
|
||||
@@ -331,8 +332,12 @@ export const PurchaseRequestStaffApprovalFormDefaultValues = (
|
||||
label: item.warehouse?.name || '',
|
||||
},
|
||||
qty: item.sub_qty || item.qty || 0,
|
||||
price: item.price,
|
||||
total_price: item.total_price,
|
||||
price: type === 'add'
|
||||
? ('ProductPrice' in item.product ? (item.product.ProductPrice || item.price || '') : item.price)
|
||||
: item.price,
|
||||
total_price: type === 'add'
|
||||
? (('ProductPrice' in item.product ? (item.product.ProductPrice || item.price || 0) : item.price) * (item.sub_qty || item.qty || 0))
|
||||
: item.total_price,
|
||||
}))
|
||||
: [
|
||||
{
|
||||
|
||||
@@ -294,9 +294,9 @@ const PurchaseOrderStaffApprovalForm = ({
|
||||
// ===== FORM CONFIGURATION =====
|
||||
const formikInitialValues = useMemo(() => {
|
||||
return initialValues
|
||||
? PurchaseRequestStaffApprovalFormDefaultValues(initialValues)
|
||||
? PurchaseRequestStaffApprovalFormDefaultValues(initialValues, type)
|
||||
: PurchaseRequestStaffApprovalFormInitialValues;
|
||||
}, [initialValues]);
|
||||
}, [initialValues, type]);
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues: formikInitialValues,
|
||||
@@ -485,9 +485,18 @@ const PurchaseOrderStaffApprovalForm = ({
|
||||
},
|
||||
warehouse_id: purchaseItem.warehouse_id || 0,
|
||||
qty: originalItem?.qty || purchaseItem.quantity || 0,
|
||||
price: type === 'edit' && originalItem ? originalItem.price : '',
|
||||
price:
|
||||
type === 'edit' && originalItem
|
||||
? originalItem.price
|
||||
: originalItem?.product && 'ProductPrice' in originalItem.product
|
||||
? originalItem.product.ProductPrice || ''
|
||||
: '',
|
||||
total_price:
|
||||
type === 'edit' && originalItem ? originalItem.total_price : '',
|
||||
type === 'edit' && originalItem
|
||||
? originalItem.total_price
|
||||
: (originalItem?.product && 'ProductPrice' in originalItem.product
|
||||
? originalItem.product.ProductPrice || 0
|
||||
: 0) * (originalItem?.qty || purchaseItem.quantity || 0),
|
||||
};
|
||||
return itemData;
|
||||
});
|
||||
@@ -1140,6 +1149,7 @@ const PurchaseOrderStaffApprovalForm = ({
|
||||
color='warning'
|
||||
className='px-4'
|
||||
onClick={() => {
|
||||
formik.setValues(formikInitialValues);
|
||||
formik.resetForm();
|
||||
setPurchaseOrderFormErrorMessage('');
|
||||
onCancel?.();
|
||||
|
||||
Reference in New Issue
Block a user