mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
refactor(FE): Refactor flags field to boolean and update form handling
This commit is contained in:
@@ -17,7 +17,7 @@ export const NonstockFormSchema = Yup.object({
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|
||||||
flags: Yup.array().of(Yup.string()).notRequired(),
|
flags: Yup.boolean().default(false),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const UpdateNonstockFormSchema = NonstockFormSchema;
|
export const UpdateNonstockFormSchema = NonstockFormSchema;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import SelectInput, {
|
|||||||
OptionType,
|
OptionType,
|
||||||
useSelect,
|
useSelect,
|
||||||
} from '@/components/input/SelectInput';
|
} from '@/components/input/SelectInput';
|
||||||
|
import { RadioGroup } from '@/components/input/RadioInput';
|
||||||
import { useModal } from '@/components/Modal';
|
import { useModal } from '@/components/Modal';
|
||||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||||
import RequirePermission from '@/components/helper/RequirePermission';
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
@@ -29,8 +30,7 @@ import {
|
|||||||
} from '@/types/api/master-data/nonstock';
|
} from '@/types/api/master-data/nonstock';
|
||||||
import { NonstockApi, SupplierApi, UomApi } from '@/services/api/master-data';
|
import { NonstockApi, SupplierApi, UomApi } from '@/services/api/master-data';
|
||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
import { flags } from '@/types/api/api-general';
|
|
||||||
import { SUPPLIER_FLAG_OPTIONS } from '@/config/constant';
|
|
||||||
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
import AlertErrorList from '@/components/helper/form/FormErrors';
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
import { Supplier } from '@/types/api/master-data/supplier';
|
import { Supplier } from '@/types/api/master-data/supplier';
|
||||||
@@ -97,7 +97,7 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
|
|||||||
label: supplier.name,
|
label: supplier.name,
|
||||||
})) ?? [],
|
})) ?? [],
|
||||||
|
|
||||||
flags: initialValues?.flags ?? [],
|
flags: initialValues?.flags?.includes('EKSPEDISI') ?? false,
|
||||||
};
|
};
|
||||||
}, [initialValues]);
|
}, [initialValues]);
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
|
|||||||
name: values.name,
|
name: values.name,
|
||||||
uom_id: values.uomId,
|
uom_id: values.uomId,
|
||||||
supplier_ids: values.supplierIds as number[],
|
supplier_ids: values.supplierIds as number[],
|
||||||
flags: values.flags as flags[],
|
flags: values.flags ? ['EKSPEDISI'] : [],
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -183,12 +183,8 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
|
|||||||
router.push('/master-data/nonstock');
|
router.push('/master-data/nonstock');
|
||||||
};
|
};
|
||||||
|
|
||||||
const flagsChangeHandler = (val: OptionType | OptionType[] | null) => {
|
const expeditionChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const formattedFlags = (val as OptionType[]).map(
|
formik.setFieldValue('isExpedition', e.target.value === 'true');
|
||||||
(flag) => flag.value as string
|
|
||||||
);
|
|
||||||
|
|
||||||
formik.setFieldValue('flags', formattedFlags);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -268,18 +264,19 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
|
|||||||
isDisabled={type === 'detail'}
|
isDisabled={type === 'detail'}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SelectInput
|
<RadioGroup
|
||||||
label='Flags'
|
label='Ekspedisi?'
|
||||||
isMulti
|
name='flags'
|
||||||
value={SUPPLIER_FLAG_OPTIONS.filter((opt) =>
|
value={String(formik.values.flags)}
|
||||||
formik.values.flags?.includes(opt.value)
|
onChange={expeditionChangeHandler}
|
||||||
)}
|
onBlur={formik.handleBlur}
|
||||||
onChange={flagsChangeHandler}
|
options={[
|
||||||
options={SUPPLIER_FLAG_OPTIONS}
|
{ label: 'Ya', value: 'true' },
|
||||||
|
{ label: 'Tidak', value: 'false' },
|
||||||
|
]}
|
||||||
isError={formik.touched.flags && Boolean(formik.errors.flags)}
|
isError={formik.touched.flags && Boolean(formik.errors.flags)}
|
||||||
errorMessage={formik.errors.flags as string}
|
errorMessage={formik.errors.flags as string}
|
||||||
isDisabled={type === 'detail'}
|
disabled={type === 'detail'}
|
||||||
isClearable
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user