Skip to content

Commit 652f4b1

Browse files
committed
chore: update schema for more required fields
1 parent a0bd742 commit 652f4b1

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

src/schemas/application.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,51 @@ const minGradYear = 2025;
88
const maxGradYear = 2030;
99

1010
export const applicationSchema = object({
11-
name: string(),
11+
name: string().required("Name is required"),
1212
email: string()
1313
.email("Invalid email format")
14-
//Matches any .edu email
1514
.matches(/^[a-zA-Z0-9._%+-]+@([a-zA-Z0-9-]+\.)+(edu)$/, {
1615
message: "Must be a .edu email",
1716
excludeEmptyString: true
1817
})
19-
.required(),
18+
.required("Email is required"),
2019
preferredEmail: string().email("Invalid email format"),
2120
phone: string().matches(
2221
/^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/,
2322
"Invalid phone number format"
2423
),
25-
major: string().min(2),
26-
skill: number().min(0).max(4),
24+
major: string()
25+
.min(2, "Major must be at least 2 characters long")
26+
.required("Major is required"),
27+
skill: number()
28+
.min(0, "Skill level must be at least 0")
29+
.max(4, "Skill level must be at most 4"),
2730
gradYear: number()
28-
.typeError("Must be number")
29-
.positive()
30-
.integer()
31-
.min(minGradYear, "Invalid grad year")
32-
.max(maxGradYear),
33-
school: string().test("validSchool", "Invalid school", (value) => {
34-
if (value) {
35-
return usUni.some((uni) => uni.institution === value);
36-
}
37-
return false;
38-
}),
39-
education: string().oneOf(["Bachelor", "Associate", "Master", "Doctoral"]),
31+
.typeError("Graduation year must be a number")
32+
.positive("Graduation year must be positive")
33+
.integer("Graduation year must be an integer")
34+
.min(minGradYear, `Graduation year cannot be before ${minGradYear}`)
35+
.max(maxGradYear, `Graduation year cannot be after ${maxGradYear}`)
36+
.required("Graduation year is required"),
37+
school: string()
38+
.required("School is required")
39+
.test("validSchool", "Invalid school name", (value) => {
40+
return value ? usUni.some((uni) => uni.institution === value) : false;
41+
}),
42+
education: string()
43+
.oneOf(
44+
["Bachelor", "Associate", "Master", "Doctoral"],
45+
"Invalid education level"
46+
)
47+
.required("Education level is required"),
4048
response: string()
41-
.test("wordCount50", "Must be at least 50 words", (value) => {
42-
if (value) {
43-
const wordCount = value.trim().split(/\s+/).length;
44-
return wordCount >= 50;
45-
}
46-
return false;
49+
.test("wordCount50", "Response must be at least 50 words", (value) => {
50+
return value ? value.trim().split(/\s+/).length >= 50 : false;
4751
})
48-
.test("wordCount500", "Must be less than 500 words", (value) => {
49-
if (value) {
50-
const wordCount = value.trim().split(/\s+/).length;
51-
return wordCount <= 500;
52-
}
53-
return false;
52+
.test("wordCount500", "Response must be at most 500 words", (value) => {
53+
return value ? value.trim().split(/\s+/).length <= 500 : true;
5454
})
55+
.required("Response is required")
5556
}).required();
5657

5758
export type Application = InferType<typeof applicationSchema>;

0 commit comments

Comments
 (0)