From a1ec3650ddc42806e021d9074ecf1dab766b3f63 Mon Sep 17 00:00:00 2001 From: Drish-xD Date: Mon, 26 Aug 2024 23:45:14 +0530 Subject: [PATCH 1/6] chore: handle platform= null --- src/types/api.types.ts | 4 ++-- src/types/form.types.ts | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) 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) { From 821aebef9bdf2fbd92b25eeed8e56baec856d140 Mon Sep 17 00:00:00 2001 From: Drish-xD Date: Mon, 26 Aug 2024 23:59:56 +0530 Subject: [PATCH 2/6] fix: types error --- src/types/form.types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/form.types.ts b/src/types/form.types.ts index b954673..e77d787 100644 --- a/src/types/form.types.ts +++ b/src/types/form.types.ts @@ -227,7 +227,7 @@ export const liveSchema = z .pipe(z.string().url('This is not a valid url')), platformId: z.string({ required_error: 'This field is required' }), subject: z.array(z.string()).min(1, 'This field is required'), - platform: z.string().optional(), + platform: z.string().optional().nullable(), }) .refine( (data) => { From 1c78b498cef8b38c8107b7a05a2019eac921688f Mon Sep 17 00:00:00 2001 From: Drish-xD Date: Wed, 28 Aug 2024 01:25:59 +0530 Subject: [PATCH 3/6] fix: enable disable session --- src/app/(home)/Table/Actions.tsx | 1 + src/lib/time-picker-utils.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/app/(home)/Table/Actions.tsx b/src/app/(home)/Table/Actions.tsx index 5298a35..1517473 100644 --- a/src/app/(home)/Table/Actions.tsx +++ b/src/app/(home)/Table/Actions.tsx @@ -49,6 +49,7 @@ const TableActions = ({ session }: { session: Session }) => { await patchSession( { is_active: !session.is_active, + meta_data: session.meta_data, }, session.id ?? 0, session diff --git a/src/lib/time-picker-utils.ts b/src/lib/time-picker-utils.ts index c89028f..d7f1d6e 100644 --- a/src/lib/time-picker-utils.ts +++ b/src/lib/time-picker-utils.ts @@ -171,12 +171,14 @@ export function display12HourValue(hours: number) { } export function utcToISTDate(utcDate: string) { + if (!utcDate) return ''; const parsedDate = new Date(utcDate); const istDate = addMinutes(parsedDate, UTC_IST_OFFSET).toISOString(); return istDate; } export function istToUTCDate(istDate: string) { + if (!istDate) return ''; const parsedDate = new Date(istDate); const utcDate = subMinutes(parsedDate, UTC_IST_OFFSET).toISOString(); return utcDate; From d321a3c29b766e0eb3ab05ee52690764d874b931 Mon Sep 17 00:00:00 2001 From: Drish-xD Date: Wed, 28 Aug 2024 21:14:28 +0530 Subject: [PATCH 4/6] chore: add no-platform as option --- src/app/session/[type]/Steps/helper.ts | 8 +++----- src/types/api.types.ts | 2 +- src/types/enums.ts | 1 + src/types/form.types.ts | 16 +++++++--------- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/app/session/[type]/Steps/helper.ts b/src/app/session/[type]/Steps/helper.ts index 8dc05d9..f73348f 100644 --- a/src/app/session/[type]/Steps/helper.ts +++ b/src/app/session/[type]/Steps/helper.ts @@ -25,7 +25,6 @@ export const setGroupPreset = (value: string, form: UseFormReturn, apiOptions: A isPopupForm: false, popupFormId: null, noOfFieldsInPopup: '', - isRedirection: true, isIdGeneration: false, parentBatch: '', subBatch: [], @@ -43,7 +42,6 @@ export const setGroupPreset = (value: string, form: UseFormReturn, apiOptions: A isPopupForm: false, popupFormId: null, noOfFieldsInPopup: '', - isRedirection: true, isIdGeneration: true, parentBatch: '', subBatch: [], @@ -62,7 +60,6 @@ export const setGroupPreset = (value: string, form: UseFormReturn, apiOptions: A isPopupForm: false, popupFormId: null, noOfFieldsInPopup: '', - isRedirection: true, isIdGeneration: false, parentBatch: '', subBatch: [], @@ -78,7 +75,6 @@ export const setGroupPreset = (value: string, form: UseFormReturn, apiOptions: A isPopupForm: false, popupFormId: null, noOfFieldsInPopup: '', - isRedirection: true, isIdGeneration: false, parentBatch: '', subBatch: [], @@ -92,7 +88,6 @@ export const setGroupPreset = (value: string, form: UseFormReturn, apiOptions: A isPopupForm: false, popupFormId: null, noOfFieldsInPopup: '', - isRedirection: true, isIdGeneration: false, parentBatch: '', subBatch: [], @@ -283,6 +278,9 @@ export const handleBatchFields = ( fieldsSchema.parentBatch.hide = false; } + if (value === Platform.NoPlatform) { + form.setValue('isRedirection', false, { shouldDirty: true }); + } const selectedGroup = form.watch('group'); if (selectedGroup) { setParentBatchOptions(selectedGroup, form, apiOptions, fieldsSchema); diff --git a/src/types/api.types.ts b/src/types/api.types.ts index f485375..bb1fa75 100644 --- a/src/types/api.types.ts +++ b/src/types/api.types.ts @@ -48,7 +48,7 @@ export const sessionSchema = z.object({ meta_data: metaDataSchema, name: z.string(), owner_id: z.string(), - platform: z.string().nullable(), + platform: z.string(), platform_id: z.string(), platform_link: z.string().url(), popup_form: z.boolean(), diff --git a/src/types/enums.ts b/src/types/enums.ts index a0d1395..400a155 100644 --- a/src/types/enums.ts +++ b/src/types/enums.ts @@ -24,6 +24,7 @@ export enum Platform { Others = 'others', Plio = 'AF-plio', SPlio = 'SCERT-plio', + NoPlatform = 'no-platform', } export enum Group { diff --git a/src/types/form.types.ts b/src/types/form.types.ts index e77d787..91a4baa 100644 --- a/src/types/form.types.ts +++ b/src/types/form.types.ts @@ -6,6 +6,7 @@ import { SessionTypeOptions, StreamOptions, TestFormatOptions, + TestPlatformOptions, TestPurposeOptions, TestTypeOptions, } from '@/Constants'; @@ -49,7 +50,12 @@ 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' }).optional().nullable(), + platform: z + .string({ required_error: 'This field is required' }) + .refine( + (value) => TestPlatformOptions.some((option) => option.value === value), + 'Invalid option selected' + ), name: z.string({ required_error: 'This field is required' }).min(1, 'This field is required'), }) .superRefine((data, context) => { @@ -82,14 +88,6 @@ 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, From 5a57e0d694dcfe0e126cc0c6686548f9c5ece300 Mon Sep 17 00:00:00 2001 From: Drish-xD Date: Wed, 28 Aug 2024 21:49:16 +0530 Subject: [PATCH 5/6] chore: comment options --- src/Constants/Options.ts | 3 ++- src/types/enums.ts | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Constants/Options.ts b/src/Constants/Options.ts index cf4be2a..2e5e474 100644 --- a/src/Constants/Options.ts +++ b/src/Constants/Options.ts @@ -9,7 +9,8 @@ export const TestTypeOptions: Option[] = [ export const SessionTypeOptions: Option[] = [ { value: 'sign-in', label: 'SignIn' }, { value: 'sign-up', label: 'SignUp' }, - { value: 'sign-in with forgot id', label: 'SignIn with Forgot ID' }, + // Removed as now we are not allowing forgot id + // { value: 'sign-in with forgot id', label: 'SignIn with Forgot ID' }, { value: 'broadcast', label: 'Broadcast' }, ]; diff --git a/src/types/enums.ts b/src/types/enums.ts index 400a155..3e7ffa3 100644 --- a/src/types/enums.ts +++ b/src/types/enums.ts @@ -67,10 +67,11 @@ export const GroupShortName: Record = { export enum AuthType { ID = 'ID', - IDPH = 'ID,PH', IDDOB = 'ID,DOB', - IDPHDOB = 'ID,PH,DOB', CODE = 'CODE', + // Removed as now we are not allowing these. + // IDPH = 'ID,PH', + // IDPHDOB = 'ID,PH,DOB', } export enum Subjects { From d1f6caf1cf9d0b47a9b0e7e6fbd2477dc3f02a1f Mon Sep 17 00:00:00 2001 From: Drish-xD Date: Thu, 29 Aug 2024 21:07:25 +0530 Subject: [PATCH 6/6] chore: handle isRedirection --- src/app/session/[type]/Steps/helper.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/session/[type]/Steps/helper.ts b/src/app/session/[type]/Steps/helper.ts index f73348f..e2aa4db 100644 --- a/src/app/session/[type]/Steps/helper.ts +++ b/src/app/session/[type]/Steps/helper.ts @@ -280,6 +280,8 @@ export const handleBatchFields = ( if (value === Platform.NoPlatform) { form.setValue('isRedirection', false, { shouldDirty: true }); + } else { + form.setValue('isRedirection', true, { shouldDirty: true }); } const selectedGroup = form.watch('group'); if (selectedGroup) {