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 experience form

Khuram Niazc0fac61a47bc
diff --git a/src/components/ComboBox.tsx b/src/components/ComboBox.tsx
index 0f9797b..597c431 100644
--- a/src/components/ComboBox.tsx
+++ b/src/components/ComboBox.tsx
@@ -29,7 +29,7 @@ import { createJobTitle } from "@/actions/jobtitle.actions";
interface ComboboxProps {
options: any[];
- field: ControllerRenderProps<JobForm, any>;
+ field: ControllerRenderProps<any, any>;
creatable?: boolean;
}
diff --git a/src/components/DatePicker.tsx b/src/components/DatePicker.tsx
index de5a29a..8067170 100644
--- a/src/components/DatePicker.tsx
+++ b/src/components/DatePicker.tsx
@@ -24,7 +24,7 @@ import { useState } from "react";
import { FormControl } from "./ui/form";
interface DatePickerProps {
- field: ControllerRenderProps<JobForm, any>;
+ field: ControllerRenderProps<any, any>;
presets: boolean;
isEnabled: boolean;
}
diff --git a/src/components/profile/AddExperience.tsx b/src/components/profile/AddExperience.tsx
new file mode 100644
index 0000000..69d100a
--- /dev/null
+++ b/src/components/profile/AddExperience.tsx
@@ -0,0 +1,257 @@
+"use client";
+import { AddExperienceFormSchema } from "@/models/addExperienceForm.schema";
+import { WorkExperience } from "@/models/profile.model";
+import { useCallback, useEffect, useState, useTransition } from "react";
+import { useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { z } from "zod";
+import {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "../ui/dialog";
+import { Button } from "../ui/button";
+import { Loader } from "lucide-react";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "../ui/form";
+import { Input } from "../ui/input";
+import TiptapEditor from "../TiptapEditor";
+import { toast } from "../ui/use-toast";
+import { Combobox } from "../ComboBox";
+import { DatePicker } from "../DatePicker";
+import { Company, JobLocation, JobTitle } from "@/models/job.model";
+import { getAllCompanies } from "@/actions/company.actions";
+import { getAllJobTitles } from "@/actions/jobtitle.actions";
+import { getAllJobLocations } from "@/actions/jobLocation.actions";
+
+type AddExperienceProps = {
+ dialogOpen: boolean;
+ setDialogOpen: (e: boolean) => void;
+ experienceToEdit?: WorkExperience;
+};
+
+function AddExperience({
+ dialogOpen,
+ setDialogOpen,
+ experienceToEdit,
+}: AddExperienceProps) {
+ const [companies, setCompanies] = useState<Company[]>([]);
+ const [locations, setLocations] = useState<JobLocation[]>([]);
+ const [jobTitles, setJobTitles] = useState<JobTitle[]>([]);
+ const pageTitle = experienceToEdit ? "Edit Experience" : "Add Experience";
+ const [isPending, startTransition] = useTransition();
+ const getTitleCompanyAndLocationData = useCallback(async () => {
+ console.log("get titles, companies and locations");
+ const [_companies, _titles, _locations] = await Promise.all([
+ getAllCompanies(),
+ getAllJobTitles(),
+ getAllJobLocations(),
+ ]);
+ setCompanies(_companies);
+ setLocations(_locations);
+ setJobTitles(_titles);
+ }, []);
+
+ const form = useForm<z.infer<typeof AddExperienceFormSchema>>({
+ resolver: zodResolver(AddExperienceFormSchema),
+ defaultValues: {},
+ });
+
+ const { setValue, reset, formState, clearErrors } = form;
+
+ useEffect(() => {
+ getTitleCompanyAndLocationData();
+ }, [getTitleCompanyAndLocationData]);
+
+ const onSubmit = (data: z.infer<typeof AddExperienceFormSchema>) => {
+ startTransition(async () => {
+ const res = { res: experienceToEdit, success: true, message: "" };
+ // ? 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: `Experience has been ${
+ experienceToEdit ? "updated" : "added"
+ } successfully`,
+ });
+ }
+ });
+ };
+
+ return (
+ <Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
+ <DialogContent className="h-full 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 */}
+ <div className="md:col-span-2">
+ <FormField
+ control={form.control}
+ name="sectionTitle"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Section Title</FormLabel>
+ <FormControl>
+ <Input {...field} placeholder="Ex: Experience" />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <hr className="md:col-span-2" />
+ {/* JOB TITLE */}
+ <div className="md:col-span-2">
+ <FormField
+ control={form.control}
+ name="title"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Job Title</FormLabel>
+ <FormControl>
+ <Combobox options={jobTitles!} field={field} creatable />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* COMPANY */}
+ <div>
+ <FormField
+ control={form.control}
+ name="company"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Company</FormLabel>
+ <FormControl>
+ <Combobox options={companies!} field={field} creatable />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ {/* LOCATION */}
+ <div>
+ <FormField
+ control={form.control}
+ name="location"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Job Location</FormLabel>
+ <FormControl>
+ <Combobox options={locations!} field={field} creatable />
+ </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}
+ />
+ <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}
+ />
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* JOB DESCRIPTION */}
+ <div className="md:col-span-2">
+ <FormField
+ control={form.control}
+ name="jobDescription"
+ render={({ field }) => (
+ <FormItem className="flex flex-col">
+ <FormLabel>Job 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 AddExperience;
diff --git a/src/components/profile/AddResumeSection.tsx b/src/components/profile/AddResumeSection.tsx
index e85c471..37630c7 100644
--- a/src/components/profile/AddResumeSection.tsx
+++ b/src/components/profile/AddResumeSection.tsx
@@ -17,6 +17,7 @@ import {
SectionType,
} from "@/models/profile.model";
import AddResumeSummary from "./AddResumeSummary";
+import AddExperience from "./AddExperience";
interface AddResumeSectionProps {
resume: Resume;
@@ -31,6 +32,7 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
({ resume }, ref) => {
const [contactInfoDialogOpen, setContactInfoDialogOpen] = useState(false);
const [summaryDialogOpen, setSummaryDialogOpen] = useState(false);
+ const [experienceDialogOpen, setExperienceDialogOpen] = useState(false);
const [contactInfoToEdit, setContactInfoToEdit] =
useState<ContactInfo | null>(null);
const [summaryToEdit, setSummaryToEdit] = useState<ResumeSection | null>(
@@ -76,7 +78,12 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
>
Add Summary
</DropdownMenuItem>
- <DropdownMenuItem>Add Experience</DropdownMenuItem>
+ <DropdownMenuItem
+ className="cursor-pointer"
+ onClick={() => setExperienceDialogOpen(true)}
+ >
+ Add Experience
+ </DropdownMenuItem>
<DropdownMenuItem>Add Education</DropdownMenuItem>
</DropdownMenuGroup>
</DropdownMenuContent>
@@ -93,6 +100,10 @@ const AddResumeSection = forwardRef<AddResumeSectionRef, AddResumeSectionProps>(
setDialogOpen={setSummaryDialogOpen}
summaryToEdit={summaryToEdit}
/>
+ <AddExperience
+ dialogOpen={experienceDialogOpen}
+ setDialogOpen={setExperienceDialogOpen}
+ />
</>
);
}
diff --git a/src/models/addExperienceForm.schema.ts b/src/models/addExperienceForm.schema.ts
new file mode 100644
index 0000000..b524e0b
--- /dev/null
+++ b/src/models/addExperienceForm.schema.ts
@@ -0,0 +1,37 @@
+import { z } from "zod";
+
+export const AddExperienceFormSchema = z.object({
+ id: z.string().optional(),
+ sectionTitle: z
+ .string({
+ required_error: "Section title is required.",
+ })
+ .min(1),
+ sectionType: z.string().optional(),
+ title: z
+ .string({
+ required_error: "Job title is required.",
+ })
+ .min(2, {
+ message: "Job title must be at least 2 characters.",
+ }),
+ company: z
+ .string({
+ required_error: "Company name is required.",
+ })
+ .min(2, {
+ message: "Company name must be at least 2 characters.",
+ }),
+ location: z
+ .string({
+ required_error: "Location is required.",
+ })
+ .min(2, {
+ message: "Location name must be at least 2 characters.",
+ }),
+ jobDescription: z.string().min(10, {
+ message: "Job description must be at least 10 characters.",
+ }),
+ startDate: z.date(),
+ endDate: z.date().optional(),
+});
diff --git a/src/models/profile.model.ts b/src/models/profile.model.ts
index d408837..bb6ca1b 100644
--- a/src/models/profile.model.ts
+++ b/src/models/profile.model.ts
@@ -1,3 +1,5 @@
+import { Company, JobLocation, JobTitle } from "./job.model";
+
export interface Resume {
id?: string;
profileId?: string;
@@ -53,4 +55,16 @@ export interface ResumeSection {
sectionTitle: string;
sectionType: SectionType;
summary?: Summary;
+ workExperiences?: WorkExperience[];
+}
+
+export interface WorkExperience {
+ id?: string;
+ createdAt?: string;
+ updatedAt?: string;
+ company: Company;
+ title: JobTitle;
+ location: JobLocation;
+ startDate: Date;
+ endDate: Date;
}