Skip to content

Commit

Permalink
Modified mentee registration validations (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Disura-Randunu authored Oct 5, 2024
1 parent e56a4e1 commit b89ea32
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ export const MenteeApplicationSchema = z.object({
firstName: z.string().min(1, { message: 'First name cannot be empty' }),
lastName: z.string().min(1, { message: 'Last name cannot be empty' }),
email: z.string().email({ message: 'Invalid email address' }),
contactNo: z.string().min(1, { message: 'Contact number cannot be empty' }),
contactNo: z
.string()
.min(1, { message: 'Contact number cannot be empty' })
.startsWith('+', { message: "Must start with '+' for country code" })
.regex(/^\+\d{6,14}$/, { message: 'Invalid contact number' }),
company: z.string().min(1, { message: 'Company cannot be empty' }).optional(),
profilePic: z
.string()
Expand All @@ -13,16 +17,23 @@ export const MenteeApplicationSchema = z.object({
.string()
.min(1, { message: 'Position cannot be empty' })
.optional(),
cv: z.string().min(1, { message: 'CV cannot be empty' }),
cv: z
.string()
.min(1, { message: 'CV cannot be empty' })
.url({ message: 'Please enter a valid link' }),
isUndergrad: z.boolean(),
graduatedYear: z
.number({ invalid_type_error: 'Graduated year is required' })
.int({ message: 'Graduated year must be an integer' })
.refine(
(data) => {
return data === undefined || (!isNaN(data) && data >= 1980);
return (
data === undefined ||
(!isNaN(data) && data >= 1980 && data <= new Date().getFullYear())
);
},
{
message: 'Graduated year must be a year',
message: 'Graduated year must be a valid year',
}
)
.optional(),
Expand All @@ -32,6 +43,7 @@ export const MenteeApplicationSchema = z.object({
.optional(),
yearOfStudy: z
.number({ invalid_type_error: 'Year of study is required' })
.int({ message: 'Year of study must be an integer' })
.gte(1, { message: 'Year must be greater than 0' })
.lte(4, { message: 'Year must be less than or equal 4' })
.optional(),
Expand Down

0 comments on commit b89ea32

Please sign in to comment.