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.

Edit resume title, reset edit form

Khuram Niaz25e7f3fcfbe7
diff --git a/src/actions/profile.actions.ts b/src/actions/profile.actions.ts
index 6aec6a0..6dd9fec 100644
--- a/src/actions/profile.actions.ts
+++ b/src/actions/profile.actions.ts
@@ -205,51 +205,33 @@ export const createResumeProfile = async (
}
};
-// export const editResumeTitle = async (
-// data: z.infer<typeof CreateResumeFormSchema>
-// ): Promise<any | undefined> => {
-// try {
-// const user = await getCurrentUser();
-
-// if (!user) {
-// throw new Error("Not authenticated");
-// }
-
-// const { id, company, logoUrl, createdBy } = data;
-
-// if (!id || user.id != createdBy) {
-// throw new Error("Id is not provided or no user privilages");
-// }
-
-// const value = company.trim().toLowerCase();
-
-// const companyExists = await prisma.company.findUnique({
-// where: {
-// value,
-// },
-// });
-
-// if (companyExists) {
-// throw new Error("Company already exists!");
-// }
-
-// const res = await prisma.company.update({
-// where: {
-// id,
-// },
-// data: {
-// value,
-// label: company,
-// logoUrl,
-// },
-// });
-
-// return { success: true, data: res };
-// } catch (error) {
-// const msg = "Failed to update company.";
-// console.error(msg, error);
-// if (error instanceof Error) {
-// return { success: false, message: error.message };
-// }
-// }
-// };
+export const editResume = async (
+ data: z.infer<typeof CreateResumeFormSchema>
+): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
+ const { id, title } = data;
+
+ const res = await prisma.resume.update({
+ where: {
+ id,
+ },
+ data: {
+ title,
+ },
+ });
+
+ return { success: true, data: res };
+ } catch (error) {
+ const msg = "Failed to update resume.";
+ console.error(msg, error);
+ if (error instanceof Error) {
+ return { success: false, message: error.message };
+ }
+ }
+};
diff --git a/src/components/AddCompany.tsx b/src/components/AddCompany.tsx
index b352c44..99abb0a 100644
--- a/src/components/AddCompany.tsx
+++ b/src/components/AddCompany.tsx
@@ -48,10 +48,11 @@ function AddCompany({
resolver: zodResolver(AddCompanyFormSchema),
});
- const { setValue, reset, formState } = form;
+ const { setValue, reset, formState, clearErrors } = form;
useEffect(() => {
if (editCompany) {
+ clearErrors();
setValue("id", editCompany.id);
setValue("company", editCompany.label);
setValue("createdBy", editCompany.createdBy);
@@ -61,7 +62,7 @@ function AddCompany({
setDialogOpen(true);
}
- }, [editCompany, setValue]);
+ }, [editCompany, setValue, clearErrors]);
const addCompanyForm = () => {
reset();
diff --git a/src/components/AddContactInfo.tsx b/src/components/AddContactInfo.tsx
index e5e4716..a95dea2 100644
--- a/src/components/AddContactInfo.tsx
+++ b/src/components/AddContactInfo.tsx
@@ -53,10 +53,11 @@ function AddContactInfo({
},
});
- const { setValue, reset, formState } = form;
+ const { setValue, reset, formState, clearErrors } = form;
useEffect(() => {
if (contactInfoToEdit) {
+ clearErrors();
setValue("id", contactInfoToEdit.id);
setValue("resumeId", contactInfoToEdit.resumeId);
setValue("firstName", contactInfoToEdit.firstName);
@@ -65,8 +66,10 @@ function AddContactInfo({
setValue("email", contactInfoToEdit.email);
setValue("phone", contactInfoToEdit.phone);
setValue("address", contactInfoToEdit.address);
+ } else {
+ reset();
}
- }, [contactInfoToEdit, setValue]);
+ }, [contactInfoToEdit, setValue, clearErrors, reset, dialogOpen]);
const onSubmit = (data: z.infer<typeof AddContactInfoFormSchema>) => {
startTransition(async () => {
@@ -82,7 +85,6 @@ function AddContactInfo({
} else {
reset();
setDialogOpen(false);
- // reloadCompanies();
toast({
variant: "success",
description: `Contact Info has been ${
diff --git a/src/components/AddJob.tsx b/src/components/AddJob.tsx
index fd9158c..7fc3800 100644
--- a/src/components/AddJob.tsx
+++ b/src/components/AddJob.tsx
@@ -77,12 +77,13 @@ export function AddJob({
},
});
- const { setValue, reset, watch, resetField } = form;
+ const { setValue, reset, watch, resetField, clearErrors } = form;
const appliedValue = watch("applied");
useEffect(() => {
if (editJob) {
+ clearErrors();
setValue("id", editJob.id);
setValue("userId", editJob.userId);
setValue("title", editJob.JobTitle.id);
@@ -103,7 +104,7 @@ export function AddJob({
}
setDialogOpen(true);
}
- }, [editJob, setValue]);
+ }, [editJob, setValue, clearErrors]);
function onSubmit(data: z.infer<typeof AddJobFormSchema>) {
startTransition(async () => {
diff --git a/src/components/AddResumeSection.tsx b/src/components/AddResumeSection.tsx
index c513e09..11f4f17 100644
--- a/src/components/AddResumeSection.tsx
+++ b/src/components/AddResumeSection.tsx
@@ -10,22 +10,25 @@ import {
} from "./ui/dropdown-menu";
import AddContactInfo from "./AddContactInfo";
import { forwardRef, useImperativeHandle, useState } from "react";
-import { Resume } from "@/models/profile.model";
+import { ContactInfo, Resume } from "@/models/profile.model";
interface AddResumeSectionProps {
resume: Resume;
}
export interface AddResumeSectionRef {
- openDialog: () => void;
+ openDialog: (c: ContactInfo) => void;
}
const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
({ resume }, ref) => {
const [contactInfoDialogOpen, setContactInfoDialogOpen] = useState(false);
+ const [contactInfoToEdit, setContactInfoToEdit] =
+ useState<ContactInfo | null>(null);
useImperativeHandle(ref, () => ({
- openDialog() {
+ openDialog(contactInfo: ContactInfo) {
setContactInfoDialogOpen(true);
+ setContactInfoToEdit({ ...contactInfo });
},
}));
return (
@@ -58,7 +61,7 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
dialogOpen={contactInfoDialogOpen}
setDialogOpen={setContactInfoDialogOpen}
resumeId={resume.id}
- contactInfoToEdit={resume.ContactInfo}
+ contactInfoToEdit={contactInfoToEdit}
/>
</>
);
diff --git a/src/components/ContactInfoCard.tsx b/src/components/ContactInfoCard.tsx
index 7ac12e8..572526d 100644
--- a/src/components/ContactInfoCard.tsx
+++ b/src/components/ContactInfoCard.tsx
@@ -10,7 +10,6 @@ interface ContactInfoCardProps {
}
function ContactInfoCard({ contactInfo, openDialog }: ContactInfoCardProps) {
- const editContactInfo = () => {};
return (
<Card>
<CardHeader className="flex-row justify-between relative">
diff --git a/src/components/CreateResume.tsx b/src/components/CreateResume.tsx
index ef8c587..be5b10a 100644
--- a/src/components/CreateResume.tsx
+++ b/src/components/CreateResume.tsx
@@ -5,7 +5,7 @@ import { useForm } from "react-hook-form";
import { CreateResumeFormSchema } from "@/models/createResumeForm.schema";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
-import { useState, useTransition } from "react";
+import { useEffect, useState, useTransition } from "react";
import {
Dialog,
DialogClose,
@@ -25,37 +25,51 @@ import {
import { Input } from "./ui/input";
import { Resume } from "@/models/profile.model";
import { toast } from "./ui/use-toast";
-import { createResumeProfile } from "@/actions/profile.actions";
+import { createResumeProfile, editResume } from "@/actions/profile.actions";
type CreateResumeProps = {
- editResume?: Resume | null;
+ resumeToEdit?: Resume | null;
reloadResumes: () => void;
+ resetResumeToEdit: () => void;
};
-function CreateResume({ editResume, reloadResumes }: CreateResumeProps) {
+function CreateResume({
+ resumeToEdit,
+ reloadResumes,
+ resetResumeToEdit,
+}: CreateResumeProps) {
const [dialogOpen, setDialogOpen] = useState(false);
const [isPending, startTransition] = useTransition();
- const pageTitle = editResume ? "Edit Resume Title" : "Create Resume";
+ const pageTitle = resumeToEdit ? "Edit Resume Title" : "Create Resume";
const form = useForm<z.infer<typeof CreateResumeFormSchema>>({
resolver: zodResolver(CreateResumeFormSchema),
});
- const { setValue, reset, formState } = form;
+ const { setValue, reset, formState, clearErrors } = form;
+
+ useEffect(() => {
+ if (resumeToEdit) {
+ clearErrors();
+ setValue("id", resumeToEdit.id);
+ setValue("title", resumeToEdit.title);
+
+ setDialogOpen(true);
+ }
+ }, [resumeToEdit, setValue, clearErrors]);
const createResume = () => {
- // reset();
- // resetEditJob();
+ reset();
+ resetResumeToEdit();
setDialogOpen(true);
};
const onSubmit = (data: z.infer<typeof CreateResumeFormSchema>) => {
startTransition(async () => {
- const res = await createResumeProfile(data);
- // const res = editCompany
- // ? await updateCompany(data)
- // : await addCompany(data);
+ const res = resumeToEdit
+ ? await editResume(data)
+ : await createResumeProfile(data);
if (!res.success) {
toast({
variant: "destructive",
@@ -69,7 +83,7 @@ function CreateResume({ editResume, reloadResumes }: CreateResumeProps) {
toast({
variant: "success",
description: `Resume title has been ${
- editResume ? "updated" : "created"
+ resumeToEdit ? "updated" : "created"
} successfully`,
});
}
diff --git a/src/components/ProfileContainer.tsx b/src/components/ProfileContainer.tsx
index 193b4c6..eb68412 100644
--- a/src/components/ProfileContainer.tsx
+++ b/src/components/ProfileContainer.tsx
@@ -14,6 +14,7 @@ function ActivitiesContainer() {
const recordsPerPage = APP_CONSTANTS.RECORDS_PER_PAGE;
const [resumes, setResumes] = useState<Resume[]>([]);
+ const [resumeToEdit, setResumeToEdit] = useState<Resume | null>(null);
const [totalResumes, setTotalResumes] = useState(0);
const [currentPage, setCurrentPage] = useState(
Number(queryParams.get("page")) || 1
@@ -46,12 +47,25 @@ function ActivitiesContainer() {
loadResumes(currentPage);
}, [currentPage, loadResumes]);
+ const onEditResume = (resume: Resume) => {
+ const _resumeToEdit = { id: resume.id, title: resume.title };
+ setResumeToEdit(_resumeToEdit);
+ };
+
+ const resetResumeToEdit = () => {
+ setResumeToEdit(null);
+ };
+
return (
<Card>
<CardHeader className="flex-row justify-between items-center">
<CardTitle>Profile</CardTitle>
<div className="flex items-center">
- <CreateResume reloadResumes={reloadResumes} />
+ <CreateResume
+ reloadResumes={reloadResumes}
+ resumeToEdit={resumeToEdit}
+ resetResumeToEdit={resetResumeToEdit}
+ />
</div>
</CardHeader>
<CardContent>
@@ -63,7 +77,7 @@ function ActivitiesContainer() {
recordsPerPage={recordsPerPage}
totalResumes={totalResumes}
// onPageChange={onPageChange}
- // editCompany={onEditCompany}
+ editResume={onEditResume}
/>
) : (
<Loading />
diff --git a/src/components/ResumeContainer.tsx b/src/components/ResumeContainer.tsx
index 9ec9a21..2d6bdc5 100644
--- a/src/components/ResumeContainer.tsx
+++ b/src/components/ResumeContainer.tsx
@@ -8,7 +8,7 @@ import { useRef } from "react";
function ResumeContainer({ resume }: { resume: Resume }) {
const resumeSectionRef = useRef<AddResumeSectionRef>(null);
const openContactInfoDialog = () => {
- resumeSectionRef.current?.openDialog();
+ resumeSectionRef.current?.openDialog(resume.ContactInfo!);
};
return (
<>
diff --git a/src/components/ResumeTable.tsx b/src/components/ResumeTable.tsx
index e57b45f..eceecda 100644
--- a/src/components/ResumeTable.tsx
+++ b/src/components/ResumeTable.tsx
@@ -27,7 +27,7 @@ type ResumeTableProps = {
totalResumes: number;
recordsPerPage: number;
// onPageChange: (n: number) => void;
- // editCompany: (id: string) => void;
+ editResume: (resume: Resume) => void;
};
function ResumeTable({
@@ -36,8 +36,8 @@ function ResumeTable({
totalPages,
totalResumes,
recordsPerPage,
+ editResume,
}: // onPageChange,
-// editCompany,
ResumeTableProps) {
return (
<Table>
@@ -45,6 +45,7 @@ ResumeTableProps) {
<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>
@@ -63,6 +64,9 @@ ResumeTableProps) {
<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>
@@ -73,22 +77,19 @@ ResumeTableProps) {
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
- <Link href={`/dashboard/profile/resume/${resume.id}`}>
- <DropdownMenuItem
- className="cursor-pointer"
- onClick={() => ""}
- >
- <FilePenLine className="mr-2 h-4 w-4" />
- View/Edit Resume
- </DropdownMenuItem>
- </Link>
<DropdownMenuItem
className="cursor-pointer"
- onClick={() => ""}
+ 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">
<Trash className="mr-2 h-4 w-4" />
Delete