Skip to content

Commit 94cefec

Browse files
committed
yearsOfExperience
1 parent b506b6e commit 94cefec

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

app/(app)/alpha/additional-details/_client.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ import { Button } from "@/components/ui-components/button";
4040
import { Heading, Subheading } from "@/components/ui-components/heading";
4141
import { Divider } from "@/components/ui-components/divider";
4242

43-
export type YearsOfExperience = | "0-1" | "1-3" | "3-5" | "5-8" | "8-12" | "12+"
43+
export const yearsOfExperienceOptions = ["0-1", "1-3", "3-5", "5-8", "8-12", "12+"] as const;
44+
export type YearsOfExperience = typeof yearsOfExperienceOptions[number];
4445
type UserDetails = {
4546
username: string;
4647
name: string;
@@ -431,7 +432,7 @@ function SlideThree({ details }: { details: UserDetails }) {
431432
const professionalOrStudent = getValues("professionalOrStudent");
432433

433434
if (isError && professionalOrStudent === "Working professional") {
434-
isError = await trigger(["workplace", "jobTitle"]);
435+
isError = await trigger(["workplace", "jobTitle","yearsOfExperience"]);
435436
}
436437

437438
if (isError && professionalOrStudent === "Current student") {

drizzle/0010-yearsOfExperiece

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
DO $$ BEGIN
2+
ALTER TABLE "User" ADD COLUMN "yearsOfExperience" text;
3+
EXCEPTION
4+
WHEN duplicate_object THEN null;
5+
END $$;
6+
7+
DO $$ BEGIN
8+
ALTER TABLE "User" ADD CONSTRAINT "User_yearsOfExperience_check"
9+
CHECK ("yearsOfExperience" IN ('0-1', '1-3', '3-5', '5-8', '8-12', '12+'));
10+
EXCEPTION
11+
WHEN duplicate_object THEN null;
12+
END $$;

schema/additionalUserDetails.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import z from "zod";
2-
2+
import { yearsOfExperienceOptions, YearsOfExperience } from "@/app/(app)/alpha/additional-details/_client";
33
export const slideOneSchema = z.object({
44
name: z
55
.string()
@@ -30,9 +30,13 @@ export const slideThreeSchema = z
3030
jobTitle: z.string().max(30, "Max length is 30 characters."),
3131
levelOfStudy: z.string(),
3232
course: z.string().max(30, "Max name length is 30 characters."),
33-
yearsOfExperience: z.enum(['0-1', '1-3', '3-5', '5-8', '8-12', '12+'], {
34-
invalid_type_error: "Select years of experience",
33+
yearsOfExperience: z
34+
.string()
35+
.optional()
36+
.refine((val) => val === undefined || yearsOfExperienceOptions.includes(val as YearsOfExperience), {
37+
message: "Please select a valid years of experience.",
3538
}),
39+
3640
})
3741
.superRefine((val, ctx) => {
3842
if (

0 commit comments

Comments
 (0)