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.

Add job titles table

Khuram Niaz4d48d441e432
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 411db76..e13e129 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -39,7 +39,7 @@ model Contact {
model JobTitle {
id String @id @default(uuid())
label String
- value String @unique
+ value String @unique //TODO: Change and Apply unique constraint on index with value and userid
jobs Job[]
createdBy String // userId
user User @relation(fields: [createdBy], references: [id])
diff --git a/src/actions/company.actions.ts b/src/actions/company.actions.ts
index f7d44d4..0631d32 100644
--- a/src/actions/company.actions.ts
+++ b/src/actions/company.actions.ts
@@ -45,11 +45,11 @@ export const getCompanyList = async (
},
}
: {}),
- // orderBy: {
- // jobsApplied: {
- // _count: "desc",
- // },
- // },
+ orderBy: {
+ jobsApplied: {
+ _count: "desc",
+ },
+ },
}),
prisma.company.count({
where: {
diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.ts
index 2822126..bdfac2c 100644
--- a/src/actions/job.actions.ts
+++ b/src/actions/job.actions.ts
@@ -15,17 +15,6 @@ export const getStatusList = async (): Promise<any | undefined> => {
}
};
-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 getJobSourceList = async (): Promise<any | undefined> => {
try {
const list = await prisma.jobSource.findMany();
@@ -139,32 +128,6 @@ export const getJobDetails = async (
}
};
-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> => {
diff --git a/src/actions/jobtitle.actions.ts b/src/actions/jobtitle.actions.ts
new file mode 100644
index 0000000..1d4ac4d
--- /dev/null
+++ b/src/actions/jobtitle.actions.ts
@@ -0,0 +1,108 @@
+"use server";
+import prisma from "@/lib/db";
+import { getCurrentUser } from "@/utils/user.utils";
+
+export const getAllJobTitles = async (): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+ const list = await prisma.jobTitle.findMany({
+ where: {
+ createdBy: user?.id,
+ },
+ });
+ return list;
+ } catch (error) {
+ const msg = "Failed to fetch job title list. ";
+ console.error(msg, error);
+ throw new Error(msg);
+ }
+};
+
+export const getJobTitleList = async (
+ page = 1,
+ limit = 10,
+ countBy?: string
+): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+ const skip = (page - 1) * limit;
+
+ const [data, total] = await Promise.all([
+ prisma.jobTitle.findMany({
+ where: {
+ createdBy: user.id,
+ },
+ skip,
+ take: limit,
+ ...(countBy
+ ? {
+ select: {
+ id: true,
+ label: true,
+ value: true,
+ _count: {
+ select: {
+ jobs: {
+ where: {
+ Status: {
+ value: countBy,
+ },
+ },
+ },
+ },
+ },
+ },
+ }
+ : {}),
+ orderBy: {
+ jobs: {
+ _count: "desc",
+ },
+ },
+ }),
+ prisma.jobTitle.count({
+ where: {
+ createdBy: user.id,
+ },
+ }),
+ ]);
+ return { data, total };
+ } catch (error) {
+ const msg = "Failed to fetch job title list. ";
+ 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, createdBy: user.id },
+ 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);
+ }
+};
diff --git a/src/app/dashboard/admin/page.tsx b/src/app/dashboard/admin/page.tsx
index 025b045..919e0ba 100644
--- a/src/app/dashboard/admin/page.tsx
+++ b/src/app/dashboard/admin/page.tsx
@@ -1,4 +1,5 @@
import CompaniesContainer from "@/components/CompaniesContainer";
+import JobTitlesContainer from "@/components/JobTitlesContainer";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
async function AdminPage() {
@@ -16,7 +17,9 @@ async function AdminPage() {
<TabsContent value="companies">
<CompaniesContainer />
</TabsContent>
- <TabsContent value="titles">titles table here</TabsContent>
+ <TabsContent value="titles">
+ <JobTitlesContainer />
+ </TabsContent>
<TabsContent value="locations">location table here</TabsContent>
</Tabs>
</div>
diff --git a/src/app/dashboard/myjobs/page.tsx b/src/app/dashboard/myjobs/page.tsx
index 6ac6953..90a80f0 100644
--- a/src/app/dashboard/myjobs/page.tsx
+++ b/src/app/dashboard/myjobs/page.tsx
@@ -3,11 +3,11 @@ import { Metadata } from "next";
import {
getJobLocationList,
getJobSourceList,
- getJobTitleList,
getStatusList,
} from "@/actions/job.actions";
import JobsContainer from "@/components/JobsContainer";
import { getAllCompanies } from "@/actions/company.actions";
+import { getAllJobTitles } from "@/actions/jobtitle.actions";
export const metadata: Metadata = {
title: "My Jobs | JobSync",
@@ -17,7 +17,7 @@ async function MyJobs() {
const [statuses, companies, titles, locations, sources] = await Promise.all([
getStatusList(),
getAllCompanies(),
- getJobTitleList(),
+ getAllJobTitles(),
getJobLocationList(),
getJobSourceList(),
]);
diff --git a/src/app/favicon.ico b/src/app/favicon.ico
index 718d6fe..c194e85 100644
Binary files a/src/app/favicon.ico and b/src/app/favicon.ico differ
diff --git a/src/components/AddCompany.tsx b/src/components/AddCompany.tsx
index 78847e0..b352c44 100644
--- a/src/components/AddCompany.tsx
+++ b/src/components/AddCompany.tsx
@@ -107,7 +107,7 @@ function AddCompany({
<DialogHeader>
<DialogTitle>{pageTitle}</DialogTitle>
<DialogDescription className="text-primary">
- Caution: Editing name of the company with affect all the related
+ Caution: Editing name of the company will affect all the related
job records.
</DialogDescription>
</DialogHeader>
diff --git a/src/components/ComboBox.tsx b/src/components/ComboBox.tsx
index c6a9617..0f9797b 100644
--- a/src/components/ComboBox.tsx
+++ b/src/components/ComboBox.tsx
@@ -22,9 +22,10 @@ import {
import { ScrollArea } from "./ui/scroll-area";
import { useState, useTransition } from "react";
import { delay } from "@/utils/delay";
-import { createJobTitle, createLocation } from "@/actions/job.actions";
+import { createLocation } from "@/actions/job.actions";
import { JobForm } from "@/models/job.model";
import { addCompany } from "@/actions/company.actions";
+import { createJobTitle } from "@/actions/jobtitle.actions";
interface ComboboxProps {
options: any[];
diff --git a/src/components/CompaniesContainer.tsx b/src/components/CompaniesContainer.tsx
index a987075..d6866e8 100644
--- a/src/components/CompaniesContainer.tsx
+++ b/src/components/CompaniesContainer.tsx
@@ -1,14 +1,8 @@
"use client";
-import { useEffect, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
import AddCompany from "./AddCompany";
import CompaniesTable from "./CompaniesTable";
-import {
- Card,
- CardContent,
- CardFooter,
- CardHeader,
- CardTitle,
-} from "./ui/card";
+import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";
import { Company } from "@/models/job.model";
import { getCompanyById, getCompanyList } from "@/actions/company.actions";
import { APP_CONSTANTS } from "@/lib/constants";
@@ -23,15 +17,18 @@ function CompaniesContainer() {
const totalPages = Math.ceil(totalCompanies / recordsPerPage);
- const loadCompanies = async (page: number) => {
- const { data, total } = await getCompanyList(
- page,
- recordsPerPage,
- "applied"
- );
- setCompanies(data);
- setTotalCompanies(total);
- };
+ const loadCompanies = useCallback(
+ async (page: number) => {
+ const { data, total } = await getCompanyList(
+ page,
+ recordsPerPage,
+ "applied"
+ );
+ setCompanies(data);
+ setTotalCompanies(total);
+ },
+ [recordsPerPage]
+ );
const reloadCompanies = () => {
loadCompanies(1);
@@ -43,7 +40,7 @@ function CompaniesContainer() {
useEffect(() => {
loadCompanies(currentPage);
- }, [currentPage]);
+ }, [currentPage, loadCompanies]);
const onEditCompany = async (companyId: string) => {
const company = await getCompanyById(companyId);
diff --git a/src/components/CompaniesTable.tsx b/src/components/CompaniesTable.tsx
index 2853e76..2488e76 100644
--- a/src/components/CompaniesTable.tsx
+++ b/src/components/CompaniesTable.tsx
@@ -110,7 +110,7 @@ function CompaniesTable({
{startPostIndex} to {endPostIndex}
</strong>{" "}
of
- <strong> {totalCompanies}</strong> jobs
+ <strong> {totalCompanies}</strong> companies
</div>
{totalCompanies > recordsPerPage ? (
<TablePagination
diff --git a/src/components/JobTitlesContainer.tsx b/src/components/JobTitlesContainer.tsx
new file mode 100644
index 0000000..c029066
--- /dev/null
+++ b/src/components/JobTitlesContainer.tsx
@@ -0,0 +1,72 @@
+"use client";
+import { useCallback, useEffect, useState } from "react";
+import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";
+import { APP_CONSTANTS } from "@/lib/constants";
+import { JobTitle } from "@prisma/client";
+import JobTitlesTable from "./JobTitlesTable";
+import { getJobTitleList } from "@/actions/jobtitle.actions";
+
+function JobTitlesContainer() {
+ const [titles, setTitles] = useState<JobTitle[]>([]);
+ const [totalJobTitles, setTotalJobTitles] = useState(0);
+ const [currentPage, setCurrentPage] = useState(1);
+ const [editJobTitle, setEditJobTitle] = useState(null);
+
+ const recordsPerPage = APP_CONSTANTS.RECORDS_PER_PAGE;
+
+ const totalPages = Math.ceil(totalJobTitles / recordsPerPage);
+
+ const loadJobTitles = useCallback(
+ async (page: number) => {
+ const { data, total } = await getJobTitleList(
+ page,
+ recordsPerPage,
+ "applied"
+ );
+ setTitles(data);
+ setTotalJobTitles(total);
+ },
+ [recordsPerPage]
+ );
+
+ const reloadJobTitles = () => {
+ loadJobTitles(1);
+ };
+
+ const resetEditJobTitle = () => {
+ setEditJobTitle(null);
+ };
+
+ useEffect(() => {
+ loadJobTitles(currentPage);
+ }, [currentPage, loadJobTitles]);
+
+ return (
+ <>
+ <div className="col-span-3">
+ <Card x-chunk="dashboard-06-chunk-0">
+ <CardHeader className="flex-row justify-between items-center">
+ <CardTitle>Job Titles</CardTitle>
+ <div className="flex items-center">
+ <div className="ml-auto flex items-center gap-2">
+ {/* <AddCompany reloadCompanies={reloadJobTitles} /> */}
+ </div>
+ </div>
+ </CardHeader>
+ <CardContent>
+ <JobTitlesTable
+ jobTitles={titles}
+ currentPage={currentPage}
+ totalPages={totalPages}
+ recordsPerPage={recordsPerPage}
+ totalJobTitles={totalJobTitles}
+ onPageChange={setCurrentPage}
+ />
+ </CardContent>
+ </Card>
+ </div>
+ </>
+ );
+}
+
+export default JobTitlesContainer;
diff --git a/src/components/JobTitlesTable.tsx b/src/components/JobTitlesTable.tsx
new file mode 100644
index 0000000..9e74b17
--- /dev/null
+++ b/src/components/JobTitlesTable.tsx
@@ -0,0 +1,104 @@
+"use client";
+import { Button } from "./ui/button";
+
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuTrigger,
+} from "./ui/dropdown-menu";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "./ui/table";
+import { JobTitle } from "@/models/job.model";
+import { MoreHorizontal, Pencil } from "lucide-react";
+import { TablePagination } from "./TablePagination";
+
+type JobTitlesTableProps = {
+ jobTitles: JobTitle[];
+ currentPage: number;
+ totalPages: number;
+ totalJobTitles: number;
+ recordsPerPage: number;
+ onPageChange: (n: number) => void;
+};
+
+function JobTitlesTable({
+ jobTitles,
+ currentPage,
+ totalPages,
+ totalJobTitles,
+ recordsPerPage,
+ onPageChange,
+}: JobTitlesTableProps) {
+ const startPostIndex = (currentPage - 1) * recordsPerPage + 1;
+ const endPostIndex = Math.min(currentPage * recordsPerPage, totalJobTitles);
+
+ return (
+ <>
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Job Title</TableHead>
+ <TableHead>Value</TableHead>
+ <TableHead>Jobs Applied</TableHead>
+ <TableHead>Actions</TableHead>
+ <TableHead>
+ <span className="sr-only">Actions</span>
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {jobTitles.map((title: JobTitle) => {
+ return (
+ <TableRow key={title.id}>
+ <TableCell className="font-medium">{title.label}</TableCell>
+ <TableCell className="font-medium">{title.value}</TableCell>
+ <TableCell className="font-medium">
+ {title._count?.jobs}
+ </TableCell>
+ <TableCell>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button aria-haspopup="true" size="icon" variant="ghost">
+ <MoreHorizontal className="h-4 w-4" />
+ <span className="sr-only">Toggle menu</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
+ <DropdownMenuItem>Delete</DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </TableCell>
+ </TableRow>
+ );
+ })}
+ </TableBody>
+ </Table>
+ <div className="text-xs text-muted-foreground">
+ Showing{" "}
+ <strong>
+ {startPostIndex} to {endPostIndex}
+ </strong>{" "}
+ of
+ <strong> {totalJobTitles}</strong> companies
+ </div>
+ {totalJobTitles > recordsPerPage ? (
+ <TablePagination
+ currentPage={currentPage}
+ totalPages={totalPages}
+ onPageChange={onPageChange}
+ />
+ ) : null}
+ </>
+ );
+}
+
+export default JobTitlesTable;
diff --git a/src/components/JobsAppliedCard.tsx b/src/components/JobsAppliedCard.tsx
index 7fe9dfc..16c8f4b 100644
--- a/src/components/JobsAppliedCard.tsx
+++ b/src/components/JobsAppliedCard.tsx
@@ -7,9 +7,10 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
-import { redirect } from "next/navigation";
+import { useRouter } from "next/navigation";
export default function JobsAppliedCard() {
+ const router = useRouter();
return (
<Card className="sm:col-span-2">
<CardHeader className="pb-3">
@@ -19,7 +20,9 @@ export default function JobsAppliedCard() {
</CardDescription>
</CardHeader>
<CardFooter>
- <Button>Add New Job</Button>
+ <Button onClick={() => router.push("/dashboard/myjobs")}>
+ Add New Job
+ </Button>
</CardFooter>
</Card>
);
diff --git a/src/lib/db.ts b/src/lib/db.ts
index e5d7482..6293c3e 100644
--- a/src/lib/db.ts
+++ b/src/lib/db.ts
@@ -2,6 +2,9 @@ import { PrismaClient } from "@prisma/client";
const prismaClientSingleton = () => {
return new PrismaClient();
+ // {
+ // log: ["query"],
+ // }
};
declare const globalThis: {
diff --git a/src/models/job.model.ts b/src/models/job.model.ts
index 7cf4932..e87e33c 100644
--- a/src/models/job.model.ts
+++ b/src/models/job.model.ts
@@ -38,6 +38,9 @@ export interface JobTitle {
label: string;
value: string;
createdBy: string;
+ _count?: {
+ jobs: number;
+ };
}
export interface Company {