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 to Prep List dialog and a creatable question-category combobox case
Khuram Niaz95dfedbe3350
diff --git a/__tests__/AddPrepQuestionsDialog.spec.tsx b/__tests__/AddPrepQuestionsDialog.spec.tsxnew file mode 100644index 0000000..2158ca9--- /dev/null+++ b/__tests__/AddPrepQuestionsDialog.spec.tsx@@ -0,0 +1,86 @@+import { render, screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { AddPrepQuestionsDialog } from "@/components/myjobs/job-details/timeline/AddPrepQuestionsDialog";+import { addStagePrepQuestions } from "@/actions/jobStage.actions";+import { getQuestionsList } from "@/actions/question.actions";++vi.mock("@/actions/jobStage.actions", () => ({+ addStagePrepQuestions: vi.fn().mockResolvedValue({ success: true, data: [] }),+}));+vi.mock("@/actions/question.actions", () => ({+ getQuestionsList: vi.fn(),+ createQuestion: vi.fn().mockResolvedValue({+ success: true,+ data: { id: "q9", question: "New one", tags: [] },+ }),+}));+vi.mock("@/actions/tag.actions", () => ({ getAllTags: vi.fn().mockResolvedValue([]) }));+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" } },+ prepQuestions: [{ id: "p1", questionId: "q1" }],+} as any;++beforeEach(() => {+ vi.clearAllMocks();+ (getQuestionsList as any).mockResolvedValue({+ success: true,+ total: 2,+ data: [+ { id: "q1", question: "Walk through your caching strategy", tags: [{ id: "tg1", label: "System Design", value: "system design", createdBy: "u1" }] },+ { id: "q2", question: "Tell me about a conflict with a teammate", tags: [] },+ ],+ });+});++describe("AddPrepQuestionsDialog", () => {+ it("heads the dialog with the stage and explains the asked workflow", async () => {+ render(<AddPrepQuestionsDialog open stage={stage} onOpenChange={() => {}} onAdded={() => {}} />);++ expect(await screen.findByText("Final / Onsite Interview · Sep 24, 2026")).toBeInTheDocument();+ expect(+ screen.getByText(/check them off as "asked" from the Timeline tab/),+ ).toBeInTheDocument();+ });++ // The same question cannot be added twice to one stage.+ it("shows a question already on the prep list as such and does not allow selecting it", async () => {+ render(<AddPrepQuestionsDialog open stage={stage} onOpenChange={() => {}} onAdded={() => {}} />);++ const already = await screen.findByRole("checkbox", {+ name: /Walk through your caching strategy/,+ });+ expect(already).toBeDisabled();+ expect(already).toBeChecked();+ });++ it("shows a selection as a removable chip and submits it", async () => {+ render(<AddPrepQuestionsDialog open stage={stage} onOpenChange={() => {}} onAdded={() => {}} />);++ await userEvent.click(+ await screen.findByRole("checkbox", { name: /Tell me about a conflict/ }),+ );+ expect(+ screen.getByRole("button", { name: /Remove Tell me about a conflict/ }),+ ).toBeInTheDocument();++ await userEvent.click(+ screen.getByRole("button", { name: "Done — 1 question added to prep list" }),+ );++ expect(addStagePrepQuestions).toHaveBeenCalledWith("st1", ["q2"]);+ });++ it("renders the question's tags as category badges", async () => {+ render(<AddPrepQuestionsDialog open stage={stage} onOpenChange={() => {}} onAdded={() => {}} />);++ expect(await screen.findByText("System Design")).toBeInTheDocument();+ });+});diff --git a/__tests__/ComboBox.spec.tsx b/__tests__/ComboBox.spec.tsxindex 87916e0..a14e9fa 100644--- a/__tests__/ComboBox.spec.tsx+++ b/__tests__/ComboBox.spec.tsx@@ -37,6 +37,10 @@ vi.mock("@/actions/contactRole.actions", () => ({createContactRole: vi.fn(),}));+vi.mock("@/actions/tag.actions", () => ({+ createTag: vi.fn(),+}));+vi.mock("@/lib/toast", () => ({toastError: vi.fn(),}));diff --git a/src/components/ComboBox.tsx b/src/components/ComboBox.tsxindex 7406d5f..5094a91 100644--- a/src/components/ComboBox.tsx+++ b/src/components/ComboBox.tsx@@ -29,6 +29,7 @@ import { toastError } from "@/lib/toast";import { createActivityType } from "@/actions/activity.actions";import { createJobSource } from "@/actions/job.actions";import { createContactRole } from "@/actions/contactRole.actions";+import { createTag } from "@/actions/tag.actions";interface ComboboxProps {options: any[];@@ -122,6 +123,14 @@ export function Combobox({}response = roleRes.data;break;+ case "questionCategory":+ const tagRes = await createTag(label);+ if (!tagRes.success) {+ toastError(tagRes.message);+ return;+ }+ response = tagRes.data;+ break;case "activityType":response = await createActivityType(label);break;diff --git a/src/components/myjobs/JobDetails.tsx b/src/components/myjobs/JobDetails.tsxindex ddc1f15..aed3c2c 100644--- a/src/components/myjobs/JobDetails.tsx+++ b/src/components/myjobs/JobDetails.tsx@@ -45,6 +45,7 @@ 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 { AddPrepQuestionsDialog } from "./job-details/timeline/AddPrepQuestionsDialog";import type { JobStage, JobStageTypeRef } from "@/models/jobStage.model";const JOB_DETAIL_TABS = [@@ -368,6 +369,12 @@ function JobDetails({router.refresh();}}/>+ <AddPrepQuestionsDialog+ open={prepQuestionsOpen}+ stage={selectedStage ?? currentStage}+ onOpenChange={setPrepQuestionsOpen}+ onAdded={() => void reloadStages()}+ /><DeleteAlertDialogpageTitle="job"open={deleteAlertOpen}diff --git a/src/components/myjobs/job-details/timeline/AddPrepQuestionsDialog.tsx b/src/components/myjobs/job-details/timeline/AddPrepQuestionsDialog.tsxnew file mode 100644index 0000000..218a77c--- /dev/null+++ b/src/components/myjobs/job-details/timeline/AddPrepQuestionsDialog.tsx@@ -0,0 +1,284 @@+"use client";+import { useEffect, useId, useRef, useState, useTransition } from "react";+import { useForm } from "react-hook-form";+import { Search, X } from "lucide-react";+import { Badge } from "@/components/ui/badge";+import { Button } from "@/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "@/components/ui/dialog";+import { Form, FormField, FormItem } from "@/components/ui/form";+import { Input } from "@/components/ui/input";+import { Combobox } from "@/components/ComboBox";+import { toastActionResult } from "@/lib/toast";+import { addStagePrepQuestions } from "@/actions/jobStage.actions";+import { createQuestion, getQuestionsList } from "@/actions/question.actions";+import { getAllTags } from "@/actions/tag.actions";+import type { Tag } from "@/models/job.model";+import type { JobStage } from "@/models/jobStage.model";+import { stageHeading } from "./stageDisplay";++type BankQuestion = { id: string; question: string; tags: Tag[] };++type AddPrepQuestionsDialogProps = {+ open: boolean;+ stage: JobStage | null;+ onOpenChange: (open: boolean) => void;+ onAdded: () => void;+};++// A cap rather than an unbounded read: the search below filters client-side,+// which is what makes the artboard's instant search possible at all.+const BANK_PAGE_SIZE = 200;++// The question bank requires an answer; "TBD" is the app's own placeholder+// for one that has not been written yet (QuestionForm).+const UNANSWERED = "TBD";++export function AddPrepQuestionsDialog({+ open,+ stage,+ onOpenChange,+ onAdded,+}: AddPrepQuestionsDialogProps) {+ const [bank, setBank] = useState<BankQuestion[]>([]);+ const [tags, setTags] = useState<Tag[]>([]);+ const [search, setSearch] = useState("");+ const [selected, setSelected] = useState<string[]>([]);+ const [newQuestion, setNewQuestion] = useState("");+ const [isPending, startTransition] = useTransition();+ const loaded = useRef(false);+ const rowId = useId();++ // The category picker is a creatable Combobox, so it needs a form field to+ // hang off; nothing else in this dialog is form-driven.+ const form = useForm<{ questionCategory: string }>({+ defaultValues: { questionCategory: "" },+ });++ useEffect(() => {+ if (!open || loaded.current) return;+ loaded.current = true;+ void (async () => {+ const [res, allTags] = await Promise.all([+ getQuestionsList(1, BANK_PAGE_SIZE),+ getAllTags(),+ ]);+ if (res?.success && Array.isArray(res.data)) setBank(res.data);+ if (Array.isArray(allTags)) setTags(allTags);+ })();+ }, [open]);++ useEffect(() => {+ if (!open) return;+ setSearch("");+ setSelected([]);+ setNewQuestion("");+ form.reset({ questionCategory: "" });+ }, [open, stage, form]);++ if (!stage) return null;++ const alreadyLinked = new Set(+ (stage.prepQuestions ?? []).map((row) => row.questionId),+ );+ const term = search.trim().toLowerCase();+ const visible = term+ ? bank.filter((q) => q.question.toLowerCase().includes(term))+ : bank;++ const toggle = (id: string, checked: boolean) =>+ setSelected((prev) =>+ checked ? [...prev, id] : prev.filter((x) => x !== id),+ );++ const addQuestion = () =>+ startTransition(async () => {+ const category = form.getValues("questionCategory");+ const res = await createQuestion({+ question: newQuestion.trim(),+ answer: UNANSWERED,+ tagIds: category ? [category] : [],+ });+ toastActionResult(res, {+ success: "Question has been added to your bank",+ onSuccess: () => {+ // Banked and selected in one click: the user asked for it here.+ setBank((prev) => [res.data, ...prev]);+ setSelected((prev) => [...prev, res.data.id]);+ setNewQuestion("");+ form.reset({ questionCategory: "" });+ },+ });+ });++ const submit = () => {+ if (selected.length === 0) {+ onOpenChange(false);+ return;+ }+ startTransition(async () => {+ const res = await addStagePrepQuestions(stage.id, selected);+ toastActionResult(res, {+ success: "Prep list has been updated successfully",+ onSuccess: () => {+ onAdded();+ onOpenChange(false);+ },+ });+ });+ };++ const doneLabel =+ selected.length === 0+ ? "Done"+ : `Done — ${selected.length} question${+ selected.length === 1 ? "" : "s"+ } added to prep list`;++ return (+ <Dialog open={open} onOpenChange={onOpenChange}>+ <DialogContent className="sm:max-w-[540px] max-h-[800px] overflow-hidden">+ <DialogHeader>+ <DialogTitle>Add to Prep List</DialogTitle>+ <DialogDescription>{stageHeading(stage)}</DialogDescription>+ </DialogHeader>++ <div className="max-h-[60vh] space-y-4 overflow-y-auto p-1">+ <p className="text-[13px] text-muted-foreground">+ Select questions you expect to be asked. After the interview, check+ them off as "asked" from the Timeline tab.+ </p>++ <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 question bank…"+ value={search}+ onChange={(e) => setSearch(e.target.value)}+ />+ </div>++ {selected.length > 0 && (+ <div className="flex flex-wrap gap-2">+ {selected.map((id) => {+ const q = bank.find((row) => row.id === id);+ if (!q) return null;+ return (+ <span+ key={id}+ className="flex max-w-full items-center gap-1.5 rounded-full bg-primary/10 py-1 pl-3 pr-1.5 text-xs"+ >+ <span className="truncate">{q.question}</span>+ <button+ type="button"+ aria-label={`Remove ${q.question}`}+ className="flex h-4 w-4 shrink-0 items-center justify-center rounded-full hover:bg-primary/20"+ onClick={() => toggle(id, false)}+ >+ <X className="h-3 w-3" />+ </button>+ </span>+ );+ })}+ </div>+ )}++ <ul className="overflow-hidden rounded-lg border">+ {visible.length === 0 && (+ <li className="px-3.5 py-4 text-[13px] text-muted-foreground">+ No questions match that search.+ </li>+ )}+ {visible.map((q, index) => {+ const isLinked = alreadyLinked.has(q.id);+ return (+ <li+ key={q.id}+ className={`flex items-center gap-2.5 px-3.5 py-2.5 ${+ index > 0 ? "border-t" : ""+ }`}+ >+ <input+ id={`${rowId}-${q.id}`}+ type="checkbox"+ className="h-4 w-4 shrink-0"+ checked={isLinked || selected.includes(q.id)}+ disabled={isLinked}+ onChange={(e) => toggle(q.id, e.target.checked)}+ />+ <label+ htmlFor={`${rowId}-${q.id}`}+ className="flex-1 cursor-pointer text-[13px]"+ >+ {q.question}+ </label>+ {q.tags?.map((tag) => (+ <Badge key={tag.id} variant="secondary" className="text-[11px]">+ {tag.label}+ </Badge>+ ))}+ {isLinked && (+ <span className="text-[11px] text-muted-foreground">+ On prep list+ </span>+ )}+ </li>+ );+ })}+ </ul>++ <div className="space-y-3 rounded-lg border border-dashed p-3.5">+ <p className="text-[13px] font-semibold">Add a new question</p>+ <Input+ placeholder="Type a new interview question…"+ aria-label="New question"+ value={newQuestion}+ onChange={(e) => setNewQuestion(e.target.value)}+ />+ <Form {...form}>+ <FormField+ control={form.control}+ name="questionCategory"+ render={({ field }) => (+ <FormItem className="flex flex-col">+ <Combobox+ options={tags}+ field={field}+ creatable+ fullWidth+ label="category"+ />+ </FormItem>+ )}+ />+ </Form>+ <Button+ size="sm"+ variant="outline"+ disabled={isPending || !newQuestion.trim()}+ onClick={addQuestion}+ >+ Add Question+ </Button>+ </div>+ </div>++ <DialogFooter>+ <Button variant="outline" onClick={() => onOpenChange(false)}>+ Cancel+ </Button>+ <Button onClick={submit} disabled={isPending}>+ {doneLabel}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ );+}