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 create resume test and delete resume

Khuram Niaz18898b701913
diff --git a/e2e/profile.spec.ts b/e2e/profile.spec.ts
new file mode 100644
index 0000000..b46e7d2
--- /dev/null
+++ b/e2e/profile.spec.ts
@@ -0,0 +1,31 @@
+import { test, expect } from "@playwright/test";
+
+test.beforeEach(async ({ page }) => {
+ await page.goto("localhost:3000");
+ await page.getByPlaceholder("[email protected]").click();
+ await page.getByPlaceholder("[email protected]").fill("[email protected]");
+ await page.getByLabel("Password").click();
+ await page.getByLabel("Password").fill("password123");
+ await page.getByRole("button", { name: "Login" }).click();
+
+ await expect(page).toHaveURL("http://localhost:3000/dashboard");
+});
+
+test.describe("Profile page", () => {
+ test("should create a new resume", async ({ page }) => {
+ await page.getByRole("link", { name: "Profile" }).click();
+
+ await page.getByRole("button", { name: "Create Resume" }).click();
+ await page
+ .getByPlaceholder("Ex: Full Stack Developer")
+ .fill("Test Resume 1");
+ await page.getByRole("button", { name: "Save" }).click();
+ await expect(page.getByRole("status")).toHaveText(
+ /Resume title has been created/
+ );
+ await expect(page.locator("tbody")).toContainText("Test Resume 1");
+ });
+
+ test("should edit the resume title", async ({ page }) => {});
+ test("should delete a resume", async ({ page }) => {});
+});
diff --git a/src/actions/profile.actions.ts b/src/actions/profile.actions.ts
index b23844c..e308de9 100644
--- a/src/actions/profile.actions.ts
+++ b/src/actions/profile.actions.ts
@@ -239,6 +239,66 @@ export const editResume = async (
}
};
+export const deleteResumeById = async (
+ resumeId: string
+): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ // TODO: Check if resume is associated with any job
+
+ await prisma.$transaction(async (prisma) => {
+ await prisma.contactInfo.delete({
+ where: {
+ resumeId: resumeId,
+ },
+ });
+
+ await prisma.summary.deleteMany({
+ where: {
+ ResumeSection: {
+ resumeId: resumeId,
+ },
+ },
+ });
+
+ await prisma.workExperience.deleteMany({
+ where: {
+ ResumeSection: {
+ resumeId: resumeId,
+ },
+ },
+ });
+
+ await prisma.education.deleteMany({
+ where: {
+ ResumeSection: {
+ resumeId: resumeId,
+ },
+ },
+ });
+
+ await prisma.resumeSection.deleteMany({
+ where: {
+ resumeId: resumeId,
+ },
+ });
+
+ await prisma.resume.delete({
+ where: { id: resumeId },
+ });
+ });
+ return { success: true };
+ } catch (error) {
+ const msg = "Failed to delete resume.";
+ return handleError(error, msg);
+ }
+};
+
export const addResumeSummary = async (
data: z.infer<typeof AddSummarySectionFormSchema>
): Promise<any | undefined> => {
diff --git a/src/components/profile/ProfileContainer.tsx b/src/components/profile/ProfileContainer.tsx
index 9bf583e..8c278d1 100644
--- a/src/components/profile/ProfileContainer.tsx
+++ b/src/components/profile/ProfileContainer.tsx
@@ -78,6 +78,7 @@ function ActivitiesContainer() {
totalResumes={totalResumes}
// onPageChange={onPageChange}
editResume={onEditResume}
+ reloadResumes={reloadResumes}
/>
) : (
<Loading />
diff --git a/src/components/profile/ResumeTable.tsx b/src/components/profile/ResumeTable.tsx
index 1feb2a3..8ee5a71 100644
--- a/src/components/profile/ResumeTable.tsx
+++ b/src/components/profile/ResumeTable.tsx
@@ -18,7 +18,20 @@ import {
import { Resume } from "@/models/profile.model";
import { format } from "date-fns";
import Link from "next/link";
-import { Button } from "../ui/button";
+import { Button, buttonVariants } from "../ui/button";
+import { useMemo, useState } from "react";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "../ui/alert-dialog";
+import { toast } from "../ui/use-toast";
+import { deleteResumeById } from "@/actions/profile.actions";
type ResumeTableProps = {
resumes: Resume[];
@@ -28,6 +41,7 @@ type ResumeTableProps = {
recordsPerPage: number;
// onPageChange: (n: number) => void;
editResume: (resume: Resume) => void;
+ reloadResumes: () => void;
};
function ResumeTable({
@@ -37,71 +51,127 @@ function ResumeTable({
totalResumes,
recordsPerPage,
editResume,
+ reloadResumes,
}: // onPageChange,
ResumeTableProps) {
+ const [alertOpen, setAlertOpen] = useState(false);
+ const [resumeIdToDelete, setResumeIdToDelete] = useState<string>();
+ const onDeleteResume = useMemo(
+ () => (resumeId: string | undefined) => {
+ if (!resumeId) return;
+ setAlertOpen(true);
+ setResumeIdToDelete(resumeId);
+ },
+ []
+ );
+
+ const deleteResume = async (resumeId: string | undefined) => {
+ if (!resumeId) return;
+ const { success, message } = await deleteResumeById(resumeId);
+ if (success) {
+ toast({
+ variant: "success",
+ description: `Resume has been deleted successfully`,
+ });
+ reloadResumes();
+ } else {
+ toast({
+ variant: "destructive",
+ title: "Error!",
+ description: message,
+ });
+ }
+ };
return (
- <Table>
- <TableHeader>
- <TableRow>
- <TableHead>Resume Title</TableHead>
- <TableHead>Created</TableHead>
- <TableHead className="hidden md:table-cell">Updated</TableHead>
- <TableHead>Actions</TableHead>
- <TableHead>
- <span className="sr-only">Actions</span>
- </TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {resumes.map((resume: Resume) => {
- return (
- <TableRow key={resume.id}>
- <TableCell className="font-medium">
- <Link href={`/dashboard/profile/resume/${resume.id}`}>
- {resume.title}
- </Link>
- </TableCell>
- <TableCell>
- {resume.createdAt && format(resume.createdAt, "PP")}
- </TableCell>
- <TableCell className="hidden md:table-cell">
- {resume.updatedAt && format(resume.updatedAt, "PP")}
- </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
- className="cursor-pointer"
- onClick={() => editResume(resume)}
- >
- <Pencil className="mr-2 h-4 w-4" />
- Edit Resume Title
- </DropdownMenuItem>
- <Link href={`/dashboard/profile/resume/${resume.id}`}>
- <DropdownMenuItem className="cursor-pointer">
- <FilePenLine className="mr-2 h-4 w-4" />
- View/Edit Resume
+ <>
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Resume Title</TableHead>
+ <TableHead>Created</TableHead>
+ <TableHead className="hidden md:table-cell">Updated</TableHead>
+ <TableHead>Actions</TableHead>
+ <TableHead>
+ <span className="sr-only">Actions</span>
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {resumes.map((resume: Resume) => {
+ return (
+ <TableRow key={resume.id}>
+ <TableCell className="font-medium">
+ <Link href={`/dashboard/profile/resume/${resume.id}`}>
+ {resume.title}
+ </Link>
+ </TableCell>
+ <TableCell>
+ {resume.createdAt && format(resume.createdAt, "PP")}
+ </TableCell>
+ <TableCell className="hidden md:table-cell">
+ {resume.updatedAt && format(resume.updatedAt, "PP")}
+ </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
+ className="cursor-pointer"
+ onClick={() => editResume(resume)}
+ >
+ <Pencil className="mr-2 h-4 w-4" />
+ Edit Resume Title
+ </DropdownMenuItem>
+ <Link href={`/dashboard/profile/resume/${resume.id}`}>
+ <DropdownMenuItem className="cursor-pointer">
+ <FilePenLine className="mr-2 h-4 w-4" />
+ View/Edit Resume
+ </DropdownMenuItem>
+ </Link>
+ <DropdownMenuItem
+ className="text-red-600 cursor-pointer"
+ onClick={() => onDeleteResume(resume.id)}
+ >
+ <Trash className="mr-2 h-4 w-4" />
+ Delete
</DropdownMenuItem>
- </Link>
- <DropdownMenuItem className="text-red-600 cursor-pointer">
- <Trash className="mr-2 h-4 w-4" />
- Delete
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </TableCell>
- </TableRow>
- );
- })}
- </TableBody>
- </Table>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </TableCell>
+ </TableRow>
+ );
+ })}
+ </TableBody>
+ </Table>
+ <AlertDialog open={alertOpen} onOpenChange={setAlertOpen}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>
+ Are you sure you want to delete this resume?
+ </AlertDialogTitle>
+ <AlertDialogDescription>
+ This action cannot be undone. This will permanently delete and
+ remove data from server.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ className={buttonVariants({ variant: "destructive" })}
+ onClick={() => deleteResume(resumeIdToDelete)}
+ >
+ Delete
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </>
);
}