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.

Create job title and location

Khuram Niaz013383456e20
diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.ts
index d521c2a..fa2b66e 100644
--- a/src/actions/job.actions.ts
+++ b/src/actions/job.actions.ts
@@ -4,24 +4,45 @@ 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) {
- console.error("Failed to fetch status list:", error);
- throw new Error("Failed to fetch status list.");
+ const msg = "Failed to fetch status list. ";
+ console.error(msg, error);
+ throw new Error(msg);
}
};
export const getCompanyList = async (): Promise<any | undefined> => {
try {
- console.log("GETTING COMPANY LIST");
-
const companies = await prisma.company.findMany();
return companies;
} catch (error) {
- console.error("Failed to fetch company list:", error);
- throw new Error("Failed to fetch company list.");
+ const msg = "Failed to fetch company list. ";
+ console.error(msg, error);
+ throw new Error(msg);
+ }
+};
+
+export const getJobTitleList = async (): Promise<any | undefined> => {
+ try {
+ const list = await prisma.jobTitle.findMany();
+ return list;
+ } catch (error) {
+ const msg = "Failed to fetch job title list. ";
+ console.error(msg, error);
+ throw new Error(msg);
+ }
+};
+
+export const getJobLocationList = async (): Promise<any | undefined> => {
+ try {
+ const list = await prisma.location.findMany();
+ return list;
+ } catch (error) {
+ const msg = "Failed to fetch job location list. ";
+ console.error(msg, error);
+ throw new Error(msg);
}
};
@@ -46,7 +67,58 @@ export const createCompany = async (
return upsertedName;
} catch (error) {
- console.error("Failed to create company: ", error);
- throw new Error("Failed to create company.");
+ const msg = "Failed to create company. ";
+ console.error(msg, error);
+ throw new Error(msg);
+ }
+};
+
+export const createJobTitle = async (
+ label: string
+): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ const value = label.trim().toLowerCase();
+
+ const upsertedTitle = await prisma.jobTitle.upsert({
+ where: { value },
+ update: { label },
+ create: { label, value, createdBy: user.id },
+ });
+
+ return upsertedTitle;
+ } catch (error) {
+ const msg = "Failed to create job title. ";
+ console.error(msg, error);
+ throw new Error(msg);
+ }
+};
+
+export const createLocation = async (
+ label: string
+): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ const value = label.trim().toLowerCase();
+
+ const location = await prisma.location.create({
+ data: { label, value, createdBy: user.id },
+ });
+
+ return location;
+ } catch (error) {
+ const msg = "Failed to create job location. ";
+ console.error(msg, error);
+ throw new Error(msg);
}
};
diff --git a/src/components/AddJob.tsx b/src/components/AddJob.tsx
index 30ff9a3..cf9909b 100644
--- a/src/components/AddJob.tsx
+++ b/src/components/AddJob.tsx
@@ -1,18 +1,30 @@
import { DialogHeader, DialogTitle } from "@/components/ui/dialog";
import AddJobForm from "./AddJobForm";
-import { getCompanyList, getStatusList } from "@/actions/job.actions";
+import {
+ getCompanyList,
+ getJobLocationList,
+ getJobTitleList,
+ getStatusList,
+} from "@/actions/job.actions";
export async function AddJob() {
- const [statuses, companies] = await Promise.all([
+ const [statuses, companies, jobTitles, locations] = await Promise.all([
getStatusList(),
getCompanyList(),
+ getJobTitleList(),
+ getJobLocationList(),
]);
return (
<>
<DialogHeader>
<DialogTitle>Add Job</DialogTitle>
</DialogHeader>
- <AddJobForm jobStatuses={statuses} companies={companies} />
+ <AddJobForm
+ jobStatuses={statuses}
+ companies={companies}
+ jobTitles={jobTitles}
+ locations={locations}
+ />
</>
);
}
diff --git a/src/components/AddJobForm.tsx b/src/components/AddJobForm.tsx
index 1115aed..2315952 100644
--- a/src/components/AddJobForm.tsx
+++ b/src/components/AddJobForm.tsx
@@ -26,11 +26,15 @@ import { useState } from "react";
interface AddJobFormProps {
jobStatuses: { id: string; label: string; value: string }[];
companies: any[];
+ jobTitles: { id: string; label: string; value: string }[];
+ locations: { id: string; label: string; value: string }[];
}
export default function AddJobForm({
jobStatuses,
companies,
+ jobTitles,
+ locations,
}: AddJobFormProps) {
const [loading, setLoading] = useState(false);
@@ -71,7 +75,7 @@ export default function AddJobForm({
<FormItem className="flex flex-col">
<FormLabel>Job Title</FormLabel>
<FormControl>
- <Input {...field} />
+ <Combobox options={jobTitles} field={field} creatable />
</FormControl>
<FormMessage />
</FormItem>
@@ -103,7 +107,7 @@ export default function AddJobForm({
<FormItem className="flex flex-col">
<FormLabel>Job Location</FormLabel>
<FormControl>
- <Input {...field} />
+ <Combobox options={locations} field={field} creatable />
</FormControl>
<FormMessage />
</FormItem>
diff --git a/src/components/ComboBox.tsx b/src/components/ComboBox.tsx
index 623b22e..2fc8bd2 100644
--- a/src/components/ComboBox.tsx
+++ b/src/components/ComboBox.tsx
@@ -23,7 +23,11 @@ import { Job } from "@/models/job.model";
import { ScrollArea } from "./ui/scroll-area";
import { useState, useTransition } from "react";
import { delay } from "@/utils/delay";
-import { createCompany } from "@/actions/job.actions";
+import {
+ createCompany,
+ createJobTitle,
+ createLocation,
+} from "@/actions/job.actions";
interface ComboboxProps {
options: any[];
@@ -37,10 +41,23 @@ export function Combobox({ options, field, creatable }: ComboboxProps) {
const [isPending, startTransition] = useTransition();
- const onCreateOption2 = (label: string) => {
+ const onCreateOption = (label: string) => {
if (!label) return;
startTransition(async () => {
- const response = await createCompany(label);
+ let response;
+ switch (field.name) {
+ case "company":
+ response = await createCompany(label);
+ break;
+ case "title":
+ response = await createJobTitle(label);
+ break;
+ case "location":
+ response = await createLocation(label);
+ break;
+ default:
+ break;
+ }
options.unshift(response);
field.onChange(response.value);
setIsPopoverOpen(false);
@@ -80,7 +97,7 @@ export function Combobox({ options, field, creatable }: ComboboxProps) {
/>
<CommandEmpty
onClick={() => {
- onCreateOption2(newOption);
+ onCreateOption(newOption);
setNewOption("");
}}
className={cn(