mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +00:00
refactor(FE-114,136): improve location and coop field handling in RecordingForm
This commit is contained in:
@@ -150,21 +150,42 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
|
||||
// Handlers
|
||||
const locationChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||
formik.setFieldTouched('location', true);
|
||||
const locationValue = (val as OptionType)?.value;
|
||||
|
||||
formik.setFieldValue('location', val);
|
||||
formik.setFieldTouched('location_id', true);
|
||||
formik.setFieldValue('location_id', (val as OptionType)?.value);
|
||||
// Reset coop selection when location changes
|
||||
formik.setFieldValue('location_id', locationValue || 0);
|
||||
|
||||
// Only set touched if there's a value
|
||||
if (locationValue) {
|
||||
formik.setFieldTouched('location', true);
|
||||
formik.setFieldTouched('location_id', true);
|
||||
} else {
|
||||
formik.setFieldTouched('location', false);
|
||||
formik.setFieldTouched('location_id', false);
|
||||
}
|
||||
|
||||
// Reset coop selection when location changes or is cleared
|
||||
formik.setFieldValue('coop', null);
|
||||
formik.setFieldValue('coop_id', 0);
|
||||
formik.setFieldTouched('coop', false);
|
||||
formik.setFieldTouched('coop_id', false);
|
||||
setCoopSelectInputValue('');
|
||||
};
|
||||
|
||||
const coopChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||
formik.setFieldTouched('coop', true);
|
||||
const coopValue = (val as OptionType)?.value;
|
||||
|
||||
formik.setFieldValue('coop', val);
|
||||
formik.setFieldTouched('coop_id', true);
|
||||
formik.setFieldValue('coop_id', (val as OptionType)?.value);
|
||||
formik.setFieldValue('coop_id', coopValue || 0);
|
||||
|
||||
// Only set touched if there's a value
|
||||
if (coopValue) {
|
||||
formik.setFieldTouched('coop', true);
|
||||
formik.setFieldTouched('coop_id', true);
|
||||
} else {
|
||||
formik.setFieldTouched('coop', false);
|
||||
formik.setFieldTouched('coop_id', false);
|
||||
}
|
||||
};
|
||||
|
||||
const isRepeaterInputError = <T extends keyof CreateRecordingPayload>(
|
||||
@@ -423,6 +444,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
/>
|
||||
|
||||
<SelectInput
|
||||
key={`coop-select-${formik.values.location_id || 'no-location'}`}
|
||||
required
|
||||
label='Kandang'
|
||||
value={formik.values.coop ?? undefined}
|
||||
|
||||
Reference in New Issue
Block a user