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
feat(timeline): add the Add/Edit Stage dialog with custom stage types and interview-only fields
Khuram Niaz3eedda38d3b4
diff --git a/__tests__/AddStageDialog.spec.tsx b/__tests__/AddStageDialog.spec.tsxnew file mode 100644index 0000000..f698a7b--- /dev/null+++ b/__tests__/AddStageDialog.spec.tsx@@ -0,0 +1,114 @@+import { render, screen, within } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { AddStageDialog } from "@/components/myjobs/job-details/timeline/AddStageDialog";+import { addJobStage } from "@/actions/jobStage.actions";++vi.mock("@/actions/jobStage.actions", () => ({+ addJobStage: vi.fn().mockResolvedValue({ success: true, data: { id: "st1" } }),+ updateJobStage: vi.fn().mockResolvedValue({ success: true, data: { id: "st1" } }),+}));+vi.mock("@/lib/toast", () => ({+ toastActionResult: vi.fn((res, opts) => res.success && opts.onSuccess?.()),+ toastSuccess: vi.fn(),+ toastError: vi.fn(),+}));++// jsdom lacks scrollIntoView, which cmdk calls when selecting an item+Element.prototype.scrollIntoView = vi.fn();++const stageTypes = [+ { id: "t-off", label: "Offer", value: "offer", statusId: "s-off", sortOrder: 7, Status: { id: "s-off", label: "Offer", value: "offer" } },+ { id: "t-int", label: "Final / Onsite Interview", value: "final / onsite interview", statusId: "s-int", sortOrder: 6, Status: { id: "s-int", label: "Interview", value: "interview" } },+] as any;++const jobStatuses = [+ { id: "s-off", label: "Offer", value: "offer" },+ { id: "s-int", label: "Interview", value: "interview" },+] as any;++const props = {+ open: true,+ jobId: "j1",+ jobLabel: "Senior Frontend Engineer · Acme Corp",+ stage: null,+ stageTypes,+ jobStatuses,+ onOpenChange: () => {},+ onSaved: vi.fn(),+};++// The shared Combobox takes no data-testid, so the picker is wrapped in one+// and the trigger reached through it (Playwright's centre click lands on the+// button; a jsdom click on the wrapper would not).+const openStageTypePicker = async () =>+ userEvent.click(+ within(screen.getByTestId("stage-type-select")).getByRole("combobox"),+ );++describe("AddStageDialog", () => {+ beforeEach(() => vi.clearAllMocks());++ it("heads the dialog with the job it belongs to", () => {+ render(<AddStageDialog {...props} />);+ expect(screen.getByText("Senior Frontend Engineer · Acme Corp")).toBeInTheDocument();+ });++ it("ticks Set as current stage by default", () => {+ render(<AddStageDialog {...props} />);+ expect(screen.getByRole("checkbox", { name: /Set as current stage/ })).toBeChecked();+ });++ // Nothing demotes a stage, so a live checkbox here would silently do nothing.+ it("locks the checkbox when editing the stage that is already current", () => {+ render(+ <AddStageDialog+ {...props}+ stage={{ id: "st1", isCurrent: true, stageTypeId: "t-int", occurredAt: null, notes: null, outcome: null, durationMins: null, format: null, location: null, StageType: stageTypes[1] } as any}+ />,+ );++ const box = screen.getByRole("checkbox", { name: /Set as current stage/ });+ expect(box).toBeChecked();+ expect(box).toBeDisabled();+ expect(screen.getByText(/tick the box on another stage to move it/)).toBeInTheDocument();+ });++ it("hides the parent-status picker until a custom name is typed", async () => {+ render(<AddStageDialog {...props} />);+ expect(screen.queryByText(/PARENT STATUS/i)).toBeNull();++ await userEvent.type(+ screen.getByPlaceholderText("e.g. Panel Interview, Reference Check…"),+ "Panel Interview",+ );++ expect(screen.getByText(/PARENT STATUS/i)).toBeInTheDocument();+ });++ it("saves with the picked type, no date, and set-as-current", async () => {+ render(<AddStageDialog {...props} />);++ await openStageTypePicker();+ await userEvent.click(screen.getByRole("option", { name: "Offer" }));+ await userEvent.click(screen.getByRole("button", { name: "Add Stage" }));++ expect(addJobStage).toHaveBeenCalledWith(+ expect.objectContaining({+ jobId: "j1",+ stageTypeId: "t-off",+ setAsCurrent: true,+ }),+ );+ });++ it("refuses to save with neither a type nor a custom name", async () => {+ render(<AddStageDialog {...props} />);++ await userEvent.click(screen.getByRole("button", { name: "Add Stage" }));++ expect(addJobStage).not.toHaveBeenCalled();+ expect(+ await screen.findByText(/Pick a stage or enter a custom stage name/),+ ).toBeInTheDocument();+ });+});diff --git a/__tests__/JobDetails.spec.tsx b/__tests__/JobDetails.spec.tsxindex 33250c8..95085cf 100644--- a/__tests__/JobDetails.spec.tsx+++ b/__tests__/JobDetails.spec.tsx@@ -6,7 +6,12 @@ import userEvent from "@testing-library/user-event";// The active tab lives in the URL, so a click only calls router.replace —// what the user sees next comes from the re-render with the new params.-const router = { back: vi.fn(), push: vi.fn(), replace: vi.fn() };+const router = {+ back: vi.fn(),+ push: vi.fn(),+ replace: vi.fn(),+ refresh: vi.fn(),+};let searchParams = new URLSearchParams();const onTab = (tab: string) => {searchParams = new URLSearchParams(`tab=${tab}`);@@ -71,6 +76,8 @@ vi.mock("@/actions/jobStage.actions", () => ({removeStagePrepQuestion: vi.fn(),unlinkStageInterviewer: vi.fn(),setStageNotes: vi.fn(),+ addJobStage: vi.fn(),+ updateJobStage: vi.fn(),}));const makeStage = (id: string, label: string, over: any = {}) => ({diff --git a/src/components/myjobs/JobDetails.tsx b/src/components/myjobs/JobDetails.tsxindex 521bada..5498702 100644--- a/src/components/myjobs/JobDetails.tsx+++ b/src/components/myjobs/JobDetails.tsx@@ -43,6 +43,7 @@ import { JobContactsTab } from "./job-details/JobContactsTab";import { JobTimelineTab } from "./job-details/timeline/JobTimelineTab";import { useJobStages } from "./job-details/timeline/useJobStages";import { UpdateStatusMenu } from "./job-details/timeline/UpdateStatusMenu";+import { AddStageDialog } from "./job-details/timeline/AddStageDialog";import type { JobStage, JobStageTypeRef } from "@/models/jobStage.model";const JOB_DETAIL_TABS = [@@ -342,6 +343,21 @@ function JobDetails({hideTriggerredirectPath={`/dashboard/myjobs/${job.id}?tab=${activeTab}`}/>+ <AddStageDialog+ open={!!addStageTarget}+ jobId={job.id}+ jobLabel={`${job.JobTitle?.label ?? ""}${+ job.Company?.label ? ` · ${job.Company.label}` : ""+ }`}+ stage={addStageTarget?.mode === "edit" ? addStageTarget.stage : null}+ stageTypes={stageTypes}+ jobStatuses={jobStatuses}+ onOpenChange={(open) => !open && setAddStageTarget(null)}+ onSaved={() => {+ void reloadStages();+ router.refresh();+ }}+ /><DeleteAlertDialogpageTitle="job"open={deleteAlertOpen}diff --git a/src/components/myjobs/job-details/timeline/AddStageDialog.tsx b/src/components/myjobs/job-details/timeline/AddStageDialog.tsxnew file mode 100644index 0000000..99a30c9--- /dev/null+++ b/src/components/myjobs/job-details/timeline/AddStageDialog.tsx@@ -0,0 +1,371 @@+"use client";+import { useEffect, useTransition } from "react";+import { useForm } from "react-hook-form";+import { zodResolver } from "@hookform/resolvers/zod";+import { format } from "date-fns";+import { Loader } from "lucide-react";+import { Button } from "@/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "@/components/ui/dialog";+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "@/components/ui/form";+import { Input } from "@/components/ui/input";+import { Textarea } from "@/components/ui/textarea";+import { Combobox } from "@/components/ComboBox";+import { DatePicker } from "@/components/DatePicker";+import { TimePicker } from "@/components/TimePicker";+import SelectFormCtrl from "@/components/Select";+import { toastActionResult } from "@/lib/toast";+import { STAGE_OUTCOMES } from "@/lib/constants";+import { addJobStage, updateJobStage } from "@/actions/jobStage.actions";+import {+ AddJobStageFormSchema,+ type AddJobStageValues,+ type JobStage,+ type JobStageTypeRef,+} from "@/models/jobStage.model";+import type { JobStatus } from "@/models/job.model";++type AddStageDialogProps = {+ open: boolean;+ jobId: string;+ jobLabel: string;+ stage: JobStage | null;+ stageTypes: JobStageTypeRef[];+ jobStatuses: JobStatus[];+ onOpenChange: (open: boolean) => void;+ onSaved: () => void;+};++const OUTCOME_OPTIONS = STAGE_OUTCOMES.map((o) => ({+ id: o.value,+ label: o.label,+}));++const emptyValues = (jobId: string): AddJobStageValues => ({+ jobId,+ stageTypeId: "",+ customLabel: "",+ customStatusId: "",+ date: null,+ time: "",+ notes: "",+ outcome: null,+ durationMins: null,+ format: "",+ location: "",+ setAsCurrent: true,+});++const editValues = (jobId: string, stage: JobStage): AddJobStageValues => ({+ ...emptyValues(jobId),+ id: stage.id,+ stageTypeId: stage.stageTypeId,+ date: stage.occurredAt ?? null,+ time: stage.occurredAt ? format(stage.occurredAt, "hh:mm a") : "",+ notes: stage.notes ?? "",+ outcome: stage.outcome ?? null,+ durationMins: stage.durationMins ?? null,+ format: stage.format ?? "",+ location: stage.location ?? "",+ setAsCurrent: stage.isCurrent,+});++export function AddStageDialog({+ open,+ jobId,+ jobLabel,+ stage,+ stageTypes,+ jobStatuses,+ onOpenChange,+ onSaved,+}: AddStageDialogProps) {+ const [isPending, startTransition] = useTransition();++ const form = useForm<AddJobStageValues>({+ resolver: zodResolver(AddJobStageFormSchema) as any,+ defaultValues: emptyValues(jobId),+ });++ const { reset } = form;++ // The host renders this dialog permanently and only flips `open`, so it+ // cannot call reset() itself — the same reason AddContact resets on open.+ useEffect(() => {+ if (!open) return;+ reset(stage ? editValues(jobId, stage) : emptyValues(jobId), {+ keepDefaultValues: true,+ });+ }, [open, stage, jobId, reset]);++ const customLabel = form.watch("customLabel");+ const isCustom = !!customLabel?.trim();+ const statusValue = isCustom+ ? jobStatuses.find((s) => s.id === form.watch("customStatusId"))?.value+ : stageTypes.find((t) => t.id === form.watch("stageTypeId"))?.Status?.value;+ const showInterviewFields = statusValue === "interview";++ // Nothing demotes a stage: stageDataFrom never writes isCurrent, so an+ // unticked box here would save without error and change nothing.+ const currentLocked = !!stage?.isCurrent;++ const onSubmit = (values: AddJobStageValues) => {+ startTransition(async () => {+ const res = stage+ ? await updateJobStage({ ...values, id: stage.id })+ : await addJobStage(values);+ toastActionResult(res, {+ success: `Stage has been ${stage ? "updated" : "added"} successfully`,+ onSuccess: () => {+ onSaved();+ onOpenChange(false);+ },+ });+ });+ };++ return (+ <Dialog open={open} onOpenChange={onOpenChange}>+ <DialogContent className="sm:max-w-[480px] max-h-[85vh] overflow-y-auto">+ <DialogHeader>+ <DialogTitle>{stage ? "Edit Stage" : "Add Stage"}</DialogTitle>+ <DialogDescription>{jobLabel}</DialogDescription>+ </DialogHeader>+ <Form {...form}>+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4 p-1">+ <FormField+ control={form.control}+ name="stageTypeId"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>STAGE</FormLabel>+ <div data-testid="stage-type-select">+ <Combobox+ options={stageTypes}+ field={field}+ fullWidth+ label="stage"+ />+ </div>+ <FormMessage />+ </FormItem>+ )}+ />++ <FormField+ control={form.control}+ name="customLabel"+ render={({ field }) => (+ <FormItem>+ <FormLabel>OR ENTER A CUSTOM STAGE NAME</FormLabel>+ <FormControl>+ <Input+ placeholder="e.g. Panel Interview, Reference Check…"+ {...field}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ {isCustom && (+ <FormField+ control={form.control}+ name="customStatusId"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>PARENT STATUS</FormLabel>+ <SelectFormCtrl+ label="status"+ options={jobStatuses}+ field={field}+ />+ <FormMessage />+ </FormItem>+ )}+ />+ )}++ <div className="grid grid-cols-2 gap-4">+ <FormField+ control={form.control}+ name="date"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>DATE</FormLabel>+ <DatePicker+ field={field}+ presets={false}+ isEnabled+ captionLayout+ fullWidth+ />+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="time"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>TIME</FormLabel>+ <TimePicker field={field} />+ <FormMessage />+ </FormItem>+ )}+ />+ </div>++ {showInterviewFields && (+ <div className="grid grid-cols-2 gap-4">+ <FormField+ control={form.control}+ name="format"+ render={({ field }) => (+ <FormItem>+ <FormLabel>FORMAT</FormLabel>+ <FormControl>+ <Input placeholder="e.g. Video, Phone" {...field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="durationMins"+ render={({ field }) => (+ <FormItem>+ <FormLabel>DURATION (MIN)</FormLabel>+ <FormControl>+ <Input+ type="number"+ min={1}+ value={field.value ?? ""}+ onChange={(e) =>+ field.onChange(+ e.target.value ? Number(e.target.value) : null,+ )+ }+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <div className="col-span-2">+ <FormField+ control={form.control}+ name="location"+ render={({ field }) => (+ <FormItem>+ <FormLabel>LOCATION</FormLabel>+ <FormControl>+ <Input+ placeholder="e.g. 200 King St W, or a meeting link"+ {...field}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </div>+ </div>+ )}++ {stage && (+ <FormField+ control={form.control}+ name="outcome"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <FormLabel>OUTCOME</FormLabel>+ <SelectFormCtrl+ label="outcome"+ options={OUTCOME_OPTIONS}+ field={{ ...field, value: field.value ?? "" }}+ />+ <FormMessage />+ </FormItem>+ )}+ />+ )}++ <FormField+ control={form.control}+ name="notes"+ render={({ field }) => (+ <FormItem>+ <FormLabel>NOTES (OPTIONAL)</FormLabel>+ <FormControl>+ <Textarea+ className="min-h-20"+ placeholder="Add any context for this stage…"+ {...field}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ <FormField+ control={form.control}+ name="setAsCurrent"+ render={({ field }) => (+ <FormItem>+ <label className="flex cursor-pointer items-center gap-2.5">+ <input+ type="checkbox"+ className="h-4 w-4 shrink-0"+ checked={!!field.value}+ disabled={currentLocked}+ onChange={(e) => field.onChange(e.target.checked)}+ />+ <span className="text-[13px]">Set as current stage</span>+ </label>+ {currentLocked && (+ <p className="text-xs text-muted-foreground">+ This is the current stage — tick the box on another stage+ to move it.+ </p>+ )}+ </FormItem>+ )}+ />++ <DialogFooter>+ <Button+ type="button"+ variant="outline"+ onClick={() => onOpenChange(false)}+ >+ Cancel+ </Button>+ <Button type="submit" disabled={isPending}>+ {stage ? "Save Changes" : "Add Stage"}+ {isPending && <Loader className="h-4 w-4 shrink-0 spinner" />}+ </Button>+ </DialogFooter>+ </form>+ </Form>+ </DialogContent>+ </Dialog>+ );+}