-
-
Notifications
You must be signed in to change notification settings - Fork 173
Feature/years of experience #1120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bce6c91
44b056c
42966cb
2be6c5e
d9bfb08
f216eca
b506b6e
94cefec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,8 @@ import { redirect } from "next/navigation"; | |||||||||||||||
| import Content from "./_client"; | ||||||||||||||||
| import { getServerAuthSession } from "@/server/auth"; | ||||||||||||||||
| import { db } from "@/server/db"; | ||||||||||||||||
| import {YearsOfExperience} from "./_client"; | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| export default async function Page() { | ||||||||||||||||
| const session = await getServerAuthSession(); | ||||||||||||||||
|
|
@@ -22,6 +24,7 @@ export default async function Page() { | |||||||||||||||
| levelOfStudy: true, | ||||||||||||||||
| jobTitle: true, | ||||||||||||||||
| workplace: true, | ||||||||||||||||
| yearsOfExperience: true, | ||||||||||||||||
| }, | ||||||||||||||||
| where: (user, { eq }) => eq(user.id, userId), | ||||||||||||||||
| }); | ||||||||||||||||
|
|
@@ -37,6 +40,10 @@ export default async function Page() { | |||||||||||||||
| levelOfStudy: details?.levelOfStudy || "", | ||||||||||||||||
| jobTitle: details?.jobTitle || "", | ||||||||||||||||
| workplace: details?.workplace || "", | ||||||||||||||||
| yearsOfExperience: details?.yearsOfExperience && | ||||||||||||||||
| ["0-1", "1-3", "3-5", "5-8", "8-12", "12+"].includes(details.yearsOfExperience) | ||||||||||||||||
| ? details.yearsOfExperience as YearsOfExperience // Cast to the union type | ||||||||||||||||
| : "0-1", | ||||||||||||||||
|
Comment on lines
+43
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle unexpected Defaulting to 🛠️ Refactor suggestion Simplify the The current assignment logic can be simplified to enhance readability and maintainability. Checking for Consider applying this diff: -yearsOfExperience: details?.yearsOfExperience &&
- ["0-1", "1-3", "3-5", "5-8", "8-12", "12+"].includes(details.yearsOfExperience)
- ? details.yearsOfExperience as YearsOfExperience // Cast to the union type
- : "0-1",
+yearsOfExperience: ["0-1", "1-3", "3-5", "5-8", "8-12", "12+"].includes(details?.yearsOfExperience)
+ ? (details.yearsOfExperience as YearsOfExperience) // Cast to the union type
+ : "0-1",📝 Committable suggestion
Suggested change
|
||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| return <Content details={detailsWithNullsRemoved} />; | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| DO $$ BEGIN | ||
| ALTER TABLE "User" ADD COLUMN "yearsOfExperience" text; | ||
| EXCEPTION | ||
| WHEN duplicate_object THEN null; | ||
| END $$; | ||
|
|
||
| DO $$ BEGIN | ||
| ALTER TABLE "User" ADD CONSTRAINT "User_yearsOfExperience_check" | ||
| CHECK ("yearsOfExperience" IN ('0-1', '1-3', '3-5', '5-8', '8-12', '12+')); | ||
| EXCEPTION | ||
| WHEN duplicate_object THEN null; | ||
| END $$; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import z from "zod"; | ||
|
|
||
| import { yearsOfExperienceOptions, YearsOfExperience } from "@/app/(app)/alpha/additional-details/_client"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider moving shared constants to a common file. Importing from a client-side file ( Consider moving the // shared/constants.ts
export const yearsOfExperienceOptions = [...] as const;
export type YearsOfExperience = typeof yearsOfExperienceOptions[number];Then update the import statement: import { yearsOfExperienceOptions, YearsOfExperience } from "@/shared/constants";This approach ensures that these constants are accessible throughout your application without risking server-side rendering issues. |
||
| export const slideOneSchema = z.object({ | ||
| name: z | ||
| .string() | ||
|
|
@@ -30,6 +30,13 @@ export const slideThreeSchema = z | |
| jobTitle: z.string().max(30, "Max length is 30 characters."), | ||
| levelOfStudy: z.string(), | ||
| course: z.string().max(30, "Max name length is 30 characters."), | ||
| yearsOfExperience: z | ||
| .string() | ||
| .optional() | ||
| .refine((val) => val === undefined || yearsOfExperienceOptions.includes(val as YearsOfExperience), { | ||
| message: "Please select a valid years of experience.", | ||
| }), | ||
|
|
||
| }) | ||
| .superRefine((val, ctx) => { | ||
| if ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consolidate imports from the same module
To improve code clarity and organization, consider combining the imports from
"./_client"into a single statement.Apply this diff: