@@ -8,50 +8,51 @@ const minGradYear = 2025;
8
8
const maxGradYear = 2030 ;
9
9
10
10
export const applicationSchema = object ( {
11
- name : string ( ) ,
11
+ name : string ( ) . required ( "Name is required" ) ,
12
12
email : string ( )
13
13
. email ( "Invalid email format" )
14
- //Matches any .edu email
15
14
. matches ( / ^ [ a - z A - Z 0 - 9 . _ % + - ] + @ ( [ a - z A - Z 0 - 9 - ] + \. ) + ( e d u ) $ / , {
16
15
message : "Must be a .edu email" ,
17
16
excludeEmptyString : true
18
17
} )
19
- . required ( ) ,
18
+ . required ( "Email is required" ) ,
20
19
preferredEmail : string ( ) . email ( "Invalid email format" ) ,
21
20
phone : string ( ) . matches (
22
21
/ ^ \D ? ( \d { 3 } ) \D ? \D ? ( \d { 3 } ) \D ? ( \d { 4 } ) $ / ,
23
22
"Invalid phone number format"
24
23
) ,
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" ) ,
27
30
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" ) ,
40
48
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 ;
47
51
} )
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 ;
54
54
} )
55
+ . required ( "Response is required" )
55
56
} ) . required ( ) ;
56
57
57
58
export type Application = InferType < typeof applicationSchema > ;
0 commit comments