1
- import { type TypeOf , boolean , coerce , object , string } from "zod" ;
1
+ import { type TypeOf , z } from "zod" ;
2
2
import { t } from "../util/i18n" ;
3
3
4
4
import type { APPLICATION_STATUS , USER_TYPES } from "../constants" ;
5
5
import { isDateAfterCurrentDate } from "../util" ;
6
6
import { emailSchema } from "./auth" ;
7
7
8
- export const introSchema = object ( {
9
- accept_terms_and_conditions : boolean ( ) . refine ( ( value ) => value === true , {
8
+ export const introSchema = z . object ( {
9
+ accept_terms_and_conditions : z . boolean ( ) . refine ( ( value ) => value === true , {
10
10
message : t ( "You need to check this option to Access the Scheme" ) ,
11
11
} ) ,
12
12
} ) ;
13
13
14
14
export type IntroInput = TypeOf < typeof introSchema > ;
15
15
16
- export const submitSchema = object ( {
17
- agree_topass_info_to_banking_partner : boolean ( ) . refine ( ( value ) => value === true , {
16
+ export const submitSchema = z . object ( {
17
+ agree_topass_info_to_banking_partner : z . boolean ( ) . refine ( ( value ) => value === true , {
18
18
message : t ( "You need to check this option to submit the application" ) ,
19
19
} ) ,
20
20
} ) ;
21
21
22
22
export type SubmitInput = TypeOf < typeof submitSchema > ;
23
23
24
- const UUIDType = string ( ) . optional ( ) ;
24
+ const UUIDType = z . string ( ) . optional ( ) ;
25
25
26
- export const applicationBaseSchema = object ( {
26
+ export const applicationBaseSchema = z . object ( {
27
27
uuid : UUIDType ,
28
28
} ) ;
29
29
30
30
export type ApplicationBaseInput = TypeOf < typeof applicationBaseSchema > ;
31
31
32
- export const declineApplicationSchema = object ( {
33
- decline_this : boolean ( ) ,
34
- decline_all : boolean ( ) ,
32
+ export const declineApplicationSchema = z . object ( {
33
+ decline_this : z . boolean ( ) ,
34
+ decline_all : z . boolean ( ) ,
35
35
uuid : UUIDType ,
36
36
} ) . refine ( ( data ) => data . decline_this || data . decline_all , {
37
37
path : [ "decline_all" ] ,
@@ -60,40 +60,40 @@ export const DECLINE_FEEDBACK_NAMES: { [key: string]: string } = {
60
60
[ DECLINE_FEEDBACK . other ] : t ( "Other" ) ,
61
61
} ;
62
62
63
- export const declineFeedbackSchema = object ( {
64
- [ DECLINE_FEEDBACK . dont_need_access_credit ] : boolean ( ) ,
65
- [ DECLINE_FEEDBACK . already_have_acredit ] : boolean ( ) ,
66
- [ DECLINE_FEEDBACK . preffer_to_go_to_bank ] : boolean ( ) ,
67
- [ DECLINE_FEEDBACK . dont_want_access_credit ] : boolean ( ) ,
68
- [ DECLINE_FEEDBACK . suspicious_email ] : boolean ( ) ,
69
- [ DECLINE_FEEDBACK . other ] : boolean ( ) ,
70
- other_comments : string ( ) . optional ( ) ,
63
+ export const declineFeedbackSchema = z . object ( {
64
+ [ DECLINE_FEEDBACK . dont_need_access_credit ] : z . boolean ( ) ,
65
+ [ DECLINE_FEEDBACK . already_have_acredit ] : z . boolean ( ) ,
66
+ [ DECLINE_FEEDBACK . preffer_to_go_to_bank ] : z . boolean ( ) ,
67
+ [ DECLINE_FEEDBACK . dont_want_access_credit ] : z . boolean ( ) ,
68
+ [ DECLINE_FEEDBACK . suspicious_email ] : z . boolean ( ) ,
69
+ [ DECLINE_FEEDBACK . other ] : z . boolean ( ) ,
70
+ other_comments : z . string ( ) . optional ( ) ,
71
71
uuid : UUIDType ,
72
72
} ) ;
73
73
74
74
export type DeclineFeedbackInput = TypeOf < typeof declineFeedbackSchema > ;
75
75
76
- export const creditOptionsSchema = object ( {
77
- borrower_size : string ( ) . min ( 1 , t ( "Borrower size is required" ) ) ,
78
- sector : string ( ) . min ( 1 , t ( "Sector is required" ) ) ,
79
- annual_revenue : coerce . number ( ) . optional ( ) . nullable ( ) ,
80
- amount_requested : coerce . number ( ) . min ( 1 , t ( "Amount requested must be greater than 0" ) ) ,
76
+ export const creditOptionsSchema = z . object ( {
77
+ borrower_size : z . string ( ) . min ( 1 , t ( "Borrower size is required" ) ) ,
78
+ sector : z . string ( ) . min ( 1 , t ( "Sector is required" ) ) ,
79
+ annual_revenue : z . coerce . number ( ) . optional ( ) . nullable ( ) ,
80
+ amount_requested : z . coerce . number ( ) . min ( 1 , t ( "Amount requested must be greater than 0" ) ) ,
81
81
uuid : UUIDType ,
82
82
} ) ;
83
83
84
84
export type CreditOptionsInput = TypeOf < typeof creditOptionsSchema > ;
85
85
86
86
export type GetCreditProductsOptionsInput = Omit < CreditOptionsInput , "sector" | "annual_revenue" > ;
87
87
88
- export const repaymentTermsSchema = object ( {
89
- repayment_years : coerce
88
+ export const repaymentTermsSchema = z . object ( {
89
+ repayment_years : z . coerce
90
90
. number ( {
91
91
required_error : t ( "Years is required" ) ,
92
92
invalid_type_error : t ( "Years must be a number" ) ,
93
93
} )
94
94
. gte ( 0 , t ( "Years must be greater or equal than " ) ) ,
95
- repayment_months : coerce . number ( ) . min ( 1 , t ( "Months must be greater or equal than 1" ) ) ,
96
- payment_start_date : string ( )
95
+ repayment_months : z . coerce . number ( ) . min ( 1 , t ( "Months must be greater or equal than 1" ) ) ,
96
+ payment_start_date : z . string ( )
97
97
. min ( 1 , t ( "Payment start date is required" ) )
98
98
. refine ( ( value ) => isDateAfterCurrentDate ( value ) , {
99
99
message : t ( "Payment start date must be after current date" ) ,
@@ -335,18 +335,18 @@ export interface ILenderListResponse {
335
335
page_size : number ;
336
336
}
337
337
338
- export const formEmailSchema = object ( {
339
- message : string ( ) . min ( 1 , t ( "A message is required" ) ) ,
338
+ export const formEmailSchema = z . object ( {
339
+ message : z . string ( ) . min ( 1 , t ( "A message is required" ) ) ,
340
340
} ) ;
341
341
342
342
export type FormEmailInput = TypeOf < typeof formEmailSchema > ;
343
343
344
344
export type EmailToSMEInput = FormEmailInput & PrivateApplicationInput ;
345
345
346
- export const approveSchema = object ( {
347
- compliant_checks_completed : boolean ( ) ,
348
- compliant_checks_passed : boolean ( ) ,
349
- disbursed_final_amount : coerce
346
+ export const approveSchema = z . object ( {
347
+ compliant_checks_completed : z . boolean ( ) ,
348
+ compliant_checks_passed : z . boolean ( ) ,
349
+ disbursed_final_amount : z . coerce
350
350
. number ( {
351
351
required_error : t ( "Disbursed final amount is required" ) ,
352
352
invalid_type_error : t ( "Disbursed final amount must be a number" ) ,
@@ -358,19 +358,19 @@ export type FormApprovedInput = TypeOf<typeof approveSchema>;
358
358
359
359
export type ApproveApplicationInput = FormApprovedInput & PrivateApplicationInput ;
360
360
361
- export const rejectSchema = object ( {
362
- compliance_checks_failed : boolean ( ) ,
363
- poor_credit_history : boolean ( ) ,
364
- risk_of_fraud : boolean ( ) ,
365
- other : boolean ( ) ,
366
- other_reason : string ( ) ,
361
+ export const rejectSchema = z . object ( {
362
+ compliance_checks_failed : z . boolean ( ) ,
363
+ poor_credit_history : z . boolean ( ) ,
364
+ risk_of_fraud : z . boolean ( ) ,
365
+ other : z . boolean ( ) ,
366
+ other_reason : z . string ( ) ,
367
367
} ) ;
368
368
369
369
export type FormRejectInput = TypeOf < typeof rejectSchema > ;
370
370
371
371
export type RejectApplicationInput = FormRejectInput & PrivateApplicationInput ;
372
372
373
- export const changeEmailSchema = object ( {
373
+ export const changeEmailSchema = z . object ( {
374
374
new_email : emailSchema ,
375
375
} ) ;
376
376
0 commit comments