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
Add/edit summary section
Khuram Niazf4c5502d53b2
diff --git a/prisma/migrations/20240627061730_update_resume_section_and_summary_relationship/migration.sql b/prisma/migrations/20240627061730_update_resume_section_and_summary_relationship/migration.sqlnew file mode 100644index 0000000..c30c192--- /dev/null+++ b/prisma/migrations/20240627061730_update_resume_section_and_summary_relationship/migration.sql@@ -0,0 +1,25 @@+/*+ Warnings:++ - You are about to drop the column `summaryId` on the `Resume` table. All the data in the column will be lost.+ - A unique constraint covering the columns `[summaryId]` on the table `ResumeSection` will be added. If there are existing duplicate values, this will fail.++*/+-- RedefineTables+PRAGMA foreign_keys=OFF;+CREATE TABLE "new_Resume" (+ "id" TEXT NOT NULL PRIMARY KEY,+ "profileId" TEXT NOT NULL,+ "title" TEXT NOT NULL,+ "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "updatedAt" DATETIME NOT NULL,+ CONSTRAINT "Resume_profileId_fkey" FOREIGN KEY ("profileId") REFERENCES "Profile" ("id") ON DELETE RESTRICT ON UPDATE CASCADE+);+INSERT INTO "new_Resume" ("createdAt", "id", "profileId", "title", "updatedAt") SELECT "createdAt", "id", "profileId", "title", "updatedAt" FROM "Resume";+DROP TABLE "Resume";+ALTER TABLE "new_Resume" RENAME TO "Resume";+PRAGMA foreign_key_check("Resume");+PRAGMA foreign_keys=ON;++-- CreateIndex+CREATE UNIQUE INDEX "ResumeSection_summaryId_key" ON "ResumeSection"("summaryId");diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex c855f02..77f47e7 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -42,7 +42,6 @@ model Resume {ContactInfo ContactInfo?ResumeSections ResumeSection[]profile Profile @relation(fields: [profileId], references: [id])- summaryId String?}model ResumeSection {@@ -50,7 +49,7 @@ model ResumeSection {resumeId StringsectionTitle StringsectionType String- summaryId String?+ summaryId String? @uniquesummary Summary? @relation(fields: [summaryId], references: [id])workExperiences WorkExperience[]educations Education[]@@ -74,11 +73,11 @@ model ContactInfo {}model Summary {- id String @id @default(uuid())- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt+ id String @id @default(uuid())+ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAtcontent String- ResumeSection ResumeSection[]+ ResumeSection ResumeSection? @relation}model WorkExperience {diff --git a/src/actions/profile.actions.ts b/src/actions/profile.actions.tsindex 6dd9fec..fe6e96a 100644--- a/src/actions/profile.actions.ts+++ b/src/actions/profile.actions.ts@@ -1,7 +1,9 @@"use server";import prisma from "@/lib/db";import { AddContactInfoFormSchema } from "@/models/addContactInfoForm.schema";+import { AddSummarySectionFormSchema } from "@/models/addSummaryForm.schema";import { CreateResumeFormSchema } from "@/models/createResumeForm.schema";+import { ResumeSection, SectionType, Summary } from "@/models/profile.model";import { getCurrentUser } from "@/utils/user.utils";import { revalidatePath } from "next/cache";import { z } from "zod";@@ -68,6 +70,11 @@ export const getResumeById = async (},include: {ContactInfo: true,+ ResumeSections: {+ include: {+ summary: true,+ },+ },},});return resume;@@ -235,3 +242,84 @@ export const editResume = async (}}};++export const addResumeSummary = async (+ data: z.infer<typeof AddSummarySectionFormSchema>+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();++ if (!user) {+ throw new Error("Not authenticated");+ }+ const res = await prisma.resumeSection.create({+ data: {+ resumeId: data.resumeId!,+ sectionTitle: data.sectionTitle!,+ sectionType: SectionType.SUMMARY,+ },+ });++ const summary = await prisma.resumeSection.update({+ where: {+ id: res.id,+ },+ data: {+ summary: {+ create: {+ content: data.content!,+ },+ },+ },+ });+ revalidatePath("/dashboard/profile/resume/[id]");+ return { data: summary, success: true };+ } catch (error) {+ const msg = "Failed to create summary.";+ console.error(msg, error);+ if (error instanceof Error) {+ return { success: false, message: error.message };+ }+ }+};++export const updateResumeSummary = async (+ data: z.infer<typeof AddSummarySectionFormSchema>+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();++ if (!user) {+ throw new Error("Not authenticated");+ }+ const res = await prisma.resumeSection.update({+ where: {+ id: data.id,+ },+ data: {+ sectionTitle: data.sectionTitle!,+ },+ });++ const summary = await prisma.resumeSection.update({+ where: {+ id: data.id,+ },+ data: {+ summary: {+ update: {+ content: data.content!,+ },+ },+ },+ });+ revalidatePath("/dashboard/profile/resume/[id]");+ return { data: summary, success: true };+ } catch (error) {+ const msg = "Failed to update summary.";+ console.error(msg, error);+ if (error instanceof Error) {+ return { success: false, message: error.message };+ }+ }+};diff --git a/src/components/AddResumeSection.tsx b/src/components/AddResumeSection.tsxindex 11f4f17..0f54047 100644--- a/src/components/AddResumeSection.tsx+++ b/src/components/AddResumeSection.tsx@@ -10,27 +10,45 @@ import {} from "./ui/dropdown-menu";import AddContactInfo from "./AddContactInfo";import { forwardRef, useImperativeHandle, useState } from "react";-import { ContactInfo, Resume } from "@/models/profile.model";+import {+ ContactInfo,+ Resume,+ ResumeSection,+ SectionType,+} from "@/models/profile.model";+import AddResumeSummary from "./AddResumeSummary";interface AddResumeSectionProps {resume: Resume;}export interface AddResumeSectionRef {- openDialog: (c: ContactInfo) => void;+ openContactInfoDialog: (c: ContactInfo) => void;+ openSummaryDialog: (s: ResumeSection) => void;}const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(({ resume }, ref) => {const [contactInfoDialogOpen, setContactInfoDialogOpen] = useState(false);+ const [summaryDialogOpen, setSummaryDialogOpen] = useState(false);const [contactInfoToEdit, setContactInfoToEdit] =useState<ContactInfo | null>(null);+ const [summaryToEdit, setSummaryToEdit] = useState<ResumeSection | null>(+ null+ );useImperativeHandle(ref, () => ({- openDialog(contactInfo: ContactInfo) {+ openContactInfoDialog(contactInfo: ContactInfo) {setContactInfoDialogOpen(true);setContactInfoToEdit({ ...contactInfo });},+ openSummaryDialog(summarySection: ResumeSection) {+ setSummaryDialogOpen(true);+ setSummaryToEdit({ ...summarySection });+ },}));+ const summarySection = resume.ResumeSections.find(+ (section) => section.sectionType === SectionType.SUMMARY+ );return (<><DropdownMenu>@@ -51,7 +69,13 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(>Add Contact Info</DropdownMenuItem>- <DropdownMenuItem>Add Summary</DropdownMenuItem>+ <DropdownMenuItem+ className="cursor-pointer"+ onClick={() => setSummaryDialogOpen(true)}+ disabled={!!summarySection}+ >+ Add Summary+ </DropdownMenuItem><DropdownMenuItem>Add Experience</DropdownMenuItem><DropdownMenuItem>Add Education</DropdownMenuItem></DropdownMenuGroup>@@ -63,6 +87,12 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(resumeId={resume.id}contactInfoToEdit={contactInfoToEdit}/>+ <AddResumeSummary+ resumeId={resume.id}+ dialogOpen={summaryDialogOpen}+ setDialogOpen={setSummaryDialogOpen}+ summaryToEdit={summaryToEdit}+ /></>);}diff --git a/src/components/AddResumeSummary.tsx b/src/components/AddResumeSummary.tsxnew file mode 100644index 0000000..53eece7--- /dev/null+++ b/src/components/AddResumeSummary.tsx@@ -0,0 +1,166 @@+import { useForm } from "react-hook-form";+import {+ Dialog,+ DialogClose,+ DialogContent,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "./ui/dialog";+import { AddSummarySectionFormSchema } from "@/models/addSummaryForm.schema";+import { zodResolver } from "@hookform/resolvers/zod";+import { Button } from "./ui/button";+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "./ui/form";+import { Input } from "./ui/input";+import { Loader } from "lucide-react";+import { useEffect, useTransition } from "react";+import { toast } from "./ui/use-toast";+import { z } from "zod";+import TiptapEditor from "./TiptapEditor";+import {+ addResumeSummary,+ updateResumeSummary,+} from "@/actions/profile.actions";+import { ResumeSection } from "@/models/profile.model";++interface AddResumeSummaryProps {+ resumeId: string | undefined;+ dialogOpen: boolean;+ setDialogOpen: (e: boolean) => void;+ summaryToEdit?: ResumeSection | null;+}++function AddResumeSummary({+ resumeId,+ dialogOpen,+ setDialogOpen,+ summaryToEdit,+}: AddResumeSummaryProps) {+ const [isPending, startTransition] = useTransition();++ const pageTitle = summaryToEdit ? "Edit Summary" : "Add Summary";++ const form = useForm<z.infer<typeof AddSummarySectionFormSchema>>({+ resolver: zodResolver(AddSummarySectionFormSchema),+ defaultValues: {+ resumeId,+ },+ });++ const { setValue, reset, formState, clearErrors } = form;++ useEffect(() => {+ if (summaryToEdit) {+ clearErrors();+ setValue("id", summaryToEdit.id);+ setValue("sectionTitle", summaryToEdit.sectionTitle);+ setValue("sectionType", summaryToEdit.sectionType);+ setValue("content", summaryToEdit.summary?.content!);+ } else {+ reset();+ }+ }, [summaryToEdit, setValue, clearErrors, reset, dialogOpen]);++ const onSubmit = (data: z.infer<typeof AddSummarySectionFormSchema>) => {+ startTransition(async () => {+ const res = summaryToEdit+ ? await updateResumeSummary(data)+ : await addResumeSummary(data);+ if (!res.success) {+ toast({+ variant: "destructive",+ title: "Error!",+ description: res.message,+ });+ } else {+ reset();+ setDialogOpen(false);+ toast({+ variant: "success",+ description: `Summary has been ${+ summaryToEdit ? "updated" : "created"+ } successfully`,+ });+ }+ });+ };++ return (+ <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>+ <DialogContent className="lg:max-h-screen overflow-y-scroll">+ <DialogHeader>+ <DialogTitle>{pageTitle}</DialogTitle>+ </DialogHeader>+ <Form {...form}>+ <form+ onSubmit={form.handleSubmit(onSubmit)}+ className="grid grid-cols-1 md:grid-cols-2 gap-4 p-2"+ >+ {/* SECTION TITLE */}+ <div className="md:col-span-2">+ <FormField+ control={form.control}+ name="sectionTitle"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Section Title</FormLabel>+ <FormControl>+ <Input {...field} placeholder="Ex: Summary" />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </div>+ {/* SUMMARY CONTENT */}+ <div className="md:col-span-2">+ <FormField+ control={form.control}+ name="content"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>Resume Summary</FormLabel>+ <FormControl>+ <TiptapEditor field={field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </div>+ <div className="md:col-span-2 mt-4">+ <DialogFooter+ // className="md:col-span+ >+ <DialogClose>+ <Button+ type="reset"+ variant="outline"+ className="mt-2 md:mt-0 w-full"+ >+ Cancel+ </Button>+ </DialogClose>+ <Button type="submit" disabled={!formState.isDirty}>+ Save+ {isPending ? (+ <Loader className="h-4 w-4 shrink-0 spinner" />+ ) : null}+ </Button>+ </DialogFooter>+ </div>+ </form>+ </Form>+ </DialogContent>+ </Dialog>+ );+}++export default AddResumeSummary;diff --git a/src/components/JobDetails.tsx b/src/components/JobDetails.tsxindex 6f406a0..095a82e 100644--- a/src/components/JobDetails.tsx+++ b/src/components/JobDetails.tsx@@ -3,12 +3,12 @@ import { useEffect, useState } from "react";import { Button } from "./ui/button";import {DialogClose,+ DialogDescription,DialogFooter,DialogHeader,DialogTitle,} from "./ui/dialog";import { getJobDetails } from "@/actions/job.actions";-import { DialogDescription } from "@radix-ui/react-dialog";import { format } from "date-fns";import { EditorContent, useEditor } from "@tiptap/react";import StarterKit from "@tiptap/starter-kit";diff --git a/src/components/RecentJobsCard.tsx b/src/components/RecentJobsCard.tsxindex 64ce0da..839621c 100644--- a/src/components/RecentJobsCard.tsx+++ b/src/components/RecentJobsCard.tsx@@ -4,8 +4,6 @@ import { JobResponse } from "@/models/job.model";import { format } from "date-fns";export default function RecentJobsCard({ jobs }: { jobs: JobResponse[] }) {- debugger;-return (<Card><CardHeader>diff --git a/src/components/ResumeContainer.tsx b/src/components/ResumeContainer.tsxindex 2d6bdc5..fc3cfc7 100644--- a/src/components/ResumeContainer.tsx+++ b/src/components/ResumeContainer.tsx@@ -1,14 +1,21 @@"use client";-import { Resume } from "@/models/profile.model";+import { Resume, SectionType } from "@/models/profile.model";import { Card, CardDescription, CardHeader, CardTitle } from "./ui/card";import AddResumeSection, { AddResumeSectionRef } from "./AddResumeSection";import ContactInfoCard from "./ContactInfoCard";import { useRef } from "react";+import SummarySectionCard from "./SummarySectionCard";function ResumeContainer({ resume }: { resume: Resume }) {const resumeSectionRef = useRef<AddResumeSectionRef>(null);+ const summarySection = resume.ResumeSections.find(+ (section) => section.sectionType === SectionType.SUMMARY+ );const openContactInfoDialog = () => {- resumeSectionRef.current?.openDialog(resume.ContactInfo!);+ resumeSectionRef.current?.openContactInfoDialog(resume.ContactInfo!);+ };+ const openSummaryDialogForEdit = () => {+ resumeSectionRef.current?.openSummaryDialog(summarySection!);};return (<>@@ -27,6 +34,12 @@ function ResumeContainer({ resume }: { resume: Resume }) {openDialog={openContactInfoDialog}/>) : null}+ {summarySection ? (+ <SummarySectionCard+ summarySection={summarySection}+ openDialogForEdit={openSummaryDialogForEdit}+ />+ ) : null}</>);}diff --git a/src/components/SummarySectionCard.tsx b/src/components/SummarySectionCard.tsxnew file mode 100644index 0000000..3f1c972--- /dev/null+++ b/src/components/SummarySectionCard.tsx@@ -0,0 +1,55 @@+"use client";++import { Edit } from "lucide-react";+import { Button } from "./ui/button";+import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";+import { ResumeSection } from "@/models/profile.model";+import { useEffect } from "react";+import { EditorContent, useEditor } from "@tiptap/react";+import StarterKit from "@tiptap/starter-kit";++interface SummarySectionCardProps {+ summarySection: ResumeSection | undefined;+ openDialogForEdit: () => void;+}++function SummarySectionCard({+ summarySection,+ openDialogForEdit,+}: SummarySectionCardProps) {+ const editor = useEditor({+ extensions: [StarterKit],+ content: "",+ editable: false,+ });+ useEffect(() => {+ editor?.commands.setContent(summarySection?.summary?.content!);+ });+ return (+ <>+ <Card>+ <CardHeader className="flex-row justify-between relative">+ <div>+ <CardTitle>{summarySection?.sectionTitle}</CardTitle>+ </div>+ <Button+ variant="ghost"+ size="sm"+ className="h-8 gap-1 absolute top-0 right-1"+ onClick={openDialogForEdit}+ >+ <Edit className="h-3.5 w-3.5" />+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">+ Edit+ </span>+ </Button>+ </CardHeader>+ <CardContent>+ <EditorContent editor={editor} />+ </CardContent>+ </Card>+ </>+ );+}++export default SummarySectionCard;diff --git a/src/components/TiptapEditor.tsx b/src/components/TiptapEditor.tsxindex 34aaeee..4339c31 100644--- a/src/components/TiptapEditor.tsx+++ b/src/components/TiptapEditor.tsx@@ -8,7 +8,7 @@ import { ControllerRenderProps } from "react-hook-form";import { Toggle } from "./ui/toggle";import { Bold, Heading2, Italic, List, ListOrdered } from "lucide-react";-const Tiptap = ({ field }: { field: ControllerRenderProps<JobForm, any> }) => {+const Tiptap = ({ field }: { field: ControllerRenderProps<any, any> }) => {const editor = useEditor({extensions: [StarterKit.configure({diff --git a/src/models/addSummaryForm.schema.ts b/src/models/addSummaryForm.schema.tsnew file mode 100644index 0000000..99f5071--- /dev/null+++ b/src/models/addSummaryForm.schema.ts@@ -0,0 +1,19 @@+import { z } from "zod";++export const AddSummarySectionFormSchema = z.object({+ id: z.string().optional(),+ sectionTitle: z+ .string({+ required_error: "Section title is required.",+ })+ .min(1),+ sectionType: z.string().optional(),+ createdAt: z.string().optional(),+ updatedAt: z.string().optional(),+ resumeId: z.string().optional(),+ content: z+ .string({+ required_error: "Summary content is required",+ })+ .min(10),+});diff --git a/src/models/profile.model.ts b/src/models/profile.model.tsindex a8c9b85..f053e45 100644--- a/src/models/profile.model.ts+++ b/src/models/profile.model.ts@@ -5,6 +5,7 @@ export interface Resume {createdAt?: Date;updatedAt?: Date;ContactInfo?: ContactInfo;+ ResumeSections: ResumeSection[];}export interface ContactInfo {@@ -19,3 +20,37 @@ export interface ContactInfo {phone?: string;address?: string;}++export enum SectionType {+ SUMMARY = "summary",+ EXPERIENCE = "experience",+ EDUCATION = "education",+ LICENSE = "license",+ CERTIFICATION = "certification",+ COURSE = "course",+ PROJECT = "project",+ OTHER = "other",+}++export interface Summary {+ id?: string;+ createdAt?: string;+ updatedAt?: string;+ content: string;+}++export interface SummarySectionForm {+ id?: string;+ resumeId: string;+ sectionTitle: string;+ sectionType: string;+ content: string;+}++export interface ResumeSection {+ id?: string;+ resumeId: string;+ sectionTitle: string;+ sectionType: SectionType;+ summary?: Summary;+}