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 Link Interviewers dialog with inline contact creation, and widen getAllContacts with title and company
Khuram Niazb6f0a834bf84
diff --git a/__tests__/LinkInterviewersDialog.spec.tsx b/__tests__/LinkInterviewersDialog.spec.tsxnew file mode 100644index 0000000..44a1383--- /dev/null+++ b/__tests__/LinkInterviewersDialog.spec.tsx@@ -0,0 +1,77 @@+import { render, screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { LinkInterviewersDialog } from "@/components/myjobs/job-details/timeline/LinkInterviewersDialog";+import { linkStageInterviewer } from "@/actions/jobStage.actions";+import { getAllContacts } from "@/actions/contact.actions";++vi.mock("@/actions/jobStage.actions", () => ({+ linkStageInterviewer: vi.fn().mockResolvedValue({ success: true, data: { id: "iv2" } }),+}));+vi.mock("@/actions/contact.actions", () => ({+ getAllContacts: vi.fn(),+ createContact: vi.fn().mockResolvedValue({ success: true, data: { id: "c9", name: "New Person" } }),+}));+vi.mock("@/lib/toast", () => ({+ toastActionResult: vi.fn((res, opts) => res.success && opts.onSuccess?.()),+ toastSuccess: vi.fn(),+ toastError: vi.fn(),+}));++const stage = {+ id: "st1",+ occurredAt: new Date(2026, 8, 24, 10, 0),+ StageType: { label: "Final / Onsite Interview", Status: { value: "interview" } },+ interviewers: [{ id: "iv1", contactId: "c1", Contact: { id: "c1", name: "Priya Nair" } }],+} as any;++beforeEach(() => {+ vi.clearAllMocks();+ (getAllContacts as any).mockResolvedValue([+ { id: "c1", label: "Priya Nair", title: "VP Engineering", company: "Acme Corp", value: "priya nair vp engineering acme" },+ { id: "c2", label: "John Smith", title: "Engineering Manager", company: "Acme Corp", value: "john smith engineering manager acme" },+ ]);+});++describe("LinkInterviewersDialog", () => {+ it("heads the dialog with the target stage and its date", async () => {+ render(<LinkInterviewersDialog open stage={stage} onOpenChange={() => {}} onLinked={() => {}} />);++ expect(+ await screen.findByText("Final / Onsite Interview · Sep 24, 2026"),+ ).toBeInTheDocument();+ });++ it("marks an already-linked contact and offers no Add button for them", async () => {+ render(<LinkInterviewersDialog open stage={stage} onOpenChange={() => {}} onLinked={() => {}} />);++ expect(await screen.findByText("Priya Nair")).toBeInTheDocument();+ expect(screen.getByText("VP Engineering · Acme Corp")).toBeInTheDocument();+ expect(screen.getByLabelText(/Priya Nair is already linked/)).toBeInTheDocument();+ expect(screen.getByRole("button", { name: /Add John Smith/ })).toBeInTheDocument();+ });++ it("filters the list by the search box", async () => {+ render(<LinkInterviewersDialog open stage={stage} onOpenChange={() => {}} onLinked={() => {}} />);+ await screen.findByText("John Smith");++ await userEvent.type(+ screen.getByPlaceholderText("Search contacts by name or company…"),+ "john",+ );++ expect(screen.queryByText("Priya Nair")).toBeNull();+ expect(screen.getByText("John Smith")).toBeInTheDocument();+ });++ it("links a contact and reports the running count on the Done button", async () => {+ render(<LinkInterviewersDialog open stage={stage} onOpenChange={() => {}} onLinked={() => {}} />);+ await screen.findByText("John Smith");++ await userEvent.click(screen.getByRole("button", { name: /Add John Smith/ }));++ expect(linkStageInterviewer).toHaveBeenCalledWith("st1", "c2");+ expect(+ await screen.findByRole("button", { name: "Done — 1 interviewer linked" }),+ ).toBeInTheDocument();+ });+});diff --git a/__tests__/contact.actions.spec.ts b/__tests__/contact.actions.spec.tsindex 86e2da7..4620971 100644--- a/__tests__/contact.actions.spec.ts+++ b/__tests__/contact.actions.spec.ts@@ -80,15 +80,34 @@ describe("contact actions", () => {describe("getAllContacts", () => {it("returns picker rows whose value carries the email, so search finds it", async () => {db.contact.findMany.mockResolvedValue([- { id: "c1", name: "Dave Patel", email: "[email protected]", Company: { label: "Shopify" } },+ { id: "c1", name: "Dave Patel", title: "CTO", email: "[email protected]", Company: { label: "Shopify" } },]);const res = await getAllContacts();expect(res).toEqual([- { id: "c1", label: "Dave Patel", value: "dave patel [email protected] shopify" },+ {+ id: "c1",+ label: "Dave Patel",+ title: "CTO",+ company: "Shopify",+ value: "dave patel [email protected] shopify",+ },]);});++ // The Link Interviewers dialog shows "<title> · <company>" beneath the+ // name, which the search blob alone cannot be taken apart into.+ it("carries the title and company as their own fields", async () => {+ db.contact.findMany.mockResolvedValue([+ { id: "c2", name: "Priya Nair", title: null, email: null, Company: null },+ ]);++ const res = await getAllContacts();++ expect(res[0].title).toBeNull();+ expect(res[0].company).toBeNull();+ });});describe("createContact", () => {diff --git a/src/actions/contact/queries.ts b/src/actions/contact/queries.tsindex 4631449..0c4af44 100644--- a/src/actions/contact/queries.ts+++ b/src/actions/contact/queries.ts@@ -62,6 +62,7 @@ export const getAllContacts = async (): Promise<any | undefined> => {select: {id: true,name: true,+ title: true,email: true,Company: { select: { label: true } },},@@ -71,6 +72,9 @@ export const getAllContacts = async (): Promise<any | undefined> => {return rows.map((row) => ({id: row.id,label: row.name,+ // For pickers that show more than a name (the Link Interviewers dialog).+ title: row.title,+ company: row.Company?.label ?? null,value: [row.name, row.email, row.Company?.label].filter(Boolean).join(" ")diff --git a/src/components/myjobs/JobDetails.tsx b/src/components/myjobs/JobDetails.tsxindex 5498702..ddc1f15 100644--- a/src/components/myjobs/JobDetails.tsx+++ b/src/components/myjobs/JobDetails.tsx@@ -44,6 +44,7 @@ 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 { LinkInterviewersDialog } from "./job-details/timeline/LinkInterviewersDialog";import type { JobStage, JobStageTypeRef } from "@/models/jobStage.model";const JOB_DETAIL_TABS = [@@ -358,6 +359,15 @@ function JobDetails({router.refresh();}}/>+ <LinkInterviewersDialog+ open={linkInterviewersOpen}+ stage={selectedStage ?? currentStage}+ onOpenChange={setLinkInterviewersOpen}+ onLinked={() => {+ void reloadStages();+ router.refresh();+ }}+ /><DeleteAlertDialogpageTitle="job"open={deleteAlertOpen}diff --git a/src/components/myjobs/job-details/timeline/LinkInterviewersDialog.tsx b/src/components/myjobs/job-details/timeline/LinkInterviewersDialog.tsxnew file mode 100644index 0000000..81c6ecd--- /dev/null+++ b/src/components/myjobs/job-details/timeline/LinkInterviewersDialog.tsx@@ -0,0 +1,255 @@+"use client";+import { useEffect, useRef, useState, useTransition } from "react";+import { Check, Search } from "lucide-react";+import { Button } from "@/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "@/components/ui/dialog";+import { Input } from "@/components/ui/input";+import { toastActionResult } from "@/lib/toast";+import { createContact, getAllContacts } from "@/actions/contact.actions";+import { linkStageInterviewer } from "@/actions/jobStage.actions";+import type { JobStage } from "@/models/jobStage.model";+import { stageHeading, stageInitials } from "./stageDisplay";++type ContactRow = {+ id: string;+ label: string;+ title: string | null;+ company: string | null;+ value: string;+};++type LinkInterviewersDialogProps = {+ open: boolean;+ stage: JobStage | null;+ onOpenChange: (open: boolean) => void;+ onLinked: () => void;+};++const EMPTY_NEW = { name: "", title: "", email: "" };++// createContact parses the whole contact form; the untouched optional fields+// arrive as "" and toContactData normalises them to null.+const contactPayload = (fields: typeof EMPTY_NEW) => ({+ ...fields,+ phone: "",+ linkedinUrl: "",+ company: "",+ location: "",+ relationship: "",+ workedAtCompany: "",+ contactRole: "",+ workedFrom: null,+ workedTo: null,+ notes: "",+ lastContactedAt: null,+});++export function LinkInterviewersDialog({+ open,+ stage,+ onOpenChange,+ onLinked,+}: LinkInterviewersDialogProps) {+ const [contacts, setContacts] = useState<ContactRow[]>([]);+ const [search, setSearch] = useState("");+ const [linkedIds, setLinkedIds] = useState<string[]>([]);+ const [linkedCount, setLinkedCount] = useState(0);+ const [newContact, setNewContact] = useState(EMPTY_NEW);+ const [isPending, startTransition] = useTransition();+ const loaded = useRef(false);++ // Loaded on first open only — the job page already fires many queries.+ useEffect(() => {+ if (!open || loaded.current) return;+ loaded.current = true;+ void (async () => {+ const rows = await getAllContacts();+ if (Array.isArray(rows)) setContacts(rows);+ })();+ }, [open]);++ useEffect(() => {+ if (!open) return;+ setSearch("");+ setLinkedCount(0);+ setNewContact(EMPTY_NEW);+ setLinkedIds((stage?.interviewers ?? []).map((iv) => iv.contactId));+ }, [open, stage]);++ if (!stage) return null;++ const term = search.trim().toLowerCase();+ const visible = term+ ? contacts.filter((c) => c.value.includes(term))+ : contacts;++ const link = (contactId: string) =>+ startTransition(async () => {+ const res = await linkStageInterviewer(stage.id, contactId);+ toastActionResult(res, {+ success: "Interviewer has been linked successfully",+ onSuccess: () => {+ setLinkedIds((prev) => [...prev, contactId]);+ setLinkedCount((n) => n + 1);+ onLinked();+ },+ });+ });++ const addAndLink = () =>+ startTransition(async () => {+ const res = await createContact(contactPayload(newContact));+ toastActionResult(res, {+ success: "Contact has been created successfully",+ onSuccess: () => {+ const row: ContactRow = {+ id: res.data.id,+ label: newContact.name.trim(),+ title: newContact.title.trim() || null,+ company: null,+ value: `${newContact.name} ${newContact.email}`.toLowerCase(),+ };+ setContacts((prev) => [row, ...prev]);+ setNewContact(EMPTY_NEW);+ link(row.id);+ },+ });+ });++ const doneLabel =+ linkedCount === 0+ ? "Done"+ : `Done — ${linkedCount} interviewer${linkedCount === 1 ? "" : "s"} linked`;++ return (+ <Dialog open={open} onOpenChange={onOpenChange}>+ <DialogContent className="sm:max-w-[520px] max-h-[720px] overflow-hidden">+ <DialogHeader>+ <DialogTitle>Link Interviewer</DialogTitle>+ <DialogDescription>{stageHeading(stage)}</DialogDescription>+ </DialogHeader>++ <div className="max-h-[60vh] space-y-4 overflow-y-auto p-1">+ <div className="relative">+ <Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />+ <Input+ className="pl-9"+ placeholder="Search contacts by name or company…"+ value={search}+ onChange={(e) => setSearch(e.target.value)}+ />+ </div>++ <ul className="overflow-hidden rounded-lg border">+ {visible.length === 0 && (+ <li className="px-3.5 py-4 text-[13px] text-muted-foreground">+ No contacts match that search.+ </li>+ )}+ {visible.map((contact, index) => {+ const isLinked = linkedIds.includes(contact.id);+ const sub = [contact.title, contact.company]+ .filter(Boolean)+ .join(" · ");+ return (+ <li+ key={contact.id}+ className={`flex items-center gap-3 px-3.5 py-2.5 ${+ index > 0 ? "border-t" : ""+ }`}+ >+ <span className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary/15 text-[11px] font-bold text-primary">+ {stageInitials(contact.label)}+ </span>+ <span className="min-w-0 flex-1">+ <span className="block truncate text-[13px] font-semibold">+ {contact.label}+ </span>+ {sub && (+ <span className="block truncate text-xs text-muted-foreground">+ {sub}+ </span>+ )}+ </span>+ {isLinked ? (+ <span+ aria-label={`${contact.label} is already linked`}+ className="flex h-6 w-6 items-center justify-center rounded-full bg-emerald-500/15 text-emerald-600 dark:text-emerald-300"+ >+ <Check className="h-3.5 w-3.5" />+ </span>+ ) : (+ <Button+ size="sm"+ variant="outline"+ disabled={isPending}+ onClick={() => link(contact.id)}+ >+ <span className="sr-only">Add {contact.label}</span>+ <span aria-hidden="true">Add</span>+ </Button>+ )}+ </li>+ );+ })}+ </ul>++ <div className="space-y-3 rounded-lg border border-dashed p-3.5">+ <p className="text-[13px] font-semibold">Add a new contact</p>+ <div className="grid grid-cols-2 gap-3">+ <Input+ placeholder="Full name"+ aria-label="Full name"+ value={newContact.name}+ onChange={(e) =>+ setNewContact((v) => ({ ...v, name: e.target.value }))+ }+ />+ <Input+ placeholder="Role / title"+ aria-label="Role / title"+ value={newContact.title}+ onChange={(e) =>+ setNewContact((v) => ({ ...v, title: e.target.value }))+ }+ />+ <div className="col-span-2">+ <Input+ type="email"+ placeholder="Email"+ aria-label="Email"+ value={newContact.email}+ onChange={(e) =>+ setNewContact((v) => ({ ...v, email: e.target.value }))+ }+ />+ </div>+ </div>+ <Button+ size="sm"+ variant="outline"+ disabled={isPending || !newContact.name.trim()}+ onClick={addAndLink}+ >+ Add Contact+ </Button>+ </div>+ </div>++ <DialogFooter>+ <Button variant="outline" onClick={() => onOpenChange(false)}>+ Cancel+ </Button>+ <Button onClick={() => onOpenChange(false)}>{doneLabel}</Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ );+}diff --git a/src/components/myjobs/job-details/timeline/stageDisplay.ts b/src/components/myjobs/job-details/timeline/stageDisplay.tsindex 7aee4f2..a48453f 100644--- a/src/components/myjobs/job-details/timeline/stageDisplay.ts+++ b/src/components/myjobs/job-details/timeline/stageDisplay.ts@@ -22,6 +22,14 @@ export function formatStageDateTime(: withDuration;}+// The subtitle both stage dialogs put under their title.+export function stageHeading(stage: JobStage): string {+ const label = stage.StageType?.label ?? "Stage";+ return stage.occurredAt+ ? `${label} · ${format(stage.occurredAt, "MMM d, yyyy")}`+ : label;+}+export function stageInitials(name: string): string {const parts = name.trim().split(/\s+/).filter(Boolean);if (parts.length === 0) return "?";