From b7c244f489b9de0864f030458c2318f305167e44 Mon Sep 17 00:00:00 2001 From: Drish-xD Date: Mon, 26 Aug 2024 23:45:14 +0530 Subject: [PATCH] chore: handle platform= null --- src/app/session/[type]/Steps/helper.ts | 2 +- src/components/ui/select.tsx | 5 +++-- src/types/api.types.ts | 4 ++-- src/types/form.types.ts | 29 +++++++++++++++++++------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/app/session/[type]/Steps/helper.ts b/src/app/session/[type]/Steps/helper.ts index 8dc05d9..0c9e6ac 100644 --- a/src/app/session/[type]/Steps/helper.ts +++ b/src/app/session/[type]/Steps/helper.ts @@ -276,7 +276,7 @@ export const handleBatchFields = ( apiOptions: ApiFormOptions, fieldsSchema: FieldSchema ) => { - if (value !== Platform.Quiz) { + if (value !== Platform.Quiz || !value) { fieldsSchema.parentBatch.hide = true; form.setValue('parentBatch', ''); } else { diff --git a/src/components/ui/select.tsx b/src/components/ui/select.tsx index bf7231d..4984158 100644 --- a/src/components/ui/select.tsx +++ b/src/components/ui/select.tsx @@ -153,7 +153,7 @@ const ControlledSelectField = React.forwardRef< const { label, disabled, options = [], onValueChange, helperText, ...restSchemaProps } = schema; React.useEffect(() => { - if (value && onValueChange) { + if (onValueChange) { const value = form.watch(field.name); form.setValue(field.name, value, { shouldDirty: true }); onValueChange(value, form); @@ -224,5 +224,6 @@ export { SelectScrollUpButton, SelectSeparator, SelectTrigger, - SelectValue, + SelectValue }; + diff --git a/src/types/api.types.ts b/src/types/api.types.ts index 6cc589f..f485375 100644 --- a/src/types/api.types.ts +++ b/src/types/api.types.ts @@ -39,7 +39,7 @@ const repeatScheduleSchema = z.object({ }); export const sessionSchema = z.object({ - auth_type: z.string(), + auth_type: z.string().nullable(), created_by_id: z.string().datetime(), end_time: z.string().datetime(), id: z.number().int(), @@ -48,7 +48,7 @@ export const sessionSchema = z.object({ meta_data: metaDataSchema, name: z.string(), owner_id: z.string(), - platform: z.string(), + platform: z.string().nullable(), platform_id: z.string(), platform_link: z.string().url(), popup_form: z.boolean(), diff --git a/src/types/form.types.ts b/src/types/form.types.ts index 8eb9336..b954673 100644 --- a/src/types/form.types.ts +++ b/src/types/form.types.ts @@ -6,7 +6,6 @@ import { SessionTypeOptions, StreamOptions, TestFormatOptions, - TestPlatformOptions, TestPurposeOptions, TestTypeOptions, } from '@/Constants'; @@ -35,7 +34,7 @@ export const basicSchema = z (value) => SessionTypeOptions.some((option) => option.value === value), 'Invalid option selected' ), - authType: z.string({ required_error: 'This field is required' }), + authType: z.string({ required_error: 'This field is required' }).optional().nullable(), activateSignUp: z.coerce.boolean(), isPopupForm: z.coerce.boolean(), noOfFieldsInPopup: z.coerce @@ -50,12 +49,7 @@ export const basicSchema = z isIdGeneration: z.coerce.boolean(), signupFormId: z.coerce.number().optional().nullable(), popupFormId: z.coerce.number().optional().nullable(), - platform: z - .string({ required_error: 'This field is required' }) - .refine( - (value) => TestPlatformOptions.some((option) => option.value === value), - 'Invalid option selected' - ), + platform: z.string({ required_error: 'This field is required' }).optional().nullable(), name: z.string({ required_error: 'This field is required' }).min(1, 'This field is required'), }) .superRefine((data, context) => { @@ -86,6 +80,25 @@ export const basicSchema = z } } + // Validation for sessions with Redirection = true + if (data.isRedirection) { + if (!data.platform) { + context.addIssue({ + code: z.ZodIssueCode.custom, + message: 'This field is required', + path: ['platform'], + }); + } + + if (!data.authType) { + context.addIssue({ + code: z.ZodIssueCode.custom, + message: 'This field is required', + path: ['authType'], + }); + } + } + if (data.platform === Platform.Quiz) { // Quiz platform validation if (!data.parentBatch) {