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
Edit Job
Khuram Niazcb0094e21a66
diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.tsindex 7113e61..b5ad7b1 100644--- a/src/actions/job.actions.ts+++ b/src/actions/job.actions.ts@@ -264,6 +264,61 @@ export const addJob = async (}};+export const updateJob = async (+ data: z.infer<typeof AddJobFormSchema>+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();++ if (!user) {+ throw new Error("Not authenticated");+ }+ if (!data.id || user.id != data.userId) {+ console.log({ data, user });+ throw new Error("Id is not provide or no user privilages");+ }++ const {+ id,+ title,+ company,+ location,+ type,+ status,+ source,+ salaryRange,+ dueDate,+ dateApplied,+ jobDescription,+ } = data;++ const job = await prisma.job.update({+ where: {+ id,+ },+ data: {+ jobTitleId: title,+ companyId: company,+ locationId: location,+ statusId: status,+ jobSourceId: source,+ salaryRange: salaryRange,+ createdAt: new Date(),+ dueDate: dueDate,+ appliedDate: dateApplied,+ description: jobDescription,+ jobType: type,+ },+ });++ return job;+ } catch (error) {+ const msg = "Failed to update job. ";+ console.error(msg, error);+ throw new Error(msg);+ }+};+export const deleteJobById = async (jobId: string): Promise<any | undefined> => {diff --git a/src/components/AddJob.tsx b/src/components/AddJob.tsxindex f806bd9..3310a54 100644--- a/src/components/AddJob.tsx+++ b/src/components/AddJob.tsx@@ -6,14 +6,13 @@ import {DialogHeader,DialogOverlay,DialogTitle,- DialogTrigger,DialogFooter,} from "@/components/ui/dialog";-import { addJob } from "@/actions/job.actions";+import { addJob, updateJob } from "@/actions/job.actions";import { Loader, PlusCircle } from "lucide-react";import { Button } from "./ui/button";import { useForm } from "react-hook-form";-import { useState, useTransition } from "react";+import { useEffect, useState, useTransition } from "react";import { AddJobFormSchema } from "@/models/addJobForm.schema";import { zodResolver } from "@hookform/resolvers/zod";import { JOB_TYPES } from "@/models/job.model";@@ -41,7 +40,9 @@ type AddJobProps = {jobTitles: { id: string; label: string; value: string }[];locations: { id: string; label: string; value: string }[];jobSources: { id: string; label: string; value: string }[];- onAddJob: () => void;+ reloadJobs: () => void;+ editJob?: any;+ resetEditJob: () => void;};export function AddJob({@@ -50,7 +51,9 @@ export function AddJob({jobTitles,locations,jobSources,- onAddJob,+ reloadJobs,+ editJob,+ resetEditJob,}: AddJobProps) {const [dialogOpen, setDialogOpen] = useState(false);const [isPending, startTransition] = useTransition();@@ -67,33 +70,62 @@ export function AddJob({},});+ const { setValue, reset } = form;++ useEffect(() => {+ if (editJob) {+ setValue("id", editJob.id);+ setValue("userId", editJob.userId);+ setValue("title", editJob.JobTitle.id);+ setValue("company", editJob.Company.id);+ setValue("location", editJob.Location.id);+ setValue("type", editJob.jobType);+ setValue("source", editJob.JobSource.id);+ setValue("status", editJob.Status.id);+ setValue("dueDate", editJob.dueDate);+ setValue("dateApplied", editJob.appliedDate);+ setValue("salaryRange", editJob.salaryRange);+ setValue("jobDescription", editJob.description);+ setDialogOpen(true);+ }+ }, [editJob, setValue]);+function onSubmit(data: z.infer<typeof AddJobFormSchema>) {startTransition(async () => {- const res = await addJob(data);- form.reset();+ const res = editJob ? await updateJob(data) : await addJob(data);+ reset();setDialogOpen(false);- onAddJob();+ reloadJobs();});toast({- description: "Job has been created successfully",+ description: `Job has been ${+ editJob ? "updated" : "created"+ } successfully`,});}+ const pageTitle = editJob ? "Edit Job" : "Add Job";++ const addJobForm = () => {+ reset();+ resetEditJob();+ setDialogOpen(true);+ };+return (<>+ <Button size="sm" className="h-8 gap-1" onClick={addJobForm}>+ <PlusCircle className="h-3.5 w-3.5" />+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">+ Add Job+ </span>+ </Button><Dialog open={dialogOpen} onOpenChange={setDialogOpen}>- <DialogTrigger asChild>- <Button size="sm" className="h-8 gap-1">- <PlusCircle className="h-3.5 w-3.5" />- <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">- Add Job- </span>- </Button>- </DialogTrigger>+ {/* <DialogTrigger asChild></DialogTrigger> */}<DialogOverlay><DialogContent className="lg:max-w-screen-lg lg:max-h-screen overflow-y-scroll"><DialogHeader>- <DialogTitle>Add Job</DialogTitle>+ <DialogTitle>{pageTitle}</DialogTitle></DialogHeader><Form {...form}><formdiff --git a/src/components/JobsContainer.tsx b/src/components/JobsContainer.tsxindex 4c27f06..1b3e7cb 100644--- a/src/components/JobsContainer.tsx+++ b/src/components/JobsContainer.tsx@@ -19,7 +19,11 @@ 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";+import {+ deleteJobById,+ getJobDetails,+ getJobsList,+} from "@/actions/job.actions";type MyJobsProps = {statuses: { id: string; label: string; value: string }[];@@ -39,6 +43,7 @@ function JobsContainer({const [jobs, setJobs] = useState<any[]>([]);const [currentPage, setCurrentPage] = useState(1);const [totalJobs, setTotalJobs] = useState(0);+ const [editJob, setEditJob] = useState(null);const jobsPerPage = 10;@@ -56,9 +61,17 @@ function JobsContainer({};const onDeleteJob = async (jobId: string) => {- const res = await deleteJobById(jobId);- const updatedJobs = jobs.filter((job: any) => job.id !== res.id);- setJobs(updatedJobs);+ await deleteJobById(jobId);+ reloadJobs();+ };++ const onEditJob = async (jobId: string) => {+ const job = await getJobDetails(jobId);+ setEditJob(job);+ };++ const resetEditJob = () => {+ setEditJob(null);};useEffect(() => {@@ -104,7 +117,9 @@ function JobsContainer({jobTitles={titles}locations={locations}jobSources={sources}- onAddJob={reloadJobs}+ reloadJobs={reloadJobs}+ editJob={editJob}+ resetEditJob={resetEditJob}/></div></div>@@ -118,6 +133,7 @@ function JobsContainer({totalJobs={totalJobs}onPageChange={setCurrentPage}deleteJob={onDeleteJob}+ editJob={onEditJob}/></CardContent><CardFooter></CardFooter>diff --git a/src/components/MyJobsTable.tsx b/src/components/MyJobsTable.tsxindex 576a3f8..94ec884 100644--- a/src/components/MyJobsTable.tsx+++ b/src/components/MyJobsTable.tsx@@ -52,6 +52,7 @@ type MyJobsTableProps = {jobsPerPage: number;onPageChange: (n: number) => void;deleteJob: (id: string) => void;+ editJob: (id: string) => void;};function MyJobsTable({@@ -62,6 +63,7 @@ function MyJobsTable({jobsPerPage,onPageChange,deleteJob,+ editJob,}: MyJobsTableProps) {const labels = ["draft",@@ -169,9 +171,9 @@ function MyJobsTable({<ListCollapse className="mr-2 h-4 w-4" />View Details</DropdownMenuItem>- <DropdownMenuItem>+ <DropdownMenuItem onClick={() => editJob(job.id)}><Pencil className="mr-2 h-4 w-4" />- Edit+ Edit Job</DropdownMenuItem><DropdownMenuSeparator /><DropdownMenuSub>diff --git a/src/models/addJobForm.schema.ts b/src/models/addJobForm.schema.tsindex 67475d9..e077156 100644--- a/src/models/addJobForm.schema.ts+++ b/src/models/addJobForm.schema.ts@@ -1,6 +1,8 @@import { z } from "zod";export const AddJobFormSchema = z.object({+ id: z.string().optional(),+ userId: z.string().optional(),title: z.string({required_error: "Job title is required.",