refactor(FE-208,212): update PurchaseRequestForm to reset location fields on area change, improve handling of location value and dependencies

This commit is contained in:
rstubryan
2025-11-03 15:45:42 +07:00
parent ecdd8ae49c
commit ee24ceaff1
@@ -391,7 +391,9 @@ const PurchaseRequestForm = ({
formik.setFieldValue('area_id', (area as OptionType)?.value || 0);
// Reset area dependent fields
formik.setFieldValue('location', null);
formik.setFieldTouched('location', false);
formik.setFieldValue('location', undefined);
formik.setFieldTouched('location_id', false);
formik.setFieldValue('location_id', 0);
setLocationSelectInputValue('');
@@ -590,7 +592,7 @@ const PurchaseRequestForm = ({
? 'Pilih Area terlebih dahulu'
: 'Pilih Lokasi...'
}
value={formik.values.location}
value={formik.values.area_id ? formik.values.location : null}
onChange={locationChangeHandler}
options={locationOptions}
onInputChange={setLocationSelectInputValue}
@@ -601,6 +603,7 @@ const PurchaseRequestForm = ({
errorMessage={formik.errors.location_id as string}
isDisabled={type === 'detail' || !formik.values.area_id}
isClearable={type !== 'detail' && !!formik.values.area_id}
key={`location-${formik.values.area_id}`}
/>
<div className={type === 'detail' ? 'col-span-1' : 'col-span-2'}>