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.

feat(interviews): add the interview list query, filter options, display helpers and a narrow stage-outcome action

Khuram Niaz70f21a6e311e
diff --git a/__tests__/interview.actions.spec.ts b/__tests__/interview.actions.spec.ts
new file mode 100644
index 0000000..28fd8ad
--- /dev/null
+++ b/__tests__/interview.actions.spec.ts
@@ -0,0 +1,145 @@
+import {
+ getInterviewList,
+ getInterviewFilterOptions,
+} from "@/actions/interview.actions";
+import { getCurrentUser } from "@/utils/user.utils";
+import prisma from "@/lib/db";
+
+vi.mock("@/lib/db", () => {
+ const jobStage = {
+ findMany: vi.fn(),
+ count: vi.fn(),
+ };
+ return { default: { jobStage } };
+});
+
+vi.mock("@/utils/user.utils", () => ({ getCurrentUser: vi.fn() }));
+
+const db = prisma as any;
+const user = { id: "user-1" };
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ (getCurrentUser as any).mockResolvedValue(user);
+ db.jobStage.findMany.mockResolvedValue([]);
+ db.jobStage.count.mockResolvedValue(0);
+});
+
+describe("getInterviewList", () => {
+ it("reads only interview-status stages owned through the job", async () => {
+ await getInterviewList("all");
+
+ const where = db.jobStage.findMany.mock.calls[0][0].where;
+ expect(where.Job).toEqual({ userId: user.id });
+ expect(where.StageType).toEqual({ Status: { value: "interview" } });
+ });
+
+ it("treats undated rounds as upcoming and orders them first", async () => {
+ await getInterviewList("upcoming");
+
+ const args = db.jobStage.findMany.mock.calls[0][0];
+ expect(args.where.OR).toEqual([
+ { occurredAt: { gte: expect.any(Date) } },
+ { occurredAt: null },
+ ]);
+ // SQLite sorts NULL first on ASC, which is what puts undated rounds on top
+ expect(args.orderBy[0]).toEqual({ occurredAt: "asc" });
+ });
+
+ it("orders past rounds newest first over a set with no undated rows", async () => {
+ await getInterviewList("past");
+
+ const args = db.jobStage.findMany.mock.calls[0][0];
+ expect(args.where.occurredAt).toEqual({ lt: expect.any(Date) });
+ expect(args.where.OR).toBeUndefined();
+ expect(args.orderBy[0]).toEqual({ occurredAt: "desc" });
+ });
+
+ it("pins undated rounds to page 1 of the All view", async () => {
+ db.jobStage.findMany
+ .mockResolvedValueOnce([{ id: "dated" }])
+ .mockResolvedValueOnce([{ id: "undated" }]);
+ db.jobStage.count.mockResolvedValue(2);
+
+ const res = await getInterviewList("all", 1);
+
+ // The paged query excludes NULLs; SQLite sorts them last on DESC, which
+ // would otherwise strand them on the final page.
+ expect(db.jobStage.findMany.mock.calls[0][0].where.occurredAt).toEqual({
+ not: null,
+ });
+ expect(db.jobStage.findMany.mock.calls[1][0].where.occurredAt).toBeNull();
+ expect(res.data.map((r: any) => r.id)).toEqual(["undated", "dated"]);
+ expect(res.total).toBe(2);
+ });
+
+ it("does not re-fetch the pinned rows on later pages", async () => {
+ await getInterviewList("all", 2);
+
+ expect(db.jobStage.findMany).toHaveBeenCalledTimes(1);
+ });
+
+ it("filters by round, company and search together", async () => {
+ await getInterviewList("all", 1, 25, "acme", "type-1", "co-1");
+
+ const where = db.jobStage.findMany.mock.calls[0][0].where;
+ expect(where.AND).toEqual([
+ { stageTypeId: "type-1" },
+ { Job: { companyId: "co-1" } },
+ {
+ OR: [
+ { Job: { JobTitle: { label: { contains: "acme" } } } },
+ { Job: { Company: { label: { contains: "acme" } } } },
+ { StageType: { label: { contains: "acme" } } },
+ { interviewers: { some: { Contact: { name: { contains: "acme" } } } } },
+ ],
+ },
+ ]);
+ });
+
+ it("returns the error envelope when there is no session", async () => {
+ (getCurrentUser as any).mockResolvedValue(null);
+
+ const res = await getInterviewList("all");
+
+ expect(res).toEqual({ success: false, message: "Not authenticated" });
+ });
+});
+
+describe("getInterviewFilterOptions", () => {
+ it("offers only rounds and companies that actually have interviews", async () => {
+ db.jobStage.findMany.mockResolvedValue([
+ {
+ stageTypeId: "t-final",
+ StageType: { label: "Final / Onsite Interview", sortOrder: 6 },
+ Job: { companyId: "c-north", Company: { label: "Northwind Labs" } },
+ },
+ {
+ stageTypeId: "t-screen",
+ StageType: { label: "1st Screening Interview", sortOrder: 4 },
+ Job: { companyId: "c-acme", Company: { label: "Acme Health" } },
+ },
+ {
+ stageTypeId: "t-screen",
+ StageType: { label: "1st Screening Interview", sortOrder: 4 },
+ Job: { companyId: "c-north", Company: { label: "Northwind Labs" } },
+ },
+ ]);
+
+ const res = await getInterviewFilterOptions();
+
+ expect(db.jobStage.findMany.mock.calls[0][0].where).toEqual({
+ Job: { userId: user.id },
+ StageType: { Status: { value: "interview" } },
+ });
+ // De-duplicated; rounds in Library order, companies alphabetically
+ expect(res.rounds).toEqual([
+ { id: "t-screen", label: "1st Screening Interview" },
+ { id: "t-final", label: "Final / Onsite Interview" },
+ ]);
+ expect(res.companies).toEqual([
+ { id: "c-acme", label: "Acme Health" },
+ { id: "c-north", label: "Northwind Labs" },
+ ]);
+ });
+});
diff --git a/__tests__/interviewDisplay.spec.ts b/__tests__/interviewDisplay.spec.ts
new file mode 100644
index 0000000..3ff7ea6
--- /dev/null
+++ b/__tests__/interviewDisplay.spec.ts
@@ -0,0 +1,125 @@
+import {
+ outcomeLabel,
+ outcomeTone,
+ formatIconKind,
+ formatText,
+ durationLabel,
+ whenParts,
+ interviewerSummary,
+ prepSummary,
+} from "@/components/interviews/interviewDisplay";
+
+const now = new Date("2026-09-21T12:00:00Z");
+
+describe("outcomeLabel", () => {
+ it("prefers the stored outcome over anything derived", () => {
+ expect(outcomeLabel(new Date("2026-09-30T10:00:00Z"), "failed", now)).toBe(
+ "Failed",
+ );
+ });
+
+ it("derives Scheduled for a round still ahead", () => {
+ expect(outcomeLabel(new Date("2026-09-23T10:00:00Z"), null, now)).toBe(
+ "Scheduled",
+ );
+ });
+
+ it("derives Awaiting outcome for a round already past", () => {
+ expect(outcomeLabel(new Date("2026-09-12T10:00:00Z"), null, now)).toBe(
+ "Awaiting outcome",
+ );
+ });
+
+ it("derives Not scheduled for a round with no date", () => {
+ expect(outcomeLabel(null, null, now)).toBe("Not scheduled");
+ });
+
+ it("ignores an outcome value that is not in the fixed set", () => {
+ expect(outcomeLabel(null, "ghosted", now)).toBe("Not scheduled");
+ });
+});
+
+describe("outcomeTone", () => {
+ it("marks a bad ending destructive and a good one default", () => {
+ expect(outcomeTone("Failed")).toBe("destructive");
+ expect(outcomeTone("No-show")).toBe("destructive");
+ expect(outcomeTone("Passed")).toBe("default");
+ expect(outcomeTone("Scheduled")).toBe("outline");
+ expect(outcomeTone("Not scheduled")).toBe("secondary");
+ });
+});
+
+describe("formatIconKind", () => {
+ it("recognises the common video and phone wordings", () => {
+ expect(formatIconKind("Video")).toBe("video");
+ expect(formatIconKind("zoom call")).toBe("video");
+ expect(formatIconKind("MS Teams")).toBe("video");
+ expect(formatIconKind("Phone screen")).toBe("phone");
+ });
+
+ it("falls back to a pin for anything unfamiliar or empty", () => {
+ expect(formatIconKind("Onsite")).toBe("location");
+ expect(formatIconKind(null)).toBe("location");
+ });
+});
+
+describe("formatText", () => {
+ it("prefers the location, then the format, then a placeholder", () => {
+ expect(formatText("Video", "Google Meet")).toBe("Google Meet");
+ expect(formatText("Recruiter call", "")).toBe("Recruiter call");
+ expect(formatText(null, null)).toBe("Not set");
+ });
+});
+
+describe("durationLabel", () => {
+ it("renders whole hours as hours and everything else as minutes", () => {
+ expect(durationLabel(180)).toBe("3h");
+ expect(durationLabel(90)).toBe("90m");
+ expect(durationLabel(30)).toBe("30m");
+ expect(durationLabel(null)).toBeNull();
+ });
+});
+
+describe("whenParts", () => {
+ it("splits a date into a day line and a time line", () => {
+ expect(whenParts(new Date("2026-09-23T14:30:00"))).toEqual({
+ day: "Wed 23 Sep",
+ time: "2:30 PM",
+ });
+ });
+
+ it("says No date rather than inventing one", () => {
+ expect(whenParts(null)).toEqual({ day: "No date", time: null });
+ });
+});
+
+describe("interviewerSummary", () => {
+ const person = (name: string) => ({ Contact: { name } });
+
+ it("abbreviates up to two names", () => {
+ expect(
+ interviewerSummary([person("Ayesha Rahman"), person("Jordan Pike")]),
+ ).toBe("A. Rahman, J. Pike");
+ });
+
+ it("counts three or more", () => {
+ expect(
+ interviewerSummary([person("A B"), person("C D"), person("E F")]),
+ ).toBe("3 interviewers");
+ });
+
+ it("says when nobody is linked", () => {
+ expect(interviewerSummary([])).toBe("None linked");
+ });
+});
+
+describe("prepSummary", () => {
+ it("shows asked over total once anything has been asked", () => {
+ expect(prepSummary([{ asked: true }, { asked: false }])).toBe("1 / 2");
+ });
+
+ it("shows the plain total when nothing has been asked", () => {
+ expect(prepSummary([{ asked: false }, { asked: false }])).toBe("2");
+ expect(prepSummary([])).toBe("0");
+ });
+});
diff --git a/__tests__/jobStage.actions.spec.ts b/__tests__/jobStage.actions.spec.ts
index 0772740..22da0df 100644
--- a/__tests__/jobStage.actions.spec.ts
+++ b/__tests__/jobStage.actions.spec.ts
@@ -4,6 +4,7 @@ import {
deleteJobStage,
setCurrentJobStage,
setStageNotes,
+ setStageOutcome,
} from "@/actions/jobStage.actions";
import { getCurrentUser } from "@/utils/user.utils";
import prisma from "@/lib/db";
@@ -406,3 +407,48 @@ describe("setStageNotes", () => {
});
});
});
+
+describe("setStageOutcome", () => {
+ beforeEach(() => {
+ db.jobStage.findFirst.mockResolvedValue({
+ id: "s1",
+ jobId: "j1",
+ occurredAt: null,
+ isCurrent: true,
+ StageType: interviewType,
+ });
+ });
+
+ it("writes the outcome scoped through the job's owner", async () => {
+ const res = await setStageOutcome("s1", "passed");
+
+ expect(db.jobStage.updateMany).toHaveBeenCalledWith({
+ where: { id: "s1", Job: { userId: user.id } },
+ data: { outcome: "passed" },
+ });
+ expect(res.success).toBe(true);
+ });
+
+ it("clears the outcome when given null", async () => {
+ await setStageOutcome("s1", null);
+
+ expect(db.jobStage.updateMany.mock.calls[0][0].data).toEqual({
+ outcome: null,
+ });
+ });
+
+ it("rejects an outcome that is not in STAGE_OUTCOMES", async () => {
+ const res = await setStageOutcome("s1", "ghosted");
+
+ expect(res.success).toBe(false);
+ expect(db.jobStage.updateMany).not.toHaveBeenCalled();
+ });
+
+ it("refuses a stage that is not the caller's", async () => {
+ db.jobStage.findFirst.mockResolvedValue(null);
+
+ const res = await setStageOutcome("s1", "passed");
+
+ expect(res).toEqual({ success: false, message: "Stage not found" });
+ });
+});
diff --git a/src/actions/interview.actions.ts b/src/actions/interview.actions.ts
new file mode 100644
index 0000000..578a18b
--- /dev/null
+++ b/src/actions/interview.actions.ts
@@ -0,0 +1,161 @@
+"use server";
+import prisma from "@/lib/db";
+import { handleError } from "@/lib/utils";
+import { requireUser } from "./shared";
+import { APP_CONSTANTS } from "@/lib/constants";
+import { STAGE_DETAIL_INCLUDE } from "./jobStage/shared";
+import type { InterviewView } from "@/models/interview.model";
+
+// The same include the Timeline tab uses, so a row from this list is a
+// complete JobStage and can be handed straight to AddStageDialog.
+const INTERVIEW_LIST_INCLUDE = {
+ ...STAGE_DETAIL_INCLUDE,
+ Job: {
+ select: {
+ id: true,
+ JobTitle: { select: { label: true } },
+ Company: { select: { id: true, label: true } },
+ },
+ },
+};
+
+const buildInterviewWhere = (
+ userId: string,
+ view: InterviewView,
+ now: Date,
+ search?: string,
+ stageTypeId?: string,
+ companyId?: string,
+) => {
+ const where: any = {
+ Job: { userId },
+ StageType: { Status: { value: "interview" } },
+ };
+
+ if (view === "upcoming") {
+ where.OR = [{ occurredAt: { gte: now } }, { occurredAt: null }];
+ } else if (view === "past") {
+ where.occurredAt = { lt: now };
+ }
+
+ // AND, because the upcoming window already owns the top-level OR.
+ const and: any[] = [];
+ if (stageTypeId) and.push({ stageTypeId });
+ if (companyId) and.push({ Job: { companyId } });
+ if (search) {
+ and.push({
+ OR: [
+ { Job: { JobTitle: { label: { contains: search } } } },
+ { Job: { Company: { label: { contains: search } } } },
+ { StageType: { label: { contains: search } } },
+ { interviewers: { some: { Contact: { name: { contains: search } } } } },
+ ],
+ });
+ }
+ if (and.length > 0) where.AND = and;
+
+ return where;
+};
+
+// Ordering stays in the query because the list is server-paged. SQLite sorts
+// NULL first on ASC, which is exactly the undated-first rule the Upcoming view
+// wants, and the Past view's set holds no NULLs at all.
+const interviewOrderBy = (view: InterviewView) =>
+ view === "upcoming"
+ ? [{ occurredAt: "asc" as const }, { createdAt: "asc" as const }]
+ : [{ occurredAt: "desc" as const }, { createdAt: "desc" as const }];
+
+export const getInterviewList = async (
+ view: InterviewView = "upcoming",
+ page: number = 1,
+ limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,
+ search?: string,
+ stageTypeId?: string,
+ companyId?: string,
+): Promise<any | undefined> => {
+ try {
+ const user = await requireUser();
+ const now = new Date();
+ const where = buildInterviewWhere(
+ user.id,
+ view,
+ now,
+ search,
+ stageTypeId,
+ companyId,
+ );
+
+ // On DESC, SQLite sorts NULL last, which would bury every unscheduled
+ // round on the final page. All pages dated rows and pins the rest to 1.
+ const pinUndated = view === "all";
+ const pagedWhere = pinUndated
+ ? { ...where, occurredAt: { not: null } }
+ : where;
+
+ const [rows, total, pinned] = await Promise.all([
+ prisma.jobStage.findMany({
+ where: pagedWhere,
+ skip: (page - 1) * limit,
+ take: limit,
+ include: INTERVIEW_LIST_INCLUDE,
+ orderBy: interviewOrderBy(view),
+ }),
+ prisma.jobStage.count({ where }),
+ pinUndated && page === 1
+ ? prisma.jobStage.findMany({
+ where: { ...where, occurredAt: null },
+ include: INTERVIEW_LIST_INCLUDE,
+ orderBy: { createdAt: "desc" },
+ })
+ : Promise.resolve([]),
+ ]);
+
+ return { data: [...pinned, ...rows], total };
+ } catch (error) {
+ return handleError(error, "Failed to fetch interviews. ");
+ }
+};
+
+// Options come from rows that exist, not from the Library: offering every
+// stage type and every company would mostly offer empty results.
+export const getInterviewFilterOptions = async (): Promise<any | undefined> => {
+ try {
+ const user = await requireUser();
+ const rows = await prisma.jobStage.findMany({
+ where: {
+ Job: { userId: user.id },
+ StageType: { Status: { value: "interview" } },
+ },
+ select: {
+ stageTypeId: true,
+ StageType: { select: { label: true, sortOrder: true } },
+ Job: { select: { companyId: true, Company: { select: { label: true } } } },
+ },
+ });
+
+ const roundMap = new Map<string, { label: string; sortOrder: number }>();
+ const companyMap = new Map<string, string>();
+ for (const row of rows) {
+ roundMap.set(row.stageTypeId, {
+ label: row.StageType.label,
+ sortOrder: row.StageType.sortOrder,
+ });
+ companyMap.set(row.Job.companyId, row.Job.Company.label);
+ }
+
+ const rounds = [...roundMap.entries()]
+ .sort(
+ (a, b) =>
+ a[1].sortOrder - b[1].sortOrder || a[1].label.localeCompare(b[1].label),
+ )
+ .map(([id, v]) => ({ id, label: v.label }));
+
+ const companies = [...companyMap.entries()]
+ .sort((a, b) => a[1].localeCompare(b[1]))
+ .map(([id, label]) => ({ id, label }));
+
+ return { rounds, companies };
+ } catch (error) {
+ return handleError(error, "Failed to fetch interview filters. ");
+ }
+};
diff --git a/src/actions/jobStage.actions.ts b/src/actions/jobStage.actions.ts
index 9ea1200..db0935c 100644
--- a/src/actions/jobStage.actions.ts
+++ b/src/actions/jobStage.actions.ts
@@ -7,6 +7,7 @@ export {
deleteJobStage,
setCurrentJobStage,
setStageNotes,
+ setStageOutcome,
} from "./jobStage/mutations";
export {
linkStageInterviewer,
diff --git a/src/actions/jobStage/mutations.ts b/src/actions/jobStage/mutations.ts
index 99943b7..c016f33 100644
--- a/src/actions/jobStage/mutations.ts
+++ b/src/actions/jobStage/mutations.ts
@@ -4,6 +4,7 @@ import { handleError, combineDateAndTime } from "@/lib/utils";
import { revalidatePath } from "next/cache";
import { requireUser } from "../shared";
import { resolveJobStageType } from "@/lib/jobs/resolve";
+import { STAGE_OUTCOMES } from "@/lib/constants";
import {
AddJobStageFormSchema,
type AddJobStageValues,
@@ -245,3 +246,30 @@ export const setStageNotes = async (
return handleError(error, "Failed to save the note.");
}
};
+
+// The Interviews list sets an outcome from a row menu. Its own action for the
+// same reason setStageNotes has one: updateJobStage parses the whole Add Stage
+// form and would re-run promoteStage as a side effect of one field.
+export const setStageOutcome = async (
+ stageId: string,
+ outcome: string | null,
+): Promise<any | undefined> => {
+ try {
+ const user = await requireUser();
+ await assertStageOwned(stageId, user.id);
+
+ if (outcome && !STAGE_OUTCOMES.some((o) => o.value === outcome)) {
+ throw new Error(`"${outcome}" is not a known outcome.`);
+ }
+
+ const res = await prisma.jobStage.updateMany({
+ where: { id: stageId, Job: { userId: user.id } },
+ data: { outcome },
+ });
+ if (res.count === 0) throw new Error("Stage not found");
+
+ return { success: true };
+ } catch (error) {
+ return handleError(error, "Failed to save the outcome.");
+ }
+};
diff --git a/src/components/interviews/interviewDisplay.ts b/src/components/interviews/interviewDisplay.ts
new file mode 100644
index 0000000..e0a2344
--- /dev/null
+++ b/src/components/interviews/interviewDisplay.ts
@@ -0,0 +1,80 @@
+import { format } from "date-fns";
+import { STAGE_OUTCOMES } from "@/lib/constants";
+
+// A round created through Add Stage has no outcome — the field only appears
+// when editing — so a null one is derived from the date rather than left as a
+// dash. Nothing here is ever written back.
+export function outcomeLabel(
+ occurredAt: Date | null,
+ outcome: string | null,
+ now: Date = new Date(),
+): string {
+ const stored = STAGE_OUTCOMES.find((o) => o.value === outcome);
+ if (stored) return stored.label;
+ if (!occurredAt) return "Not scheduled";
+ return occurredAt.getTime() >= now.getTime() ? "Scheduled" : "Awaiting outcome";
+}
+
+export type OutcomeTone = "default" | "secondary" | "destructive" | "outline";
+
+export function outcomeTone(label: string): OutcomeTone {
+ if (label === "Passed") return "default";
+ if (label === "Failed" || label === "No-show" || label === "Cancelled") {
+ return "destructive";
+ }
+ if (label === "Scheduled") return "outline";
+ return "secondary";
+}
+
+export type FormatIcon = "video" | "phone" | "location";
+
+// JobStage.format is free text, so the icon is a guess that degrades to a
+// neutral pin rather than to a wrong icon.
+export function formatIconKind(value: string | null): FormatIcon {
+ if (!value) return "location";
+ if (/video|zoom|meet|teams|hangout|webex/i.test(value)) return "video";
+ if (/phone|call|voice/i.test(value)) return "phone";
+ return "location";
+}
+
+export function formatText(
+ value: string | null,
+ location: string | null,
+): string {
+ return location?.trim() || value?.trim() || "Not set";
+}
+
+export function durationLabel(mins: number | null): string | null {
+ if (!mins) return null;
+ return mins >= 60 && mins % 60 === 0 ? `${mins / 60}h` : `${mins}m`;
+}
+
+export function whenParts(occurredAt: Date | null): {
+ day: string;
+ time: string | null;
+} {
+ if (!occurredAt) return { day: "No date", time: null };
+ return {
+ day: format(occurredAt, "EEE d MMM"),
+ time: format(occurredAt, "h:mm a"),
+ };
+}
+
+function abbreviate(name: string): string {
+ const parts = name.trim().split(/\s+/).filter(Boolean);
+ if (parts.length < 2) return name.trim();
+ return `${parts[0]![0]!.toUpperCase()}. ${parts[parts.length - 1]}`;
+}
+
+export function interviewerSummary(
+ interviewers: { Contact: { name: string } }[],
+): string {
+ if (interviewers.length === 0) return "None linked";
+ if (interviewers.length > 2) return `${interviewers.length} interviewers`;
+ return interviewers.map((i) => abbreviate(i.Contact.name)).join(", ");
+}
+
+export function prepSummary(prep: { asked: boolean }[]): string {
+ const asked = prep.filter((p) => p.asked).length;
+ return asked > 0 ? `${asked} / ${prep.length}` : String(prep.length);
+}
diff --git a/src/models/interview.model.ts b/src/models/interview.model.ts
new file mode 100644
index 0000000..ee3e804
--- /dev/null
+++ b/src/models/interview.model.ts
@@ -0,0 +1,25 @@
+import type { JobStage } from "./jobStage.model";
+
+// Undated rounds count as upcoming: an unscheduled interview is work still
+// ahead, and it is the row most easily forgotten.
+export const INTERVIEW_VIEWS = ["upcoming", "past", "all"] as const;
+
+export type InterviewView = (typeof INTERVIEW_VIEWS)[number];
+
+export interface InterviewRow extends JobStage {
+ Job: {
+ id: string;
+ JobTitle: { label: string };
+ Company: { id: string; label: string };
+ };
+}
+
+export interface InterviewFilterOption {
+ id: string;
+ label: string;
+}
+
+export interface InterviewFilterOptions {
+ rounds: InterviewFilterOption[];
+ companies: InterviewFilterOption[];
+}