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.

Delete job

Khuram Niaza79b3a1f1993
diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.ts
index 16471b2..7113e61 100644
--- a/src/actions/job.actions.ts
+++ b/src/actions/job.actions.ts
@@ -89,7 +89,7 @@ export const getJobsList = async (
description: false,
},
orderBy: {
- createdAt: "desc",
+ appliedDate: "desc",
},
}),
prisma.job.count({
@@ -263,3 +263,27 @@ export const addJob = async (
throw new Error(msg);
}
};
+
+export const deleteJobById = async (
+ jobId: string
+): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ const res = prisma.job.delete({
+ where: {
+ id: jobId,
+ userId: user.id,
+ },
+ });
+ return res;
+ } catch (error) {
+ const msg = "Failed to delete job.";
+ console.error(msg, error);
+ throw new Error(msg);
+ }
+};
diff --git a/src/components/MyJobsTable.tsx b/src/components/MyJobsTable.tsx
index 425133a..626484d 100644
--- a/src/components/MyJobsTable.tsx
+++ b/src/components/MyJobsTable.tsx
@@ -41,7 +41,7 @@ import {
} from "./ui/command";
import { useEffect, useState } from "react";
import { TablePagination } from "./TablePagination";
-import { getJobsList } from "@/actions/job.actions";
+import { deleteJobById, getJobsList } from "@/actions/job.actions";
import { Dialog, DialogContent, DialogTrigger } from "./ui/dialog";
import JobDetails from "./JobDetails";
@@ -83,6 +83,12 @@ 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>
@@ -108,7 +114,7 @@ function MyJobsTable() {
<TableRow
key={job.id}
className="cursor-pointer"
- onClick={() => viewJobDetails(job?.id)}
+ // onClick={() => viewJobDetails(job?.id)}
>
<TableCell className="hidden sm:table-cell">
<Image
@@ -204,7 +210,10 @@ function MyJobsTable() {
</DropdownMenuSubContent>
</DropdownMenuSub>
<DropdownMenuSeparator />
- <DropdownMenuItem className="text-red-600">
+ <DropdownMenuItem
+ className="text-red-600 cursor-pointer"
+ onClick={() => deleteJob(job.id)}
+ >
<Trash className="mr-2 h-4 w-4" />
Delete
</DropdownMenuItem>
@@ -224,10 +233,10 @@ function MyJobsTable() {
</DialogContent>
</Dialog>
<div className="text-xs text-muted-foreground">
- Showing
+ Showing{" "}
<strong>
{startPostIndex} to {endPostIndex}
- </strong>
+ </strong>{" "}
of
<strong> {totalJobs}</strong> jobs
</div>
diff --git a/src/components/RecentJobsCard.tsx b/src/components/RecentJobsCard.tsx
index ebd5e3f..2ad5212 100644
--- a/src/components/RecentJobsCard.tsx
+++ b/src/components/RecentJobsCard.tsx
@@ -24,7 +24,7 @@ export default function RecentJobsCard({ jobs }: { jobs: any[] }) {
</p>
</div>
<div className="ml-auto font-medium">
- {format(job.appliedDate, "PP")}
+ {format(job?.appliedDate, "PP")}
</div>
</div>
))}