forked from codu-code/codu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadditionalUserDetails.ts
78 lines (72 loc) · 2.04 KB
/
additionalUserDetails.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import z from "zod";
export const slideOneSchema = z.object({
name: z
.string()
.trim()
.min(2, "Min name length is 2 characters.")
.max(50, "Max name length is 50 characters."),
username: z
.string()
.trim()
.min(3, "Min username length is 3 characters.")
.max(40, "Max username length is 40 characters.")
.regex(
/^[a-zA-Z0-9-]+$/,
"Username can only contain alphanumerics and dashes.",
),
location: z.string().min(1, "Location is required"),
});
export const slideTwoSchema = z.object({
gender: z.string().min(1, "Gender is required"),
dateOfBirth: z.string(),
});
export const slideThreeSchema = z
.object({
professionalOrStudent: z.string().min(1, "Select an option"),
workplace: z.string().max(30, "Max length is 30 characters."),
jobTitle: z.string().max(30, "Max length is 30 characters."),
levelOfStudy: z.string(),
course: z.string().max(30, "Max name length is 30 characters."),
})
.superRefine((val, ctx) => {
if (
val.professionalOrStudent === "Current student" &&
val.levelOfStudy === ""
) {
ctx.addIssue({
path: ["levelOfStudy"],
code: "custom",
message: "required",
});
}
if (val.professionalOrStudent === "Current student" && val.course === "") {
ctx.addIssue({
path: ["course"],
code: "custom",
message: "required",
});
}
if (
val.professionalOrStudent === "Working professional" &&
val.workplace === ""
) {
ctx.addIssue({
path: ["workplace"],
code: "custom",
message: "required",
});
}
if (
val.professionalOrStudent === "Working professional" &&
val.jobTitle === ""
) {
ctx.addIssue({
path: ["jobTitle"],
code: "custom",
message: "required",
});
}
});
export type TypeSlideOneSchema = z.TypeOf<typeof slideOneSchema>;
export type TypeSlideTwoSchema = z.TypeOf<typeof slideTwoSchema>;
export type TypeSlideThreeSchema = z.TypeOf<typeof slideThreeSchema>;