Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Schema update and refactor to use server actions

Khuram Niaz44a747245db4
diff --git a/prisma/migrations/20240604110546_add_label_and_value/migration.sql b/prisma/migrations/20240604110546_add_label_and_value/migration.sql
new file mode 100644
index 0000000..671fcf9
--- /dev/null
+++ b/prisma/migrations/20240604110546_add_label_and_value/migration.sql
@@ -0,0 +1,138 @@
+/*
+ Warnings:
+
+ - You are about to drop the column `name` on the `Location` table. All the data in the column will be lost.
+ - You are about to drop the column `state` on the `Location` table. All the data in the column will be lost.
+ - You are about to drop the column `title` on the `JobTitle` table. All the data in the column will be lost.
+ - You are about to drop the column `name` on the `JobSource` table. All the data in the column will be lost.
+ - You are about to drop the column `statusName` on the `JobStatus` table. All the data in the column will be lost.
+ - You are about to drop the column `name` on the `Company` table. All the data in the column will be lost.
+ - Added the required column `createdBy` to the `Location` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `label` to the `Location` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `value` to the `Location` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `createdBy` to the `JobTitle` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `label` to the `JobTitle` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `value` to the `JobTitle` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `createdAt` to the `Interview` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `label` to the `JobSource` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `value` to the `JobSource` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `jobType` to the `Job` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `label` to the `JobStatus` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `value` to the `JobStatus` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `createdBy` to the `Company` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `label` to the `Company` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `value` to the `Company` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `createdAt` to the `Contact` table without a default value. This is not possible if the table is not empty.
+ - Added the required column `createdBy` to the `Contact` table without a default value. This is not possible if the table is not empty.
+
+*/
+-- RedefineTables
+PRAGMA foreign_keys=OFF;
+CREATE TABLE "new_Location" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "label" TEXT NOT NULL,
+ "value" TEXT NOT NULL,
+ "stateProv" TEXT,
+ "country" TEXT,
+ "createdBy" TEXT NOT NULL,
+ CONSTRAINT "Location_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
+);
+INSERT INTO "new_Location" ("country", "id") SELECT "country", "id" FROM "Location";
+DROP TABLE "Location";
+ALTER TABLE "new_Location" RENAME TO "Location";
+CREATE TABLE "new_JobTitle" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "label" TEXT NOT NULL,
+ "value" TEXT NOT NULL,
+ "createdBy" TEXT NOT NULL,
+ CONSTRAINT "JobTitle_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
+);
+INSERT INTO "new_JobTitle" ("id") SELECT "id" FROM "JobTitle";
+DROP TABLE "JobTitle";
+ALTER TABLE "new_JobTitle" RENAME TO "JobTitle";
+CREATE UNIQUE INDEX "JobTitle_value_key" ON "JobTitle"("value");
+CREATE TABLE "new_Interview" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "createdAt" DATETIME NOT NULL,
+ "jobId" TEXT NOT NULL,
+ CONSTRAINT "Interview_jobId_fkey" FOREIGN KEY ("jobId") REFERENCES "Job" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
+);
+INSERT INTO "new_Interview" ("id", "jobId") SELECT "id", "jobId" FROM "Interview";
+DROP TABLE "Interview";
+ALTER TABLE "new_Interview" RENAME TO "Interview";
+CREATE TABLE "new_JobSource" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "label" TEXT NOT NULL,
+ "value" TEXT NOT NULL
+);
+INSERT INTO "new_JobSource" ("id") SELECT "id" FROM "JobSource";
+DROP TABLE "JobSource";
+ALTER TABLE "new_JobSource" RENAME TO "JobSource";
+CREATE UNIQUE INDEX "JobSource_value_key" ON "JobSource"("value");
+CREATE TABLE "new_Job" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "userId" TEXT NOT NULL,
+ "description" TEXT NOT NULL,
+ "jobType" TEXT NOT NULL,
+ "createdAt" DATETIME NOT NULL,
+ "appliedDate" DATETIME,
+ "dueDate" DATETIME,
+ "statusId" TEXT NOT NULL,
+ "jobTitleId" TEXT NOT NULL,
+ "companyId" TEXT NOT NULL,
+ "jobSourceId" TEXT,
+ "salaryRange" TEXT,
+ "locationId" TEXT,
+ CONSTRAINT "Job_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "Job_statusId_fkey" FOREIGN KEY ("statusId") REFERENCES "JobStatus" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "Job_jobTitleId_fkey" FOREIGN KEY ("jobTitleId") REFERENCES "JobTitle" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "Job_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "Job_jobSourceId_fkey" FOREIGN KEY ("jobSourceId") REFERENCES "JobSource" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT "Job_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "Location" ("id") ON DELETE SET NULL ON UPDATE CASCADE
+);
+INSERT INTO "new_Job" ("appliedDate", "companyId", "createdAt", "description", "dueDate", "id", "jobSourceId", "jobTitleId", "locationId", "salaryRange", "statusId", "userId") SELECT "appliedDate", "companyId", "createdAt", "description", "dueDate", "id", "jobSourceId", "jobTitleId", "locationId", "salaryRange", "statusId", "userId" FROM "Job";
+DROP TABLE "Job";
+ALTER TABLE "new_Job" RENAME TO "Job";
+CREATE TABLE "new_JobStatus" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "label" TEXT NOT NULL,
+ "value" TEXT NOT NULL
+);
+INSERT INTO "new_JobStatus" ("id") SELECT "id" FROM "JobStatus";
+DROP TABLE "JobStatus";
+ALTER TABLE "new_JobStatus" RENAME TO "JobStatus";
+CREATE UNIQUE INDEX "JobStatus_value_key" ON "JobStatus"("value");
+CREATE TABLE "new_Company" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "label" TEXT NOT NULL,
+ "value" TEXT NOT NULL,
+ "logoUrl" TEXT,
+ "createdBy" TEXT NOT NULL,
+ CONSTRAINT "Company_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
+);
+INSERT INTO "new_Company" ("id", "logoUrl") SELECT "id", "logoUrl" FROM "Company";
+DROP TABLE "Company";
+ALTER TABLE "new_Company" RENAME TO "Company";
+CREATE UNIQUE INDEX "Company_value_key" ON "Company"("value");
+CREATE TABLE "new_Contact" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "name" TEXT NOT NULL,
+ "email" TEXT NOT NULL,
+ "createdAt" DATETIME NOT NULL,
+ "createdBy" TEXT NOT NULL,
+ "interviewId" TEXT,
+ CONSTRAINT "Contact_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "Contact_interviewId_fkey" FOREIGN KEY ("interviewId") REFERENCES "Interview" ("id") ON DELETE SET NULL ON UPDATE CASCADE
+);
+INSERT INTO "new_Contact" ("email", "id", "interviewId", "name") SELECT "email", "id", "interviewId", "name" FROM "Contact";
+DROP TABLE "Contact";
+ALTER TABLE "new_Contact" RENAME TO "Contact";
+PRAGMA foreign_key_check("Location");
+PRAGMA foreign_key_check("JobTitle");
+PRAGMA foreign_key_check("Interview");
+PRAGMA foreign_key_check("JobSource");
+PRAGMA foreign_key_check("Job");
+PRAGMA foreign_key_check("JobStatus");
+PRAGMA foreign_key_check("Company");
+PRAGMA foreign_key_check("Contact");
+PRAGMA foreign_keys=ON;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index a93e886..319641a 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -1,5 +1,7 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
+// Step: 1 run `npx prisma generate`
+// Step: 2 run `npx prisma migrate dev` after update, make sure code is updated afterwards
generator client {
provider = "prisma-client-js"
@@ -11,70 +13,87 @@ datasource db {
}
model User {
- id String @id @default(uuid())
+ id String @id @default(uuid())
name String
- email String @unique
+ email String @unique
password String
- createdAt DateTime @default(now())
+ createdAt DateTime @default(now())
jobsApplied Job[]
+ JobTitle JobTitle[]
+ Location Location[]
+ Company Company[]
+ Contact Contact[]
}
model Contact {
id String @id @default(uuid())
name String
email String
+ createdAt DateTime
+ createdBy String // userId
+ user User @relation(fields: [createdBy], references: [id])
Interview Interview? @relation(fields: [interviewId], references: [id])
interviewId String?
}
model JobTitle {
- id String @id @default(uuid())
- title String @unique
- jobs Job[]
+ id String @id @default(uuid())
+ label String
+ value String @unique
+ jobs Job[]
+ createdBy String // userId
+ user User @relation(fields: [createdBy], references: [id])
}
model JobStatus {
- id String @id @default(uuid())
- statusName String @unique
- jobs Job[]
+ id String @id @default(uuid())
+ label String
+ value String @unique
+ jobs Job[]
}
model Location {
id String @id @default(uuid())
- name String @unique
- state String?
- country String
+ label String
+ value String
+ stateProv String?
+ country String?
jobsApplied Job[]
+ createdBy String // userId
+ user User @relation(fields: [createdBy], references: [id])
}
model Company {
id String @id @default(uuid())
- name String @unique
+ label String
+ value String @unique
jobsApplied Job[]
logoUrl String? // field is optional
+ createdBy String // userId
+ user User @relation(fields: [createdBy], references: [id])
}
-//TODO: Add createdBy
-
model JobSource {
id String @id @default(uuid())
- name String
+ label String
+ value String @unique
jobsApplied Job[]
}
model Interview {
id String @id @default(uuid())
+ createdAt DateTime
jobId String
job Job? @relation(fields: [jobId], references: [id])
interviewers Contact[]
}
-//TODO: Add jobtype(fulltime, part time, contract)
model Job {
id String @id @default(uuid())
userId String
User User @relation(fields: [userId], references: [id])
description String
+ jobType String
createdAt DateTime
appliedDate DateTime?
dueDate DateTime?
diff --git a/scripts/seed.js b/scripts/seed.js
index 87005df..36f00d8 100644
--- a/scripts/seed.js
+++ b/scripts/seed.js
@@ -33,7 +33,7 @@ async function seedStatus() {
// Check if the status already exists
const existingStatus = await prisma.jobStatus.findUnique({
where: {
- statusName: status.statusName,
+ value: status.value,
},
});
diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.ts
index ac39907..d521c2a 100644
--- a/src/actions/job.actions.ts
+++ b/src/actions/job.actions.ts
@@ -1,8 +1,10 @@
-import "server-only";
+"use server";
import prisma from "@/lib/db";
+import { getCurrentUser } from "@/utils/user.utils";
export const getStatusList = async (): Promise<any | undefined> => {
try {
+ console.log("GETTING STATUS LIST");
const statuses = await prisma.jobStatus.findMany();
return statuses;
} catch (error) {
@@ -13,6 +15,8 @@ export const getStatusList = async (): Promise<any | undefined> => {
export const getCompanyList = async (): Promise<any | undefined> => {
try {
+ console.log("GETTING COMPANY LIST");
+
const companies = await prisma.company.findMany();
return companies;
} catch (error) {
@@ -20,3 +24,29 @@ export const getCompanyList = async (): Promise<any | undefined> => {
throw new Error("Failed to fetch company list.");
}
};
+
+export const createCompany = async (
+ label: string
+): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ const value = label.trim().toLowerCase();
+
+ // Upsert the name (create if it does not exist, update if it exists)
+ const upsertedName = await prisma.company.upsert({
+ where: { value },
+ update: { label },
+ create: { label, value, createdBy: user.id },
+ });
+
+ return upsertedName;
+ } catch (error) {
+ console.error("Failed to create company: ", error);
+ throw new Error("Failed to create company.");
+ }
+};
diff --git a/src/app/api/company/route.ts b/src/app/api/company/route.ts
index 2608351..a0f3155 100644
--- a/src/app/api/company/route.ts
+++ b/src/app/api/company/route.ts
@@ -1,51 +1,55 @@
-import "server-only";
-import prisma from "@/lib/db";
-import { NextResponse } from "next/server";
-import { auth } from "@/auth";
+// createCompany SERVER ACTION in job.actions.ts has replaced the need of following route handler
+// NOTE: code is kept here for an example use case
+// ============================================
+// import "server-only";
+// import prisma from "@/lib/db";
+// import { NextResponse } from "next/server";
+// import { auth } from "@/auth";
-export const POST = async (req: any) => {
- const session = await auth();
- console.log("SESSION: ", session);
- /* SESSION: {
- user: { name: 'Admin', email: '[email protected]' },
- expires: '2024-07-04T06:16:33.616Z',
- accessToken: {
- name: 'Admin',
- email: '[email protected]',
- sub: '24c84c85-b6a9-40ea-bccb-1b883bcc64cd',
- iat: 1717481780,
- exp: 1720073780,
- jti: '4b5bbd8a-aa0e-4552-b19c-82e2c2dbf130'
- }
- } */
- if (!session || !session.user) {
- return new NextResponse(JSON.stringify({ message: "Not Authenticated" }), {
- status: 401,
- });
- }
+// export const POST = async (req: any) => {
+// const session = await auth();
+// console.log("SESSION: ", session);
+// const userId = session?.accessToken.sub;
+// /* SESSION: {
+// user: { name: 'Admin', email: '[email protected]' },
+// expires: '2024-07-04T06:16:33.616Z',
+// accessToken: {
+// name: 'Admin',
+// email: '[email protected]',
+// sub: '24c84c85-b6a9-40ea-bccb-1b883bcc64cd',
+// iat: 1717481780,
+// exp: 1720073780,
+// jti: '4b5bbd8a-aa0e-4552-b19c-82e2c2dbf130'
+// }
+// } */
+// if (!session || !session.user) {
+// return new NextResponse(JSON.stringify({ message: "Not Authenticated" }), {
+// status: 401,
+// });
+// }
- const { name } = await req.json();
- if (!name) {
- return NextResponse.json(
- { message: "Company name is required" },
- { status: 400 }
- );
- }
+// const { label, value } = await req.json();
+// if (!value) {
+// return NextResponse.json(
+// { message: "Company name is required" },
+// { status: 400 }
+// );
+// }
- try {
- // Upsert the name (create if it does not exist, update if it exists)
- const upsertedName = await prisma.company.upsert({
- where: { name },
- update: { name },
- create: { name },
- });
+// try {
+// // Upsert the name (create if it does not exist, update if it exists)
+// const upsertedName = await prisma.company.upsert({
+// where: { value },
+// update: { label },
+// create: { label, value, createdBy: userId },
+// });
- return NextResponse.json(upsertedName, { status: 201 });
- } catch (error) {
- console.error("Error upserting name:", error);
- return NextResponse.json(
- { message: "Internal server error" },
- { status: 500 }
- );
- }
-};
+// return NextResponse.json(upsertedName, { status: 201 });
+// } catch (error) {
+// console.error("Error upserting name:", error);
+// return NextResponse.json(
+// { message: "Internal server error" },
+// { status: 500 }
+// );
+// }
+// };
diff --git a/src/components/AddJobForm.tsx b/src/components/AddJobForm.tsx
index fe8b545..1115aed 100644
--- a/src/components/AddJobForm.tsx
+++ b/src/components/AddJobForm.tsx
@@ -24,7 +24,7 @@ import { SALARY_RANGES } from "@/lib/data/salaryRangeData";
import { useState } from "react";
interface AddJobFormProps {
- jobStatuses: { id: string; statusName: string }[];
+ jobStatuses: { id: string; label: string; value: string }[];
companies: any[];
}
@@ -39,7 +39,7 @@ export default function AddJobForm({
// mode: "onChange",
defaultValues: {
dateApplied: new Date(),
- status: jobStatuses[0].statusName,
+ status: jobStatuses[0].value,
},
});
@@ -87,11 +87,7 @@ export default function AddJobForm({
<FormItem className="flex flex-col">
<FormLabel>Company</FormLabel>
<FormControl>
- <Combobox
- dataKeys={["name", "id"]}
- options={companies}
- field={field}
- />
+ <Combobox options={companies} field={field} creatable />
</FormControl>
<FormMessage />
</FormItem>
@@ -122,11 +118,7 @@ export default function AddJobForm({
render={({ field }) => (
<FormItem className="flex flex-col">
<FormLabel>Job Source</FormLabel>
- <Combobox
- dataKeys={["label", "value"]}
- options={JOB_SOURCES}
- field={field}
- />
+ <Combobox options={JOB_SOURCES} field={field} />
<FormMessage />
</FormItem>
)}
@@ -142,7 +134,6 @@ export default function AddJobForm({
<FormLabel>Status</FormLabel>
<SelectFormCtrl
label="Job Status"
- dataKey="statusName"
options={jobStatuses}
field={field}
/>
@@ -190,7 +181,6 @@ export default function AddJobForm({
<FormControl>
<SelectFormCtrl
label="Salary Range"
- dataKey="range"
options={SALARY_RANGES}
field={field}
/>
diff --git a/src/components/ComboBox.tsx b/src/components/ComboBox.tsx
index e371984..623b22e 100644
--- a/src/components/ComboBox.tsx
+++ b/src/components/ComboBox.tsx
@@ -1,7 +1,7 @@
"use client";
import { Check, ChevronsUpDown, CirclePlus, Loader } from "lucide-react";
-import { ControllerRenderProps, FieldName } from "react-hook-form";
+import { ControllerRenderProps } from "react-hook-form";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
@@ -13,12 +13,7 @@ import {
CommandItem,
CommandList,
} from "@/components/ui/command";
-import {
- FormControl,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/components/ui/form";
+import { FormControl } from "@/components/ui/form";
import {
Popover,
PopoverContent,
@@ -26,36 +21,31 @@ import {
} from "@/components/ui/popover";
import { Job } from "@/models/job.model";
import { ScrollArea } from "./ui/scroll-area";
-import { useState } from "react";
-import { upsertCompanyName } from "@/utils/company";
+import { useState, useTransition } from "react";
import { delay } from "@/utils/delay";
+import { createCompany } from "@/actions/job.actions";
interface ComboboxProps {
- dataKeys: string[];
options: any[];
field: ControllerRenderProps<Job, any>;
+ creatable?: boolean;
}
-export function Combobox({ options, field, dataKeys }: ComboboxProps) {
+export function Combobox({ options, field, creatable }: ComboboxProps) {
const [newOption, setNewOption] = useState<string>("");
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);
- const [loading, setLoading] = useState(false);
- const [key1, key2] = dataKeys;
- async function onCreateOption(value: string) {
- setLoading(true);
- try {
- if (field.name === "company") {
- const newOption = await upsertCompanyName(value);
- options.unshift(newOption);
- field.onChange(newOption[key2]);
- setIsPopoverOpen(false);
- }
- } catch (error) {
- console.error("Error:", error);
- } finally {
- setLoading(false);
- }
- }
+
+ const [isPending, startTransition] = useTransition();
+
+ const onCreateOption2 = (label: string) => {
+ if (!label) return;
+ startTransition(async () => {
+ const response = await createCompany(label);
+ options.unshift(response);
+ field.onChange(response.value);
+ setIsPopoverOpen(false);
+ });
+ };
return (
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>
@@ -70,10 +60,10 @@ export function Combobox({ options, field, dataKeys }: ComboboxProps) {
)}
>
{field.value
- ? options.find((option) => option[key2] === field.value)[key1]
+ ? options.find((option) => option.value === field.value).label
: `Select ${field.name}`}
- {loading ? (
+ {isPending ? (
<Loader className="h-4 w-4 shrink-0 spinner" />
) : (
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
@@ -86,16 +76,19 @@ export function Combobox({ options, field, dataKeys }: ComboboxProps) {
<CommandInput
value={newOption}
onValueChange={(val: string) => setNewOption(val)}
- placeholder={`Search ${field.name}`}
+ placeholder={`${creatable ? "Create or " : ""}Search ${field.name}`}
/>
<CommandEmpty
onClick={() => {
- onCreateOption(newOption);
+ onCreateOption2(newOption);
setNewOption("");
}}
- className="flex cursor-pointer items-center justify-center gap-1 italic"
+ className={cn(
+ "flex cursor-pointer items-center justify-center gap-1 italic mt-2",
+ !newOption && "text-muted-foreground cursor-default"
+ )}
>
- {field.name === "company" ? (
+ {creatable ? (
<>
<CirclePlus className="h-4 w-4" />
<p>Create: </p>
@@ -112,11 +105,11 @@ export function Combobox({ options, field, dataKeys }: ComboboxProps) {
<CommandList className="capitalize">
{options.map((option) => (
<CommandItem
- value={option[key1]}
- key={option[key2]}
+ value={option.value}
+ key={option.id}
onSelect={() => {
if (field.onChange) {
- field.onChange(option[key2]);
+ field.onChange(option.value);
setIsPopoverOpen(false);
}
}}
@@ -124,12 +117,12 @@ export function Combobox({ options, field, dataKeys }: ComboboxProps) {
<Check
className={cn(
"mr-2 h-4 w-4",
- option[key2] === field.value
+ option.value === field.value
? "opacity-100"
: "opacity-0"
)}
/>
- {option[key1]}
+ {option.label}
</CommandItem>
))}
</CommandList>
diff --git a/src/components/Select.tsx b/src/components/Select.tsx
index 9921cdd..1b81a08 100644
--- a/src/components/Select.tsx
+++ b/src/components/Select.tsx
@@ -15,10 +15,9 @@ interface SelectProps {
label: string;
options: any[];
field: ControllerRenderProps<Job, any>;
- dataKey: string;
}
-function SelectFormCtrl({ label, options, field, dataKey }: SelectProps) {
+function SelectFormCtrl({ label, options, field }: SelectProps) {
return (
<>
<Select
@@ -37,10 +36,10 @@ function SelectFormCtrl({ label, options, field, dataKey }: SelectProps) {
return (
<SelectItem
key={option.id}
- value={option[dataKey]}
+ value={option.value}
className="capitalize"
>
- {option[dataKey]}
+ {option.label ? option.label : option.value}
</SelectItem>
);
})}
diff --git a/src/lib/data/salaryRangeData.ts b/src/lib/data/salaryRangeData.ts
index 8e7e9bd..b69dac4 100644
--- a/src/lib/data/salaryRangeData.ts
+++ b/src/lib/data/salaryRangeData.ts
@@ -1,16 +1,16 @@
export const SALARY_RANGES = [
- { id: 1, range: "0 - 10,000" },
- { id: 2, range: "10,000 - 20,000" },
- { id: 3, range: "20,000 - 30,000" },
- { id: 4, range: "30,000 - 40,000" },
- { id: 5, range: "40,000 - 50,000" },
- { id: 6, range: "50,000 - 60,000" },
- { id: 7, range: "60,000 - 70,000" },
- { id: 8, range: "70,000 - 80,000" },
- { id: 9, range: "80,000 - 90,000" },
- { id: 10, range: "90,000 - 100,000" },
- { id: 11, range: "100,000 - 110,000" },
- { id: 12, range: "120,000 - 130,000" },
- { id: 13, range: "130,000 - 140,000" },
- { id: 14, range: "> 150,000" },
+ { id: 1, value: "0 - 10,000" },
+ { id: 2, value: "10,000 - 20,000" },
+ { id: 3, value: "20,000 - 30,000" },
+ { id: 4, value: "30,000 - 40,000" },
+ { id: 5, value: "40,000 - 50,000" },
+ { id: 6, value: "50,000 - 60,000" },
+ { id: 7, value: "60,000 - 70,000" },
+ { id: 8, value: "70,000 - 80,000" },
+ { id: 9, value: "80,000 - 90,000" },
+ { id: 10, value: "90,000 - 100,000" },
+ { id: 11, value: "100,000 - 110,000" },
+ { id: 12, value: "120,000 - 130,000" },
+ { id: 13, value: "130,000 - 140,000" },
+ { id: 14, value: "> 150,000" },
];
diff --git a/src/lib/data/seedData.js b/src/lib/data/seedData.js
index 39b82ae..42a10d7 100644
--- a/src/lib/data/seedData.js
+++ b/src/lib/data/seedData.js
@@ -1,11 +1,11 @@
const STATUS_DATA = [
- { statusName: "draft" },
- { statusName: "applied" },
- { statusName: "interview" },
- { statusName: "offer" },
- { statusName: "rejected" },
- { statusName: "expired" },
- { statusName: "archived" },
+ { label: "Draft", value: "draft" },
+ { label: "Applied", value: "applied" },
+ { label: "Interview", value: "interview" },
+ { label: "Offer", value: "offer" },
+ { label: "Rejected", value: "rejected" },
+ { label: "Expired", value: "expired" },
+ { label: "Archived", value: "archived" },
];
module.exports = {
diff --git a/src/utils/company.ts b/src/utils/company.ts
index 62a27f2..e3d274a 100644
--- a/src/utils/company.ts
+++ b/src/utils/company.ts
@@ -1,16 +1,20 @@
-export const upsertCompanyName = async (name: string) => {
- const response = await fetch("/api/company", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({ name: name.trim().toLowerCase() }),
- });
+// FOLLOWING IS AN EXAMPLE OF ROUTE HANDLER APPROACH (FOR API refer to api/company/route.ts)
+// FUNCTION IS REPLACED BY SERVER ACTION IN job.action.ts
+// ========================================================
+// export const upsertCompanyName = async (label: string) => {
+// const value = label.trim().toLowerCase();
+// const response = await fetch("/api/company", {
+// method: "POST",
+// headers: {
+// "Content-Type": "application/json",
+// },
+// body: JSON.stringify({ label, value }),
+// });
- if (!response.ok) {
- throw new Error(`HTTP error! status: ${response.status}`);
- }
+// if (!response.ok) {
+// throw new Error(`HTTP error! status: ${response.status}`);
+// }
- const data = await response.json();
- return data;
-};
+// const data = await response.json();
+// return data;
+// };