@@ -11,6 +11,19 @@ const processSalaryValue = (val: unknown) => {
1111 return val ;
1212} ;
1313
14+ const capitalize = ( s : string ) => {
15+ if ( s == null || typeof s !== 'string' ) {
16+ return s ;
17+ }
18+
19+ return s . trim ( ) . length === 0
20+ ? ''
21+ : s
22+ . trim ( )
23+ . toLowerCase ( )
24+ . replace ( / \b \w / g, ( c ) => c . toUpperCase ( ) ) ;
25+ } ;
26+
1427export const opportunityEditInfoSchema = z . object ( {
1528 title : z . string ( ) . nonempty ( labels . form . required ) . max ( 240 ) ,
1629 tldr : z . string ( ) . nonempty ( labels . form . required ) . max ( 480 ) ,
@@ -23,16 +36,37 @@ export const opportunityEditInfoSchema = z.object({
2336 . min ( 1 , labels . form . required )
2437 . max ( 100 ) ,
2538 location : z . array (
26- z . object ( {
27- country : z . string ( ) . nonempty ( labels . form . required ) . max ( 240 ) ,
28- city : z . string ( ) . nonempty ( labels . form . required ) . max ( 240 ) . optional ( ) ,
29- subdivision : z
30- . string ( )
31- . nonempty ( labels . form . required )
32- . max ( 240 )
33- . optional ( ) ,
34- type : z . coerce . number ( labels . form . required ) . min ( 1 ) ,
35- } ) ,
39+ z
40+ . object ( {
41+ country : z . string ( ) . max ( 240 ) ,
42+ city : z . string ( ) . max ( 240 ) . optional ( ) ,
43+ subdivision : z . string ( ) . max ( 240 ) . optional ( ) ,
44+ continent : z
45+ . preprocess (
46+ capitalize ,
47+ z . union ( [ z . literal ( 'Europe' ) , z . literal ( '' ) , z . undefined ( ) ] ) ,
48+ )
49+ . optional ( ) ,
50+ type : z . coerce . number ( ) . min ( 1 ) ,
51+ } )
52+ . superRefine ( ( val , ctx ) => {
53+ const present = [
54+ val . country && val . country . trim ( ) !== '' ,
55+ val . city && val . city . trim ( ) !== '' ,
56+ val . subdivision && val . subdivision . trim ( ) !== '' ,
57+ // continent counts only if it is "Europe" (empty string should not count)
58+ val . continent === 'Europe' ,
59+ ] . some ( Boolean ) ;
60+
61+ if ( ! present ) {
62+ ctx . addIssue ( {
63+ code : 'custom' ,
64+ message :
65+ 'At least one of country, city, subdivision, or continent must be provided.' ,
66+ path : [ '' ] , // form-level error
67+ } ) ;
68+ }
69+ } ) ,
3670 ) ,
3771 meta : z . object ( {
3872 employmentType : z . coerce . number ( ) . min ( 1 , {
0 commit comments