refactor(FE-114): improve product filtering logic for location and flag validation

This commit is contained in:
rstubryan
2025-10-20 10:38:10 +07:00
parent eb02a8b6f7
commit 895b7afa25
@@ -205,11 +205,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
return pakanProducts.data.filter((product) => { return pakanProducts.data.filter((product) => {
const warehouse = product.warehouse; const warehouse = product.warehouse;
if ('location' in warehouse && warehouse.location) { const hasLocationMatch =
return warehouse.location.id === formik.values.location_id; 'location' in warehouse && warehouse.location
} ? warehouse.location.id === formik.values.location_id
: false;
return false; const hasPakanFlag = product.product.flags?.includes('PAKAN');
return hasLocationMatch && hasPakanFlag;
}); });
}, [pakanProducts, formik.values.location_id]); }, [pakanProducts, formik.values.location_id]);
@@ -237,11 +240,16 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
return ovkProducts.data.filter((product) => { return ovkProducts.data.filter((product) => {
const warehouse = product.warehouse; const warehouse = product.warehouse;
if ('location' in warehouse && warehouse.location) { // Validate location match
return warehouse.location.id === formik.values.location_id; const hasLocationMatch =
} 'location' in warehouse && warehouse.location
? warehouse.location.id === formik.values.location_id
: false;
return false; // Validate product has OVK flag
const hasOvkFlag = product.product.flags?.includes('OVK');
return hasLocationMatch && hasOvkFlag;
}); });
}, [ovkProducts, formik.values.location_id]); }, [ovkProducts, formik.values.location_id]);