mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-62): update errorMessage handling and setFieldTouched for form fields
This commit is contained in:
@@ -218,7 +218,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
) {
|
||||
return {
|
||||
isError: false,
|
||||
errorMessage: undefined,
|
||||
errorMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -230,7 +230,10 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
|
||||
return {
|
||||
isError: touchedField && Boolean(errorField?.[column as string]),
|
||||
errorMessage: touchedField ? errorField?.[column as string] : undefined,
|
||||
errorMessage:
|
||||
touchedField && errorField?.[column as string]
|
||||
? errorField[column as string]
|
||||
: '',
|
||||
};
|
||||
};
|
||||
|
||||
@@ -247,7 +250,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
if (!touchedDelivery?.products || !errorDelivery?.products) {
|
||||
return {
|
||||
isError: false,
|
||||
errorMessage: undefined,
|
||||
errorMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -256,7 +259,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
|
||||
return {
|
||||
isError: Boolean(touchedField && errorField),
|
||||
errorMessage: touchedField ? errorField : undefined,
|
||||
errorMessage: touchedField && errorField ? errorField : '',
|
||||
};
|
||||
};
|
||||
|
||||
@@ -707,7 +710,9 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
label='Gudang'
|
||||
value={formik.values.source_warehouse}
|
||||
onChange={(val) => {
|
||||
formik.setFieldTouched('source_warehouse', true);
|
||||
formik.setFieldValue('source_warehouse', val);
|
||||
formik.setFieldTouched('source_warehouse_id', true);
|
||||
formik.setFieldValue(
|
||||
'source_warehouse_id',
|
||||
(val as WarehouseOptionType)?.value
|
||||
@@ -765,7 +770,9 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
label='Gudang'
|
||||
value={formik.values.destination_warehouse}
|
||||
onChange={(val) => {
|
||||
formik.setFieldTouched('destination_warehouse', true);
|
||||
formik.setFieldValue('destination_warehouse', val);
|
||||
formik.setFieldTouched('destination_warehouse_id', true);
|
||||
formik.setFieldValue(
|
||||
'destination_warehouse_id',
|
||||
(val as WarehouseOptionType)?.value
|
||||
@@ -895,10 +902,18 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
required
|
||||
value={product.product ?? undefined}
|
||||
onChange={(val) => {
|
||||
formik.setFieldTouched(
|
||||
`products.${idx}.product`,
|
||||
true
|
||||
);
|
||||
formik.setFieldValue(
|
||||
`products.${idx}.product`,
|
||||
val
|
||||
);
|
||||
formik.setFieldTouched(
|
||||
`products.${idx}.product_id`,
|
||||
true
|
||||
);
|
||||
formik.setFieldValue(
|
||||
`products.${idx}.product_id`,
|
||||
(val as ProductWarehouseOptionType)?.value
|
||||
@@ -919,7 +934,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
isClearable
|
||||
{...isRepeaterInputError(
|
||||
'products',
|
||||
'product',
|
||||
'product_id',
|
||||
idx
|
||||
)}
|
||||
className={{
|
||||
@@ -1095,10 +1110,18 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
required
|
||||
value={delivery.products[0]?.product ?? undefined}
|
||||
onChange={(val) => {
|
||||
formik.setFieldTouched(
|
||||
`deliveries.${idx}.products.0.product`,
|
||||
true
|
||||
);
|
||||
formik.setFieldValue(
|
||||
`deliveries.${idx}.products.0.product`,
|
||||
val
|
||||
);
|
||||
formik.setFieldTouched(
|
||||
`deliveries.${idx}.products.0.product_id`,
|
||||
true
|
||||
);
|
||||
formik.setFieldValue(
|
||||
`deliveries.${idx}.products.0.product_id`,
|
||||
(val as OptionType)?.value
|
||||
@@ -1107,6 +1130,14 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
options={getFilteredProductWarehouseOptions()}
|
||||
isDisabled={type === 'detail'}
|
||||
isClearable
|
||||
isError={
|
||||
isDeliveryProductInputError(idx, 0, 'product_id')
|
||||
.isError
|
||||
}
|
||||
errorMessage={
|
||||
isDeliveryProductInputError(idx, 0, 'product_id')
|
||||
.errorMessage
|
||||
}
|
||||
className={{
|
||||
wrapper:
|
||||
'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
||||
@@ -1142,10 +1173,18 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
required
|
||||
value={delivery.supplier}
|
||||
onChange={(val) => {
|
||||
formik.setFieldTouched(
|
||||
`deliveries.${idx}.supplier`,
|
||||
true
|
||||
);
|
||||
formik.setFieldValue(
|
||||
`deliveries.${idx}.supplier`,
|
||||
val
|
||||
);
|
||||
formik.setFieldTouched(
|
||||
`deliveries.${idx}.supplier_id`,
|
||||
true
|
||||
);
|
||||
formik.setFieldValue(
|
||||
`deliveries.${idx}.supplier_id`,
|
||||
(val as OptionType)?.value
|
||||
@@ -1156,6 +1195,11 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
isLoading={isLoadingSuppliers}
|
||||
isDisabled={type === 'detail'}
|
||||
isClearable
|
||||
{...isRepeaterInputError(
|
||||
'deliveries',
|
||||
'supplier_id',
|
||||
idx
|
||||
)}
|
||||
className={{
|
||||
wrapper:
|
||||
'w-full min-w-52 md:min-w-72 lg:min-w-80',
|
||||
@@ -1214,6 +1258,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
toast.error(
|
||||
'Ukuran dokumen maksimal 2 MB!'
|
||||
);
|
||||
e.target.value = '';
|
||||
return;
|
||||
}
|
||||
formik.setFieldValue(
|
||||
|
||||
Reference in New Issue
Block a user