mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +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 { PRODUCT_FLAG_MAPPING } from '@/config/constant';
|
||||
|
||||
type ProductFormSchemaType = {
|
||||
name: string;
|
||||
@@ -100,7 +101,21 @@ export const ProductFormSchema: Yup.ObjectSchema<ProductFormSchemaType> =
|
||||
.required('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;
|
||||
|
||||
Reference in New Issue
Block a user