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.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
Add locations table
Khuram Niaz8c39ad37fd47
diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.tsindex bdfac2c..38ea826 100644--- a/src/actions/job.actions.ts+++ b/src/actions/job.actions.ts@@ -26,17 +26,6 @@ export const getJobSourceList = async (): Promise<any | undefined> => {}};-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);- }-};-export const getJobsList = async (page = 1,limit = 10,diff --git a/src/actions/jobLocation.actions.ts b/src/actions/jobLocation.actions.tsnew file mode 100644index 0000000..9fc00dd--- /dev/null+++ b/src/actions/jobLocation.actions.ts@@ -0,0 +1,74 @@+"use server";+import prisma from "@/lib/db";+import { getCurrentUser } from "@/utils/user.utils";++export const getAllJobLocations = 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);+ }+};++export const getJobLocationsList = 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.location.findMany({+ where: {+ createdBy: user.id,+ },+ skip,+ take: limit,+ ...(countBy+ ? {+ select: {+ id: true,+ label: true,+ value: true,+ _count: {+ select: {+ jobsApplied: {+ where: {+ Status: {+ value: countBy,+ },+ },+ },+ },+ },+ },+ }+ : {}),+ orderBy: {+ jobsApplied: {+ _count: "desc",+ },+ },+ }),+ prisma.location.count({+ where: {+ createdBy: user.id,+ },+ }),+ ]);+ return { data, total };+ } catch (error) {+ const msg = "Failed to fetch job location list. ";+ console.error(msg, error);+ throw new Error(msg);+ }+};diff --git a/src/app/dashboard/admin/page.tsx b/src/app/dashboard/admin/page.tsxindex 919e0ba..be7eae2 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 JobLocationsContainer from "@/components/JobLocationsContainer";import JobTitlesContainer from "@/components/JobTitlesContainer";import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";@@ -20,7 +21,9 @@ async function AdminPage() {<TabsContent value="titles"><JobTitlesContainer /></TabsContent>- <TabsContent value="locations">location table here</TabsContent>+ <TabsContent value="locations">+ <JobLocationsContainer />+ </TabsContent></Tabs></div>);diff --git a/src/app/dashboard/myjobs/page.tsx b/src/app/dashboard/myjobs/page.tsxindex 90a80f0..a7e526e 100644--- a/src/app/dashboard/myjobs/page.tsx+++ b/src/app/dashboard/myjobs/page.tsx@@ -1,13 +1,10 @@import { Metadata } from "next";-import {- getJobLocationList,- getJobSourceList,- getStatusList,-} from "@/actions/job.actions";+import { getJobSourceList, getStatusList } from "@/actions/job.actions";import JobsContainer from "@/components/JobsContainer";import { getAllCompanies } from "@/actions/company.actions";import { getAllJobTitles } from "@/actions/jobtitle.actions";+import { getAllJobLocations } from "@/actions/jobLocation.actions";export const metadata: Metadata = {title: "My Jobs | JobSync",@@ -18,7 +15,7 @@ async function MyJobs() {getStatusList(),getAllCompanies(),getAllJobTitles(),- getJobLocationList(),+ getAllJobLocations(),getJobSourceList(),]);return (diff --git a/src/components/JobLocationsContainer.tsx b/src/components/JobLocationsContainer.tsxnew file mode 100644index 0000000..f6d8131--- /dev/null+++ b/src/components/JobLocationsContainer.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 JobLocationsTable from "./JobLocationsTable";+import { getJobLocationsList } from "@/actions/jobLocation.actions";++function JobLocationsContainer() {+ const [Locations, setLocations] = useState<JobTitle[]>([]);+ const [totalJobLocations, setTotalJobLocations] = useState(0);+ const [currentPage, setCurrentPage] = useState(1);+ const [editJobLocation, setEditJobLocation] = useState(null);++ const recordsPerPage = APP_CONSTANTS.RECORDS_PER_PAGE;++ const totalPages = Math.ceil(totalJobLocations / recordsPerPage);++ const loadJobLocations = useCallback(+ async (page: number) => {+ const { data, total } = await getJobLocationsList(+ page,+ recordsPerPage,+ "applied"+ );+ setLocations(data);+ setTotalJobLocations(total);+ },+ [recordsPerPage]+ );++ const reloadJobLocations = () => {+ loadJobLocations(1);+ };++ const resetEditJobLocation = () => {+ setEditJobLocation(null);+ };++ useEffect(() => {+ loadJobLocations(currentPage);+ }, [currentPage, loadJobLocations]);++ return (+ <>+ <div className="col-span-3">+ <Card x-chunk="dashboard-06-chunk-0">+ <CardHeader className="flex-row justify-between items-center">+ <CardTitle>Job Locations</CardTitle>+ <div className="flex items-center">+ <div className="ml-auto flex items-center gap-2">+ {/* <AddCompany reloadCompanies={reloadJobLocations} /> */}+ </div>+ </div>+ </CardHeader>+ <CardContent>+ <JobLocationsTable+ jobLocations={Locations}+ currentPage={currentPage}+ totalPages={totalPages}+ recordsPerPage={recordsPerPage}+ totalJobLocations={totalJobLocations}+ onPageChange={setCurrentPage}+ />+ </CardContent>+ </Card>+ </div>+ </>+ );+}++export default JobLocationsContainer;diff --git a/src/components/JobLocationsTable.tsx b/src/components/JobLocationsTable.tsxnew file mode 100644index 0000000..0295810--- /dev/null+++ b/src/components/JobLocationsTable.tsx@@ -0,0 +1,107 @@+"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 { JobLocation, JobTitle } from "@/models/job.model";+import { MoreHorizontal, Pencil } from "lucide-react";+import { TablePagination } from "./TablePagination";++type JobLocationsTableProps = {+ jobLocations: JobLocation[];+ currentPage: number;+ totalPages: number;+ totalJobLocations: number;+ recordsPerPage: number;+ onPageChange: (n: number) => void;+};++function JobLocationsTable({+ jobLocations,+ currentPage,+ totalPages,+ totalJobLocations,+ recordsPerPage,+ onPageChange,+}: JobLocationsTableProps) {+ const startPostIndex = (currentPage - 1) * recordsPerPage + 1;+ const endPostIndex = Math.min(+ currentPage * recordsPerPage,+ totalJobLocations+ );++ return (+ <>+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead>Location</TableHead>+ <TableHead>Value</TableHead>+ <TableHead>Jobs Applied</TableHead>+ <TableHead>Actions</TableHead>+ <TableHead>+ <span className="sr-only">Actions</span>+ </TableHead>+ </TableRow>+ </TableHeader>+ <TableBody>+ {jobLocations.map((location: JobLocation) => {+ return (+ <TableRow key={location.id}>+ <TableCell className="font-medium">{location.label}</TableCell>+ <TableCell className="font-medium">{location.value}</TableCell>+ <TableCell className="font-medium">+ {location._count?.jobsApplied}+ </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> {totalJobLocations}</strong> locations+ </div>+ {totalJobLocations > recordsPerPage ? (+ <TablePagination+ currentPage={currentPage}+ totalPages={totalPages}+ onPageChange={onPageChange}+ />+ ) : null}+ </>+ );+}++export default JobLocationsTable;diff --git a/src/components/JobTitlesTable.tsx b/src/components/JobTitlesTable.tsxindex 9e74b17..712b761 100644--- a/src/components/JobTitlesTable.tsx+++ b/src/components/JobTitlesTable.tsx@@ -88,7 +88,7 @@ function JobTitlesTable({{startPostIndex} to {endPostIndex}</strong>{" "}of- <strong> {totalJobTitles}</strong> companies+ <strong> {totalJobTitles}</strong> titles</div>{totalJobTitles > recordsPerPage ? (<TablePaginationdiff --git a/src/models/job.model.ts b/src/models/job.model.tsindex e87e33c..21a2280 100644--- a/src/models/job.model.ts+++ b/src/models/job.model.ts@@ -73,6 +73,9 @@ export interface JobLocation {stateProv?: string;country?: string;createdBy: string;+ _count?: {+ jobsApplied: number;+ };}export interface Country {