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
Refactor jobs container
Khuram Niaz262fdeb9b9c4
diff --git a/README.md b/README.mdindex c403366..aa57373 100644--- a/README.md+++ b/README.md@@ -34,3 +34,19 @@ You can check out [the Next.js GitHub repository](https://github.com/vercel/nextThe easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.+++Add/edit job solution++1. Move code from page.tsx (for myjobs page) and create new Myjobs (make it client component) component to hold both table and form+2. Fetch jobs data in page.tsx and pass to myjobs as props+3.+```typescript+const StateManager = ({ initialRecords }) => {+ const [records, setRecords] = useState(initialRecords);+ const addRecord = (newRecord) => { setRecords([...records, newRecord]); };+ return (+ <div> <Table records={records} /> <FormaddRecord={addRecord} /> </div>+ );+};+```diff --git a/src/app/dashboard/myjobs/page.tsx b/src/app/dashboard/myjobs/page.tsxindex f105b33..9f7af99 100644--- a/src/app/dashboard/myjobs/page.tsx+++ b/src/app/dashboard/myjobs/page.tsx@@ -1,25 +1,5 @@-import { File, ListFilter } from "lucide-react";--import { Button } from "@/components/ui/button";-import {- Card,- CardContent,- CardFooter,- CardHeader,- CardTitle,-} from "@/components/ui/card";-import {- DropdownMenu,- DropdownMenuCheckboxItem,- DropdownMenuContent,- DropdownMenuLabel,- DropdownMenuSeparator,- DropdownMenuTrigger,-} from "@/components/ui/dropdown-menu";import { Metadata } from "next";-import { AddJob } from "@/components/AddJob";-import MyJobsTable from "@/components/MyJobsTable";import {getCompanyList,getJobLocationList,@@ -27,6 +7,7 @@ import {getJobTitleList,getStatusList,} from "@/actions/job.actions";+import JobsContainer from "@/components/JobsContainer";export const metadata: Metadata = {title: "My Jobs | JobSync",@@ -42,52 +23,13 @@ async function MyJobs() {]);return (<div className="col-span-3">- <Card x-chunk="dashboard-06-chunk-0">- <CardHeader className="flex-row justify-between items-center">- <CardTitle>My Jobs</CardTitle>- <div className="flex items-center">- <div className="ml-auto flex items-center gap-2">- <DropdownMenu>- <DropdownMenuTrigger asChild>- <Button variant="outline" size="sm" className="h-8 gap-1">- <ListFilter className="h-3.5 w-3.5" />- <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">- Filter- </span>- </Button>- </DropdownMenuTrigger>- <DropdownMenuContent align="end">- <DropdownMenuLabel>Filter by</DropdownMenuLabel>- <DropdownMenuSeparator />- <DropdownMenuCheckboxItem checked>- Applied- </DropdownMenuCheckboxItem>- <DropdownMenuCheckboxItem>Draft</DropdownMenuCheckboxItem>- <DropdownMenuCheckboxItem>Interview</DropdownMenuCheckboxItem>- <DropdownMenuCheckboxItem>Archived</DropdownMenuCheckboxItem>- </DropdownMenuContent>- </DropdownMenu>- <Button size="sm" variant="outline" className="h-8 gap-1">- <File className="h-3.5 w-3.5" />- <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">- Export- </span>- </Button>- <AddJob- jobStatuses={statuses}- companies={companies}- jobTitles={titles}- locations={locations}- jobSources={sources}- />- </div>- </div>- </CardHeader>- <CardContent>- <MyJobsTable />- </CardContent>- <CardFooter></CardFooter>- </Card>+ <JobsContainer+ companies={companies}+ titles={titles}+ locations={locations}+ sources={sources}+ statuses={statuses}+ /></div>);}diff --git a/src/components/AddJob.tsx b/src/components/AddJob.tsxindex 61fca36..f806bd9 100644--- a/src/components/AddJob.tsx+++ b/src/components/AddJob.tsx@@ -35,13 +35,14 @@ import { DatePicker } from "./DatePicker";import { SALARY_RANGES } from "@/lib/data/salaryRangeData";import TiptapEditor from "./TiptapEditor";-interface AddJobProps {+type AddJobProps = {jobStatuses: { id: string; label: string; value: string }[];companies: any[];jobTitles: { id: string; label: string; value: string }[];locations: { id: string; label: string; value: string }[];jobSources: { id: string; label: string; value: string }[];-}+ onAddJob: () => void;+};export function AddJob({jobStatuses,@@ -49,6 +50,7 @@ export function AddJob({jobTitles,locations,jobSources,+ onAddJob,}: AddJobProps) {const [dialogOpen, setDialogOpen] = useState(false);const [isPending, startTransition] = useTransition();@@ -66,11 +68,11 @@ export function AddJob({});function onSubmit(data: z.infer<typeof AddJobFormSchema>) {- console.log("add job form data: ", data);startTransition(async () => {const res = await addJob(data);form.reset();setDialogOpen(false);+ onAddJob();});toast({description: "Job has been created successfully",diff --git a/src/components/JobsContainer.tsx b/src/components/JobsContainer.tsxnew file mode 100644index 0000000..4c27f06--- /dev/null+++ b/src/components/JobsContainer.tsx@@ -0,0 +1,129 @@+"use client";+import { useEffect, useState } from "react";+import {+ Card,+ CardContent,+ CardFooter,+ CardHeader,+ CardTitle,+} from "./ui/card";+import {+ DropdownMenu,+ DropdownMenuCheckboxItem,+ DropdownMenuContent,+ DropdownMenuLabel,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "./ui/dropdown-menu";+import { Button } from "./ui/button";+import { File, ListFilter } from "lucide-react";+import MyJobsTable from "./MyJobsTable";+import { AddJob } from "./AddJob";+import { deleteJobById, getJobsList } from "@/actions/job.actions";++type MyJobsProps = {+ statuses: { id: string; label: string; value: string }[];+ companies: any[];+ titles: { id: string; label: string; value: string }[];+ locations: { id: string; label: string; value: string }[];+ sources: { id: string; label: string; value: string }[];+};++function JobsContainer({+ statuses,+ companies,+ titles,+ locations,+ sources,+}: MyJobsProps) {+ const [jobs, setJobs] = useState<any[]>([]);+ const [currentPage, setCurrentPage] = useState(1);+ const [totalJobs, setTotalJobs] = useState(0);++ const jobsPerPage = 10;++ const totalPages = Math.ceil(totalJobs / jobsPerPage);++ const loadJobs = async (page: number) => {+ const { data, total } = await getJobsList(page, jobsPerPage);++ setJobs(data);+ setTotalJobs(total);+ };++ const reloadJobs = () => {+ loadJobs(1);+ };++ const onDeleteJob = async (jobId: string) => {+ const res = await deleteJobById(jobId);+ const updatedJobs = jobs.filter((job: any) => job.id !== res.id);+ setJobs(updatedJobs);+ };++ useEffect(() => {+ loadJobs(currentPage);+ }, [currentPage]);++ return (+ <>+ <Card x-chunk="dashboard-06-chunk-0">+ <CardHeader className="flex-row justify-between items-center">+ <CardTitle>My Jobs</CardTitle>+ <div className="flex items-center">+ <div className="ml-auto flex items-center gap-2">+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button variant="outline" size="sm" className="h-8 gap-1">+ <ListFilter className="h-3.5 w-3.5" />+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">+ Filter+ </span>+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuLabel>Filter by</DropdownMenuLabel>+ <DropdownMenuSeparator />+ <DropdownMenuCheckboxItem checked>+ Applied+ </DropdownMenuCheckboxItem>+ <DropdownMenuCheckboxItem>Draft</DropdownMenuCheckboxItem>+ <DropdownMenuCheckboxItem>Interview</DropdownMenuCheckboxItem>+ <DropdownMenuCheckboxItem>Archived</DropdownMenuCheckboxItem>+ </DropdownMenuContent>+ </DropdownMenu>+ <Button size="sm" variant="outline" className="h-8 gap-1">+ <File className="h-3.5 w-3.5" />+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">+ Export+ </span>+ </Button>+ <AddJob+ jobStatuses={statuses}+ companies={companies}+ jobTitles={titles}+ locations={locations}+ jobSources={sources}+ onAddJob={reloadJobs}+ />+ </div>+ </div>+ </CardHeader>+ <CardContent>+ <MyJobsTable+ jobs={jobs}+ currentPage={currentPage}+ totalPages={totalPages}+ jobsPerPage={jobsPerPage}+ totalJobs={totalJobs}+ onPageChange={setCurrentPage}+ deleteJob={onDeleteJob}+ />+ </CardContent>+ <CardFooter></CardFooter>+ </Card>+ </>+ );+}++export default JobsContainer;diff --git a/src/components/MyJobsTable.tsx b/src/components/MyJobsTable.tsxindex 626484d..576a3f8 100644--- a/src/components/MyJobsTable.tsx+++ b/src/components/MyJobsTable.tsx@@ -39,13 +39,30 @@ import {CommandItem,CommandList,} from "./ui/command";-import { useEffect, useState } from "react";+import { useState } from "react";import { TablePagination } from "./TablePagination";-import { deleteJobById, getJobsList } from "@/actions/job.actions";import { Dialog, DialogContent, DialogTrigger } from "./ui/dialog";import JobDetails from "./JobDetails";-function MyJobsTable() {+type MyJobsTableProps = {+ jobs: any[];+ currentPage: number;+ totalPages: number;+ totalJobs: number;+ jobsPerPage: number;+ onPageChange: (n: number) => void;+ deleteJob: (id: string) => void;+};++function MyJobsTable({+ jobs,+ currentPage,+ totalPages,+ totalJobs,+ jobsPerPage,+ onPageChange,+ deleteJob,+}: MyJobsTableProps) {const labels = ["draft","applied",@@ -60,21 +77,6 @@ function MyJobsTable() {const [dialogOpen, setDialogOpen] = useState(false);const [curJobId, setCurJobId] = useState("");- const [jobs, setJobs] = useState([]);- const [totalJobs, setTotalJobs] = useState(0);- const [currentPage, setCurrentPage] = useState(1);- const jobsPerPage = 10;-- useEffect(() => {- const loadJobs = async () => {- const { data, total } = await getJobsList(currentPage, jobsPerPage);-- setJobs(data);- setTotalJobs(total);- };- loadJobs();- }, [currentPage]);- const totalPages = Math.ceil(totalJobs / jobsPerPage);const startPostIndex = (currentPage - 1) * jobsPerPage + 1;const endPostIndex = Math.min(currentPage * jobsPerPage, totalJobs);@@ -83,12 +85,6 @@ function MyJobsTable() {setDialogOpen(true);};- const deleteJob = async (jobId: string) => {- const res = await deleteJobById(jobId);- const updatedJobs = jobs.filter((job: any) => job.id !== res.id);- setJobs(updatedJobs);- };-return (<><Table>@@ -243,7 +239,7 @@ function MyJobsTable() {<TablePaginationcurrentPage={currentPage}totalPages={totalPages}- onPageChange={setCurrentPage}+ onPageChange={onPageChange}/></>);