Skip to content

Commit

Permalink
chore: handle platform= null
Browse files Browse the repository at this point in the history
  • Loading branch information
Drish-xD committed Aug 26, 2024
1 parent a0eee22 commit b7c244f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/app/session/[type]/Steps/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export const handleBatchFields = (
apiOptions: ApiFormOptions,
fieldsSchema: FieldSchema<basicFields>
) => {
if (value !== Platform.Quiz) {
if (value !== Platform.Quiz || !value) {
fieldsSchema.parentBatch.hide = true;
form.setValue('parentBatch', '');
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/components/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -224,5 +224,6 @@ export {
SelectScrollUpButton,
SelectSeparator,
SelectTrigger,
SelectValue,
SelectValue
};

4 changes: 2 additions & 2 deletions src/types/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
29 changes: 21 additions & 8 deletions src/types/form.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
SessionTypeOptions,
StreamOptions,
TestFormatOptions,
TestPlatformOptions,
TestPurposeOptions,
TestTypeOptions,
} from '@/Constants';
Expand Down Expand Up @@ -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
Expand All @@ -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) => {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b7c244f

Please sign in to comment.