Skip to content

Commit 1f07b8b

Browse files
committed
chore: Use z instead of individual imports
1 parent 475bfcd commit 1f07b8b

File tree

5 files changed

+81
-81
lines changed

5 files changed

+81
-81
lines changed

src/components/DataAvailabilityForm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Box, Collapse } from "@mui/material";
33
import { useState } from "react";
44
import { FormProvider, type SubmitHandler, useForm } from "react-hook-form";
55
import { useTranslation as useT } from "react-i18next";
6-
import { type TypeOf, object, string } from "zod";
6+
import { type TypeOf, z } from "zod";
77
import { t as tNative } from "../util/i18n";
88

99
import FormInput from "../stories/form-input/FormInput";
@@ -19,8 +19,8 @@ interface DataAvailabilityFormProps {
1919
readonly: boolean;
2020
}
2121

22-
const formCellSchema = object({
23-
value: string().min(1, tNative("This field is required")),
22+
const formCellSchema = z.object({
23+
value: z.string().min(1, tNative("This field is required")),
2424
});
2525

2626
type FormCellInput = TypeOf<typeof formCellSchema>;

src/pages/SelectLanguage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { useSnackbar } from "notistack";
44
import { useEffect, useState } from "react";
55
import { FormProvider, type SubmitHandler, useForm } from "react-hook-form";
66
import { useTranslation as useT } from "react-i18next";
7-
import { type TypeOf, object, string } from "zod";
7+
import { type TypeOf, z } from "zod";
88

99
import { AVAILABLE_LANGUAGES, DISPATCH_ACTIONS } from "../constants";
1010
import useLangContext from "../hooks/useLangContext";
1111
import { Button } from "../stories/button/Button";
1212
import FormSelect, { type FormSelectOption } from "../stories/form-select/FormSelect";
1313
import Title from "../stories/title/Title";
1414

15-
const langSchema = object({
16-
lang: string(),
15+
const langSchema = z.object({
16+
lang: z.string(),
1717
});
1818

1919
type LangInput = TypeOf<typeof langSchema>;

src/schemas/OCPsettings.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import { type TypeOf, boolean, coerce, nativeEnum, object, preprocess, record, string } from "zod";
1+
import { type TypeOf, z } from "zod";
22
import { t } from "../util/i18n";
33

44
import { CREDIT_PRODUCT_TYPE } from "../constants";
55

6-
const creditProviderNameSchema = string().min(1, t("Provider name is required"));
7-
const creditProviderTypeSchema = string().min(1, t("Provider type is required"));
6+
const creditProviderNameSchema = z.string().min(1, t("Provider name is required"));
7+
const creditProviderTypeSchema = z.string().min(1, t("Provider type is required"));
88

9-
export const lenderSchema = object({
9+
export const lenderSchema = z.object({
1010
name: creditProviderNameSchema,
1111
type: creditProviderTypeSchema,
12-
sla_days: coerce
12+
sla_days: z.coerce
1313
.number()
1414
.int()
1515
.positive(t("SLA days must be greater than 0"))
1616
.min(1, t("SLA days must be greater than 0")),
17-
email_group: string().email(t("Email Address is invalid")),
18-
logo_filename: string(),
19-
external_onboarding_url: string().url(t("URL is invalid (Hint: include http:// or https://)")),
17+
email_group: z.string().email(t("Email Address is invalid")),
18+
logo_filename: z.string(),
19+
external_onboarding_url: z.string().url(t("URL is invalid (Hint: include http:// or https://)")),
2020
});
2121

2222
export type ProviderInput = TypeOf<typeof lenderSchema>;
2323

24-
export const creditProductSchema = object({
25-
borrower_size: string().min(1, t("Borrower size is required")),
26-
lower_limit: coerce.number().min(1, t("Lower limit must be greater than 0")),
27-
upper_limit: coerce.number().min(1, t("Upper limit must be greater than 0")),
28-
interest_rate: string().min(1, t("Interest rate description is required")),
29-
type: nativeEnum(CREDIT_PRODUCT_TYPE, {
24+
export const creditProductSchema = z.object({
25+
borrower_size: z.string().min(1, t("Borrower size is required")),
26+
lower_limit: z.coerce.number().min(1, t("Lower limit must be greater than 0")),
27+
upper_limit: z.coerce.number().min(1, t("Upper limit must be greater than 0")),
28+
interest_rate: z.string().min(1, t("Interest rate description is required")),
29+
type: z.nativeEnum(CREDIT_PRODUCT_TYPE, {
3030
errorMap: (issue) => {
3131
switch (issue.code) {
3232
case "invalid_type":
@@ -37,21 +37,21 @@ export const creditProductSchema = object({
3737
}
3838
},
3939
}),
40-
procurement_category_to_exclude: string(),
41-
required_document_types: record(string().min(1), boolean()),
42-
borrower_types: record(string().min(1), boolean()),
43-
other_fees_total_amount: preprocess(
40+
procurement_category_to_exclude: z.string(),
41+
required_document_types: z.record(z.string().min(1), z.boolean()),
42+
borrower_types: z.record(z.string().min(1), z.boolean()),
43+
other_fees_total_amount: z.preprocess(
4444
(args) => (args === "" ? undefined : args),
45-
coerce
45+
z.coerce
4646
.number({
4747
required_error: t("Other fees total amount is required"),
4848
invalid_type_error: t("Other fees total amount must be a number"),
4949
})
5050
.gte(0, t("Other fees total amount must be greater or equal than 0")),
5151
),
52-
other_fees_description: string().min(1, t("Other fees description is required")),
53-
additional_information: string(),
54-
more_info_url: string().url(t("URL is invalid (Hint: include http:// or https://)")),
52+
other_fees_description: z.string().min(1, t("Other fees description is required")),
53+
additional_information: z.string(),
54+
more_info_url: z.string().url(t("URL is invalid (Hint: include http:// or https://)")),
5555
})
5656
.refine((data) => data.lower_limit < data.upper_limit, {
5757
path: ["lower_limit"],

src/schemas/application.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
import { type TypeOf, boolean, coerce, object, string } from "zod";
1+
import { type TypeOf, z } from "zod";
22
import { t } from "../util/i18n";
33

44
import type { APPLICATION_STATUS, USER_TYPES } from "../constants";
55
import { isDateAfterCurrentDate } from "../util";
66
import { emailSchema } from "./auth";
77

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, {
1010
message: t("You need to check this option to Access the Scheme"),
1111
}),
1212
});
1313

1414
export type IntroInput = TypeOf<typeof introSchema>;
1515

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, {
1818
message: t("You need to check this option to submit the application"),
1919
}),
2020
});
2121

2222
export type SubmitInput = TypeOf<typeof submitSchema>;
2323

24-
const UUIDType = string().optional();
24+
const UUIDType = z.string().optional();
2525

26-
export const applicationBaseSchema = object({
26+
export const applicationBaseSchema = z.object({
2727
uuid: UUIDType,
2828
});
2929

3030
export type ApplicationBaseInput = TypeOf<typeof applicationBaseSchema>;
3131

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(),
3535
uuid: UUIDType,
3636
}).refine((data) => data.decline_this || data.decline_all, {
3737
path: ["decline_all"],
@@ -60,40 +60,40 @@ export const DECLINE_FEEDBACK_NAMES: { [key: string]: string } = {
6060
[DECLINE_FEEDBACK.other]: t("Other"),
6161
};
6262

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(),
7171
uuid: UUIDType,
7272
});
7373

7474
export type DeclineFeedbackInput = TypeOf<typeof declineFeedbackSchema>;
7575

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")),
8181
uuid: UUIDType,
8282
});
8383

8484
export type CreditOptionsInput = TypeOf<typeof creditOptionsSchema>;
8585

8686
export type GetCreditProductsOptionsInput = Omit<CreditOptionsInput, "sector" | "annual_revenue">;
8787

88-
export const repaymentTermsSchema = object({
89-
repayment_years: coerce
88+
export const repaymentTermsSchema = z.object({
89+
repayment_years: z.coerce
9090
.number({
9191
required_error: t("Years is required"),
9292
invalid_type_error: t("Years must be a number"),
9393
})
9494
.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()
9797
.min(1, t("Payment start date is required"))
9898
.refine((value) => isDateAfterCurrentDate(value), {
9999
message: t("Payment start date must be after current date"),
@@ -335,18 +335,18 @@ export interface ILenderListResponse {
335335
page_size: number;
336336
}
337337

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")),
340340
});
341341

342342
export type FormEmailInput = TypeOf<typeof formEmailSchema>;
343343

344344
export type EmailToSMEInput = FormEmailInput & PrivateApplicationInput;
345345

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
350350
.number({
351351
required_error: t("Disbursed final amount is required"),
352352
invalid_type_error: t("Disbursed final amount must be a number"),
@@ -358,19 +358,19 @@ export type FormApprovedInput = TypeOf<typeof approveSchema>;
358358

359359
export type ApproveApplicationInput = FormApprovedInput & PrivateApplicationInput;
360360

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(),
367367
});
368368

369369
export type FormRejectInput = TypeOf<typeof rejectSchema>;
370370

371371
export type RejectApplicationInput = FormRejectInput & PrivateApplicationInput;
372372

373-
export const changeEmailSchema = object({
373+
export const changeEmailSchema = z.object({
374374
new_email: emailSchema,
375375
});
376376

src/schemas/auth.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { type TypeOf, coerce, nativeEnum, object, string } from "zod";
1+
import { type TypeOf, z } from "zod";
22
import { t } from "../util/i18n";
33

44
import { USER_TYPES } from "../constants";
55
import type { ILender } from "./application";
66

7-
export const emailSchema = string().min(1, t("Email address is required")).email(t("Email Address is invalid"));
8-
const passwordSchema = string()
7+
export const emailSchema = z.string().min(1, t("Email address is required")).email(t("Email Address is invalid"));
8+
const passwordSchema = z.string()
99
.min(1, t("Password is required"))
1010
.min(14, t("Password must be more than 14 characters"));
11-
const otp = string().min(6, t("OTP length must be 6 digits")).max(6, t("OTP length must be 6 digits"));
11+
const otp = z.string().min(6, t("OTP length must be 6 digits")).max(6, t("OTP length must be 6 digits"));
1212

13-
export const loginSchema = object({
13+
export const loginSchema = z.object({
1414
username: emailSchema,
1515
password: passwordSchema,
1616
temp_password: otp,
1717
});
1818

1919
export type LoginInput = TypeOf<typeof loginSchema>;
2020

21-
export const setupMFASchema = object({
21+
export const setupMFASchema = z.object({
2222
temp_password: otp,
2323
});
2424

@@ -29,12 +29,12 @@ export interface SetupMFAInput {
2929
session: string;
3030
}
3131

32-
const nameSchema = string().nonempty(t("Full name is required"));
32+
const nameSchema = z.string().nonempty(t("Full name is required"));
3333

34-
export const createUserSchema = object({
34+
export const createUserSchema = z.object({
3535
name: nameSchema,
3636
email: emailSchema,
37-
type: nativeEnum(USER_TYPES, {
37+
type: z.nativeEnum(USER_TYPES, {
3838
errorMap: (issue) => {
3939
switch (issue.code) {
4040
case "invalid_type":
@@ -45,16 +45,16 @@ export const createUserSchema = object({
4545
}
4646
},
4747
}),
48-
lender_id: coerce.number().positive().optional(),
48+
lender_id: z.coerce.number().positive().optional(),
4949
});
5050

5151
export type CreateUserInput = TypeOf<typeof createUserSchema>;
5252

5353
export type UpdateUserInput = Omit<CreateUserInput, "email"> & { id: string | undefined };
5454

55-
export const setPasswordSchema = object({
55+
export const setPasswordSchema = z.object({
5656
password: passwordSchema,
57-
passwordConfirm: string().min(1, t("Please confirm your password")),
57+
passwordConfirm: z.string().min(1, t("Please confirm your password")),
5858
}).refine((data) => data.password === data.passwordConfirm, {
5959
path: ["passwordConfirm"],
6060
message: t("Passwords do not match"),
@@ -67,7 +67,7 @@ export type UpdatePasswordPayload = {
6767
password: string;
6868
};
6969

70-
export const resetPasswordSchema = object({
70+
export const resetPasswordSchema = z.object({
7171
username: emailSchema,
7272
});
7373

0 commit comments

Comments
 (0)