mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +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;
|
||||
|
||||
@@ -12,6 +12,7 @@ import SelectInput, {
|
||||
OptionType,
|
||||
useSelect,
|
||||
} from '@/components/input/SelectInput';
|
||||
import { RadioGroup } from '@/components/input/RadioInput';
|
||||
import { useModal } from '@/components/Modal';
|
||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
||||
import RequirePermission from '@/components/helper/RequirePermission';
|
||||
@@ -29,8 +30,7 @@ import {
|
||||
} from '@/types/api/master-data/nonstock';
|
||||
import { NonstockApi, SupplierApi, UomApi } from '@/services/api/master-data';
|
||||
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 AlertErrorList from '@/components/helper/form/FormErrors';
|
||||
import { Supplier } from '@/types/api/master-data/supplier';
|
||||
@@ -97,7 +97,7 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
|
||||
label: supplier.name,
|
||||
})) ?? [],
|
||||
|
||||
flags: initialValues?.flags ?? [],
|
||||
flags: initialValues?.flags?.includes('EKSPEDISI') ?? false,
|
||||
};
|
||||
}, [initialValues]);
|
||||
|
||||
@@ -112,7 +112,7 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
|
||||
name: values.name,
|
||||
uom_id: values.uomId,
|
||||
supplier_ids: values.supplierIds as number[],
|
||||
flags: values.flags as flags[],
|
||||
flags: values.flags ? ['EKSPEDISI'] : [],
|
||||
};
|
||||
|
||||
switch (type) {
|
||||
@@ -183,12 +183,8 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
|
||||
router.push('/master-data/nonstock');
|
||||
};
|
||||
|
||||
const flagsChangeHandler = (val: OptionType | OptionType[] | null) => {
|
||||
const formattedFlags = (val as OptionType[]).map(
|
||||
(flag) => flag.value as string
|
||||
);
|
||||
|
||||
formik.setFieldValue('flags', formattedFlags);
|
||||
const expeditionChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
formik.setFieldValue('isExpedition', e.target.value === 'true');
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -268,18 +264,19 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
|
||||
isDisabled={type === 'detail'}
|
||||
/>
|
||||
|
||||
<SelectInput
|
||||
label='Flags'
|
||||
isMulti
|
||||
value={SUPPLIER_FLAG_OPTIONS.filter((opt) =>
|
||||
formik.values.flags?.includes(opt.value)
|
||||
)}
|
||||
onChange={flagsChangeHandler}
|
||||
options={SUPPLIER_FLAG_OPTIONS}
|
||||
<RadioGroup
|
||||
label='Ekspedisi?'
|
||||
name='flags'
|
||||
value={String(formik.values.flags)}
|
||||
onChange={expeditionChangeHandler}
|
||||
onBlur={formik.handleBlur}
|
||||
options={[
|
||||
{ label: 'Ya', value: 'true' },
|
||||
{ label: 'Tidak', value: 'false' },
|
||||
]}
|
||||
isError={formik.touched.flags && Boolean(formik.errors.flags)}
|
||||
errorMessage={formik.errors.flags as string}
|
||||
isDisabled={type === 'detail'}
|
||||
isClearable
|
||||
disabled={type === 'detail'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user