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.

fix(contacts): lift the job contact links into JobDetails so the tab count updates on add

Khuram Niaz5ef9c3eb1b8a
diff --git a/__tests__/JobContactsTab.spec.tsx b/__tests__/JobContactsTab.spec.tsx
index a4d0785..f691d0f 100644
--- a/__tests__/JobContactsTab.spec.tsx
+++ b/__tests__/JobContactsTab.spec.tsx
@@ -70,7 +70,13 @@ describe("JobContactsTab", () => {
});
it("lists the linked contacts with their role", () => {
- render(<JobContactsTab jobId="j1" links={[link] as any} />);
+ render(
+ <JobContactsTab
+ jobId="j1"
+ links={[link] as any}
+ onLinksChange={vi.fn()}
+ />,
+ );
expect(screen.getByText("Sarah Cole")).toBeInTheDocument();
expect(screen.getByText("Recruiter")).toBeInTheDocument();
});
@@ -80,28 +86,52 @@ describe("JobContactsTab", () => {
...link,
Contact: { ...link.Contact, lastContactedAt: new Date(2026, 7, 1) },
};
- render(<JobContactsTab jobId="j1" links={[contacted] as any} />);
+ render(
+ <JobContactsTab
+ jobId="j1"
+ links={[contacted] as any}
+ onLinksChange={vi.fn()}
+ />,
+ );
expect(screen.getByText(/last contacted aug 1, 2026/i)).toBeInTheDocument();
});
it("omits the last contacted date when the contact has none", () => {
- render(<JobContactsTab jobId="j1" links={[link] as any} />);
+ render(
+ <JobContactsTab
+ jobId="j1"
+ links={[link] as any}
+ onLinksChange={vi.fn()}
+ />,
+ );
expect(screen.queryByText(/last contacted/i)).not.toBeInTheDocument();
});
it("shows an empty state with no links", () => {
- render(<JobContactsTab jobId="j1" links={[]} />);
+ render(<JobContactsTab jobId="j1" links={[]} onLinksChange={vi.fn()} />);
expect(screen.getByText(/no contacts on this job/i)).toBeInTheDocument();
});
it("does not fetch the picker lists until the add form is opened", () => {
- render(<JobContactsTab jobId="j1" links={[link] as any} />);
+ render(
+ <JobContactsTab
+ jobId="j1"
+ links={[link] as any}
+ onLinksChange={vi.fn()}
+ />,
+ );
expect(getAllContacts).not.toHaveBeenCalled();
expect(getAllContactRoles).not.toHaveBeenCalled();
});
it("fetches contacts and roles on first open of the add form", async () => {
- render(<JobContactsTab jobId="j1" links={[link] as any} />);
+ render(
+ <JobContactsTab
+ jobId="j1"
+ links={[link] as any}
+ onLinksChange={vi.fn()}
+ />,
+ );
await user.click(screen.getByRole("button", { name: /add contact/i }));
await waitFor(() => expect(getAllContacts).toHaveBeenCalledTimes(1));
@@ -113,15 +143,23 @@ describe("JobContactsTab", () => {
expect(getAllContacts).toHaveBeenCalledTimes(1);
});
- it("unlinks a contact and refreshes the list", async () => {
+ it("unlinks a contact and hands the refreshed list to the parent", async () => {
(removeJobContact as any).mockResolvedValue({ success: true });
(getJobContacts as any).mockResolvedValue([]);
-
- render(<JobContactsTab jobId="j1" links={[link] as any} />);
+ const onLinksChange = vi.fn();
+
+ render(
+ <JobContactsTab
+ jobId="j1"
+ links={[link] as any}
+ onLinksChange={onLinksChange}
+ />,
+ );
await user.click(screen.getByRole("button", { name: /remove sarah cole/i }));
await user.click(await screen.findByRole("button", { name: "Delete" }));
await waitFor(() => expect(removeJobContact).toHaveBeenCalledWith("jc1"));
await waitFor(() => expect(getJobContacts).toHaveBeenCalledWith("j1"));
+ await waitFor(() => expect(onLinksChange).toHaveBeenCalledWith([]));
});
});
diff --git a/src/components/myjobs/JobDetails.tsx b/src/components/myjobs/JobDetails.tsx
index 2ac3673..4c5e849 100644
--- a/src/components/myjobs/JobDetails.tsx
+++ b/src/components/myjobs/JobDetails.tsx
@@ -93,6 +93,7 @@ function JobDetails({
const [deleteAlertOpen, setDeleteAlertOpen] = useState(false);
const [noteOpenTrigger, setNoteOpenTrigger] = useState(0);
const [notesCount, setNotesCount] = useState(0);
+ const [contactLinks, setContactLinks] = useState(job.contactLinks ?? []);
const {
stages,
currentStage,
@@ -250,9 +251,9 @@ function JobDetails({
<TabsTrigger value="letter">Cover Letter</TabsTrigger>
<TabsTrigger value="contacts">
Contacts
- {(job.contactLinks?.length ?? 0) > 0 && (
+ {contactLinks.length > 0 && (
<Badge variant="secondary" className="ml-2">
- {job.contactLinks!.length}
+ {contactLinks.length}
</Badge>
)}
</TabsTrigger>
@@ -328,7 +329,8 @@ function JobDetails({
<Card className="p-6">
<JobContactsTab
jobId={job.id}
- links={job.contactLinks ?? []}
+ links={contactLinks}
+ onLinksChange={setContactLinks}
companies={companies}
locations={locations}
/>
diff --git a/src/components/myjobs/job-details/JobContactsTab.tsx b/src/components/myjobs/job-details/JobContactsTab.tsx
index 5636e1d..007d3a6 100644
--- a/src/components/myjobs/job-details/JobContactsTab.tsx
+++ b/src/components/myjobs/job-details/JobContactsTab.tsx
@@ -24,6 +24,7 @@ import { AddJobContactForm } from "./AddJobContactForm";
type JobContactsTabProps = {
jobId: string;
links: JobContactLink[];
+ onLinksChange: (links: JobContactLink[]) => void;
companies?: Company[];
locations?: JobLocation[];
};
@@ -31,10 +32,10 @@ type JobContactsTabProps = {
export function JobContactsTab({
jobId,
links,
+ onLinksChange,
companies = [],
locations = [],
}: JobContactsTabProps) {
- const [rows, setRows] = useState<JobContactLink[]>(links);
const [showForm, setShowForm] = useState(false);
const [contacts, setContacts] = useState<ContactRef[]>([]);
const [roles, setRoles] = useState<ContactRole[]>([]);
@@ -57,7 +58,7 @@ export function JobContactsTab({
const reload = async () => {
const fresh = await getJobContacts(jobId);
- if (Array.isArray(fresh)) setRows(fresh);
+ if (Array.isArray(fresh)) onLinksChange(fresh);
};
const onRemove = async () => {
@@ -72,7 +73,7 @@ export function JobContactsTab({
return (
<div className="space-y-4">
- {rows.length > 0 && !showForm && (
+ {links.length > 0 && !showForm && (
<div className="flex justify-end">
<Button
variant="outline"
@@ -102,7 +103,7 @@ export function JobContactsTab({
/>
)}
- {rows.length === 0 && !showForm && (
+ {links.length === 0 && !showForm && (
<JobTabEmptyState
icon={Users}
title="No contacts on this job"
@@ -112,9 +113,9 @@ export function JobContactsTab({
/>
)}
- {rows.length > 0 && (
+ {links.length > 0 && (
<ul className="space-y-2">
- {rows.map((row) => (
+ {links.map((row) => (
<li
key={row.id}
className="flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md border p-3 text-sm"