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 education section

Khuram Niaz22912cae4fcc
diff --git a/src/actions/profile.actions.ts b/src/actions/profile.actions.ts
index bd20d38..4d9535a 100644
--- a/src/actions/profile.actions.ts
+++ b/src/actions/profile.actions.ts
@@ -1,5 +1,6 @@
"use server";
import prisma from "@/lib/db";
+import { AddEducationFormSchema } from "@/models/AddEductionForm.schema";
import { AddContactInfoFormSchema } from "@/models/addContactInfoForm.schema";
import { AddExperienceFormSchema } from "@/models/addExperienceForm.schema";
import { AddSummarySectionFormSchema } from "@/models/addSummaryForm.schema";
@@ -81,7 +82,11 @@ export const getResumeById = async (
location: true,
},
},
- educations: true,
+ educations: {
+ include: {
+ location: true,
+ },
+ },
},
},
},
@@ -420,3 +425,94 @@ export const updateExperience = async (
}
}
};
+
+export const addEducation = async (
+ data: z.infer<typeof AddEducationFormSchema>
+): Promise<any | undefined> => {
+ try {
+ const user = await getCurrentUser();
+
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+ const section = !data.sectionId
+ ? await prisma.resumeSection.create({
+ data: {
+ resumeId: data.resumeId!,
+ sectionTitle: data.sectionTitle!,
+ sectionType: SectionType.EDUCATION,
+ },
+ })
+ : undefined;
+
+ const education = await prisma.resumeSection.update({
+ where: {
+ id: section ? section.id : data.sectionId,
+ },
+ data: {
+ educations: {
+ create: {
+ institution: data.institution,
+ degree: data.degree,
+ fieldOfStudy: data.fieldOfStudy,
+ locationId: data.location,
+ startDate: data.startDate,
+ endDate: data.endDate,
+ description: data.description,
+ },
+ },
+ },
+ });
+ revalidatePath("/dashboard/profile/resume/[id]");
+ return { data: education, success: true };
+ } catch (error) {
+ const msg = "Failed to create education.";
+ console.error(msg, error);
+ if (error instanceof Error) {
+ return { success: false, message: error.message };
+ }
+ }
+};
+
+export const updateEducation = async (
+ data: z.infer<typeof AddEducationFormSchema>
+): 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.education.update({
+ where: {
+ id: data.id,
+ },
+ data: {
+ institution: data.institution,
+ degree: data.degree,
+ fieldOfStudy: data.fieldOfStudy,
+ locationId: data.location,
+ startDate: data.startDate,
+ endDate: data.endDate,
+ description: data.description,
+ },
+ });
+ revalidatePath("/dashboard/profile/resume/[id]");
+ return { data: summary, success: true };
+ } catch (error) {
+ const msg = "Failed to update education.";
+ console.error(msg, error);
+ if (error instanceof Error) {
+ return { success: false, message: error.message };
+ }
+ }
+};
diff --git a/src/components/profile/AddEducation.tsx b/src/components/profile/AddEducation.tsx
new file mode 100644
index 0000000..bfa19bf
--- /dev/null
+++ b/src/components/profile/AddEducation.tsx
@@ -0,0 +1,340 @@
+"use client";
+import { AddEducationFormSchema } from "@/models/AddEductionForm.schema";
+import { ResumeSection } from "@/models/profile.model";
+import { useForm } from "react-hook-form";
+import { z } from "zod";
+import { zodResolver } from "@hookform/resolvers/zod";
+import {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "../ui/dialog";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "../ui/form";
+import { Input } from "../ui/input";
+import { DatePicker } from "../DatePicker";
+import { Switch } from "../ui/switch";
+import TiptapEditor from "../TiptapEditor";
+import { Button } from "../ui/button";
+import { useCallback, useEffect, useState, useTransition } from "react";
+import { toast } from "../ui/use-toast";
+import { Loader } from "lucide-react";
+import { Combobox } from "../ComboBox";
+import { JobLocation } from "@/models/job.model";
+import { addEducation, updateEducation } from "@/actions/profile.actions";
+import { getAllJobLocations } from "@/actions/jobLocation.actions";
+
+type AddEducationProps = {
+ resumeId: string | undefined;
+ sectionId: string | undefined;
+ dialogOpen: boolean;
+ setDialogOpen: (e: boolean) => void;
+ educationToEdit?: ResumeSection;
+ resetEducationToEdit: () => void;
+};
+
+function AddEducation({
+ resumeId,
+ sectionId,
+ dialogOpen,
+ setDialogOpen,
+ educationToEdit,
+ resetEducationToEdit,
+}: AddEducationProps) {
+ const pageTitle = educationToEdit ? "Edit Education" : "Add Education";
+ const [isPending, startTransition] = useTransition();
+ const [locations, setLocations] = useState<JobLocation[]>([]);
+
+ const getLocationData = useCallback(async () => {
+ const _locations = await getAllJobLocations();
+ setLocations(_locations);
+ }, []);
+
+ const form = useForm<z.infer<typeof AddEducationFormSchema>>({
+ resolver: zodResolver(AddEducationFormSchema),
+ defaultValues: {
+ resumeId,
+ sectionId,
+ degreeCompleted: true,
+ },
+ });
+
+ const { setValue, watch, reset, formState, resetField, clearErrors } = form;
+
+ const degreeCompletedValue = watch("degreeCompleted");
+
+ useEffect(() => {
+ getLocationData();
+ // if (experienceToEdit) {
+ // clearErrors();
+ // const experience: WorkExperience =
+ // experienceToEdit.workExperiences?.pop()!;
+ // setValue("id", experience?.id);
+ // setValue("title", experience?.jobTitle.id);
+ // setValue("company", experience?.Company.id);
+ // setValue("location", experience?.location.id);
+ // setValue("startDate", experience?.startDate);
+ // setValue("endDate", experience?.endDate);
+ // setValue("jobDescription", experience?.description);
+ // setValue("currentJob", !!!experience?.endDate);
+ // } else {
+ // reset();
+ // resetExperienceToEdit();
+ // }
+ setValue("sectionId", sectionId);
+ }, [
+ getLocationData,
+ // experienceToEdit,
+ // clearErrors,
+ setValue,
+ sectionId,
+ // reset,
+ // resetExperienceToEdit,
+ ]);
+
+ const onDegreeCompleted = (completed: boolean) => {
+ if (completed) {
+ resetField("endDate");
+ }
+ };
+
+ const onSubmit = (data: z.infer<typeof AddEducationFormSchema>) => {
+ startTransition(async () => {
+ const res = educationToEdit?.educations?.length
+ ? await updateEducation(data)
+ : await addEducation(data);
+ if (!res.success) {
+ toast({
+ variant: "destructive",
+ title: "Error!",
+ description: res.message,
+ });
+ } else {
+ reset();
+ setDialogOpen(false);
+ toast({
+ variant: "success",
+ description: `Education has been ${
+ educationToEdit ? "updated" : "added"
+ } successfully`,
+ });
+ }
+ });
+ };
+
+ return (
+ <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
+ <DialogContent className="h-full md:h-[85%] lg:max-h-screen md:max-w-[40rem] 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 */}
+ {!sectionId ? (
+ <>
+ <div className="md:col-span-2">
+ <FormField
+ control={form.control}
+ name="sectionTitle"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Section Title</FormLabel>
+ <FormControl>
+ <Input {...field} placeholder="Ex: Education" />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <hr className="md:col-span-2" />
+ </>
+ ) : null}
+
+ {/* INSTITUTION */}
+ <div>
+ <FormField
+ control={form.control}
+ name="institution"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>School</FormLabel>
+ <FormControl>
+ <Input {...field} placeholder="Ex: Stanford" />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* LOCATION */}
+ <div>
+ <FormField
+ control={form.control}
+ name="location"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Location</FormLabel>
+ <FormControl>
+ <Combobox options={locations!} field={field} creatable />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* DEGREE */}
+ <div>
+ <FormField
+ control={form.control}
+ name="degree"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Degree</FormLabel>
+ <FormControl>
+ <Input {...field} placeholder="Ex: Bachelor's" />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ {/* FIELD OF STUDY */}
+ <div>
+ <FormField
+ control={form.control}
+ name="fieldOfStudy"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Field of study</FormLabel>
+ <FormControl>
+ <Input {...field} placeholder="Ex: Computer Science" />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* START DATE */}
+ <div className="flex flex-col">
+ <FormField
+ control={form.control}
+ name="startDate"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Start Date</FormLabel>
+ <DatePicker
+ field={field}
+ presets={false}
+ isEnabled={true}
+ captionLayout={true}
+ />
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* END DATE */}
+ <div className="flex flex-col">
+ <FormField
+ control={form.control}
+ name="endDate"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>End Date</FormLabel>
+ <DatePicker
+ field={field}
+ presets={false}
+ isEnabled={true}
+ captionLayout={true}
+ />
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* CURRENT STUDY */}
+ <div className="flex items-center">
+ <FormField
+ control={form.control}
+ name="degreeCompleted"
+ render={({ field }) => (
+ <FormItem className="flex flex-row">
+ <Switch
+ checked={field.value}
+ onCheckedChange={(c) => {
+ field.onChange(c);
+ onDegreeCompleted(c);
+ }}
+ />
+ <FormLabel className="flex items-center ml-4 mb-2">
+ {field.value ? "Degree Completed" : "Currently Studying"}
+ </FormLabel>
+
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* DESCRIPTION */}
+ <div className="md:col-span-2">
+ <FormField
+ control={form.control}
+ name="description"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Description</FormLabel>
+ <FormControl>
+ <TiptapEditor field={field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <div className="md:col-span-2 mt-4">
+ <DialogFooter>
+ <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 AddEducation;
diff --git a/src/components/profile/AddResumeSection.tsx b/src/components/profile/AddResumeSection.tsx
index 81eb250..f40ca3b 100644
--- a/src/components/profile/AddResumeSection.tsx
+++ b/src/components/profile/AddResumeSection.tsx
@@ -18,6 +18,7 @@ import {
} from "@/models/profile.model";
import AddResumeSummary from "./AddResumeSummary";
import AddExperience from "./AddExperience";
+import AddEducation from "./AddEducation";
interface AddResumeSectionProps {
resume: Resume;
@@ -34,6 +35,7 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
const [contactInfoDialogOpen, setContactInfoDialogOpen] = useState(false);
const [summaryDialogOpen, setSummaryDialogOpen] = useState(false);
const [experienceDialogOpen, setExperienceDialogOpen] = useState(false);
+ const [educationDialogOpen, setEducationDialogOpen] = useState(false);
const [contactInfoToEdit, setContactInfoToEdit] =
useState<ContactInfo | null>(null);
const [summaryToEdit, setSummaryToEdit] = useState<ResumeSection | null>(
@@ -61,6 +63,9 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
const experienceSection = resume.ResumeSections?.find(
(section) => section.sectionType === SectionType.EXPERIENCE
);
+ const educationSection = resume.ResumeSections?.find(
+ (section) => section.sectionType === SectionType.EDUCATION
+ );
const resetExperienceToEdit = () => {
setExperienceToEdit(null);
};
@@ -97,7 +102,12 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
>
Add Experience
</DropdownMenuItem>
- <DropdownMenuItem>Add Education</DropdownMenuItem>
+ <DropdownMenuItem
+ className="cursor-pointer"
+ onClick={() => setEducationDialogOpen(true)}
+ >
+ Add Education
+ </DropdownMenuItem>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
@@ -121,6 +131,14 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
experienceToEdit={experienceToEdit!}
resetExperienceToEdit={resetExperienceToEdit}
/>
+ <AddEducation
+ resumeId={resume.id}
+ sectionId={educationSection?.id}
+ dialogOpen={educationDialogOpen}
+ setDialogOpen={setEducationDialogOpen}
+ educationToEdit={experienceToEdit!}
+ resetEducationToEdit={resetExperienceToEdit}
+ />
</>
);
}
diff --git a/src/components/profile/EducationCard.tsx b/src/components/profile/EducationCard.tsx
new file mode 100644
index 0000000..cfdaf6f
--- /dev/null
+++ b/src/components/profile/EducationCard.tsx
@@ -0,0 +1,79 @@
+"use client";
+import { ResumeSection } from "@/models/profile.model";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+} from "../ui/card";
+import { Button } from "../ui/button";
+import { Edit } from "lucide-react";
+import { format } from "date-fns";
+import { Editor, EditorContent } from "@tiptap/react";
+import StarterKit from "@tiptap/starter-kit";
+
+interface EducationCardProps {
+ educationSection: ResumeSection | undefined;
+ openDialogForEdit: (id: string) => void;
+}
+
+function EducationCard({
+ educationSection,
+ openDialogForEdit,
+}: EducationCardProps) {
+ return (
+ <>
+ <CardTitle className="pl-6 py-3">
+ {educationSection?.sectionTitle}
+ </CardTitle>
+ {educationSection?.educations?.map((education) => (
+ <Card key={education.id}>
+ <CardHeader className="p-2 pb-0 flex-row justify-between relative">
+ <CardTitle className="text-xl pl-4">
+ {education.institution}
+ </CardTitle>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-8 gap-1 absolute top-0 right-1"
+ onClick={() => openDialogForEdit(education.id!)}
+ >
+ <Edit className="h-3.5 w-3.5" />
+ <span className="sr-only sm:not-sr-only sm:whitespace-nowrap">
+ Edit
+ </span>
+ </Button>
+ </CardHeader>
+ <CardContent>
+ <h3>
+ {education.degree}, {education.fieldOfStudy}
+ </h3>
+ <CardDescription>
+ {format(education.startDate, "MMM yyyy")} -{" "}
+ {education.endDate
+ ? format(education.endDate, "MMM yyyy")
+ : "Present"}
+ <div>{education.location.label}</div>
+ </CardDescription>
+ {education.description ? (
+ <div className="pt-2">
+ <EditorContent
+ editor={
+ new Editor({
+ extensions: [StarterKit],
+ content: education.description,
+ editable: false,
+ })
+ }
+ />
+ </div>
+ ) : null}
+ </CardContent>
+ </Card>
+ ))}
+ </>
+ );
+}
+
+export default EducationCard;
diff --git a/src/components/profile/ExperienceCard.tsx b/src/components/profile/ExperienceCard.tsx
index 348e0a2..eee998a 100644
--- a/src/components/profile/ExperienceCard.tsx
+++ b/src/components/profile/ExperienceCard.tsx
@@ -48,9 +48,9 @@ function ExperienceCard({
<CardContent>
<h3>{experience.Company.label}</h3>
<CardDescription>
- {format(experience.startDate, "MMM, yyyy")} -{" "}
+ {format(experience.startDate, "MMM yyyy")} -{" "}
{experience.endDate
- ? format(experience.endDate, "MMM, yyyy")
+ ? format(experience.endDate, "MMM yyyy")
: "Present"}
<div>{experience.location.label}</div>
</CardDescription>
diff --git a/src/components/profile/ResumeContainer.tsx b/src/components/profile/ResumeContainer.tsx
index 4d88daa..f076d36 100644
--- a/src/components/profile/ResumeContainer.tsx
+++ b/src/components/profile/ResumeContainer.tsx
@@ -6,6 +6,7 @@ import ContactInfoCard from "./ContactInfoCard";
import { useRef } from "react";
import SummarySectionCard from "./SummarySectionCard";
import ExperienceCard from "./ExperienceCard";
+import EducationCard from "./EducationCard";
function ResumeContainer({ resume }: { resume: Resume }) {
const resumeSectionRef = useRef<AddResumeSectionRef>(null);
@@ -15,6 +16,9 @@ function ResumeContainer({ resume }: { resume: Resume }) {
const experienceSection = resume.ResumeSections?.find(
(section) => section.sectionType === SectionType.EXPERIENCE
);
+ const educationSection = resume.ResumeSections?.find(
+ (section) => section.sectionType === SectionType.EDUCATION
+ );
const openContactInfoDialog = () => {
resumeSectionRef.current?.openContactInfoDialog(resume.ContactInfo!);
};
@@ -30,6 +34,15 @@ function ResumeContainer({ resume }: { resume: Resume }) {
};
resumeSectionRef.current?.openExperienceDialog(section);
};
+ const openEducationDialogForEdit = (educationId: string) => {
+ // const section: ResumeSection = {
+ // ...experienceSection!,
+ // workExperiences: experienceSection?.workExperiences?.filter(
+ // (exp) => exp.id === experienceId
+ // ),
+ // };
+ // resumeSectionRef.current?.openExperienceDialog(section);
+ };
return (
<>
<Card>
@@ -59,6 +72,12 @@ function ResumeContainer({ resume }: { resume: Resume }) {
openDialogForEdit={openExperienceDialogForEdit}
/>
) : null}
+ {educationSection ? (
+ <EducationCard
+ educationSection={educationSection}
+ openDialogForEdit={openEducationDialogForEdit}
+ />
+ ) : null}
</>
);
}
diff --git a/src/models/AddEductionForm.schema.ts b/src/models/AddEductionForm.schema.ts
new file mode 100644
index 0000000..95f83d1
--- /dev/null
+++ b/src/models/AddEductionForm.schema.ts
@@ -0,0 +1,35 @@
+import { z } from "zod";
+
+export const AddEducationFormSchema = z.object({
+ id: z.string().optional(),
+ resumeId: z.string().optional(),
+ sectionId: z.string().optional(),
+ sectionTitle: z.string().default("Education").optional(),
+ sectionType: z.string().optional(),
+ institution: z
+ .string({
+ required_error: "Institution name is required.",
+ })
+ .min(2),
+ degree: z
+ .string({
+ required_error: "Degree is required.",
+ })
+ .min(2),
+ fieldOfStudy: z
+ .string({
+ required_error: "Field of study is required.",
+ })
+ .min(2),
+ location: z
+ .string({
+ required_error: "Location is required.",
+ })
+ .min(2, {
+ message: "Location name must be at least 2 characters.",
+ }),
+ description: z.string().optional(),
+ startDate: z.date(),
+ endDate: z.date().optional(),
+ degreeCompleted: z.boolean().default(true).optional(),
+});
diff --git a/src/models/profile.model.ts b/src/models/profile.model.ts
index 0f95fde..8d68517 100644
--- a/src/models/profile.model.ts
+++ b/src/models/profile.model.ts
@@ -56,6 +56,7 @@ export interface ResumeSection {
sectionType: SectionType;
summary?: Summary;
workExperiences?: WorkExperience[];
+ educations?: Education[];
}
export interface WorkExperience {
@@ -70,3 +71,16 @@ export interface WorkExperience {
currentJob?: Boolean;
description: string;
}
+
+export interface Education {
+ id?: string;
+ createdAt?: string;
+ updatedAt?: string;
+ institution: string;
+ degree: string;
+ fieldOfStudy: string;
+ startDate: Date;
+ endDate?: Date;
+ description?: string;
+ location: JobLocation;
+}