mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
refactor(FE): Add conditional validation for sub_flags in
ProductForm.schema
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
|
import { PRODUCT_FLAG_MAPPING } from '@/config/constant';
|
||||||
|
|
||||||
type ProductFormSchemaType = {
|
type ProductFormSchemaType = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -100,7 +101,21 @@ export const ProductFormSchema: Yup.ObjectSchema<ProductFormSchemaType> =
|
|||||||
.required('Flag wajib diisi!')
|
.required('Flag wajib diisi!')
|
||||||
.typeError('Flag wajib diisi!'),
|
.typeError('Flag wajib diisi!'),
|
||||||
|
|
||||||
sub_flags: Yup.array().of(Yup.string().required()),
|
sub_flags: Yup.array()
|
||||||
|
.of(Yup.string().required())
|
||||||
|
.when('flag', {
|
||||||
|
is: (flag: string) => {
|
||||||
|
const mapping = PRODUCT_FLAG_MAPPING.options.find(
|
||||||
|
(opt) => opt.flag.value === flag
|
||||||
|
);
|
||||||
|
return mapping?.allow_without_sub_flag === false;
|
||||||
|
},
|
||||||
|
then: (schema) =>
|
||||||
|
schema
|
||||||
|
.required('Sub flag wajib diisi!')
|
||||||
|
.min(1, 'Sub flag wajib diisi!'),
|
||||||
|
otherwise: (schema) => schema,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const UpdateProductFormSchema = ProductFormSchema;
|
export const UpdateProductFormSchema = ProductFormSchema;
|
||||||
|
|||||||
Reference in New Issue
Block a user