From a84128cb833cb8e0581743ee796413d712a10fb9 Mon Sep 17 00:00:00 2001 From: ngqile Date: Tue, 1 Dec 2026 19:44:53 +0800 Subject: [PATCH] feat: styled dropdown menus in admin forms Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../changes/add-visual-foundation/tasks.md | 2 +- .../app/companies/page.test.tsx | 13 ++++ solvway-admin-portal/app/companies/page.tsx | 18 +++--- .../app/companyScope.forms.test.tsx | 10 +-- .../app/components/events/EventForm.tsx | 30 +++++---- .../app/components/users/UserForm.tsx | 30 ++++----- .../[eventUuid]/[eventLeadUuid]/page.test.tsx | 25 +++++--- .../[eventUuid]/[eventLeadUuid]/page.tsx | 34 ++++++---- .../event-leads/[eventUuid]/new/page.test.tsx | 63 ++++++++++++++++--- .../app/event-leads/[eventUuid]/new/page.tsx | 34 ++++++---- 10 files changed, 178 insertions(+), 81 deletions(-) diff --git a/openspec/changes/add-visual-foundation/tasks.md b/openspec/changes/add-visual-foundation/tasks.md index 14186ca..af177b3 100644 --- a/openspec/changes/add-visual-foundation/tasks.md +++ b/openspec/changes/add-visual-foundation/tasks.md @@ -20,7 +20,7 @@ Serial. One implementer at a time, Opus review gate per task. ## 3. Form dropdowns -- [ ] 3.1 Replace the native selects in the event form, user form, company status, and the new and edit event-lead pages with the styled select; values save as before. +- [x] 3.1 Replace the native selects in the event form, user form, company status, and the new and edit event-lead pages with the styled select; values save as before. - Depends on: 2.1 - Tests first: each dropdown opens a menu, choosing an option sends that value on save; keyboard opens and chooses. - Scope: `solvway-admin-portal/app/components/events/**`, `solvway-admin-portal/app/components/users/**`, `solvway-admin-portal/app/companies/**`, `solvway-admin-portal/app/event-leads/**`, `solvway-admin-portal/app/companyScope.forms.test.tsx` diff --git a/solvway-admin-portal/app/companies/page.test.tsx b/solvway-admin-portal/app/companies/page.test.tsx index be61ac8..18037fc 100644 --- a/solvway-admin-portal/app/companies/page.test.tsx +++ b/solvway-admin-portal/app/companies/page.test.tsx @@ -46,6 +46,19 @@ describe("CompaniesPage", () => { ); }); + it("saves the status chosen in the styled dropdown", async () => { + mocks.apiPost.mockResolvedValue({ id: 1 }); + render(); + const row = (await screen.findByText("Insight")).closest("tr")!; + await userEvent.click(within(row).getByRole("button", { name: "Edit" })); + await userEvent.click(screen.getByLabelText("Status")); + await userEvent.click(await screen.findByRole("option", { name: "Inactive" })); + await userEvent.click(screen.getByRole("button", { name: /save/i })); + await waitFor(() => + expect(mocks.apiPost).toHaveBeenCalledWith("/api/companies", { id: 1, name: "Insight", status: "I" }), + ); + }); + it("edits name and status only, with no code field", async () => { mocks.apiPost.mockResolvedValue({ id: 1 }); render(); diff --git a/solvway-admin-portal/app/companies/page.tsx b/solvway-admin-portal/app/companies/page.tsx index 01564d8..1cd3340 100644 --- a/solvway-admin-portal/app/companies/page.tsx +++ b/solvway-admin-portal/app/companies/page.tsx @@ -6,6 +6,7 @@ import type { ColumnDef } from "@tanstack/react-table"; import { Button } from "@/app/components/ui/button"; import { Input } from "@/app/components/ui/input"; import { Label } from "@/app/components/ui/label"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/components/ui/select"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/app/components/ui/dialog"; import { DataTable } from "@/app/components/ui/data-table"; import { PageHeader } from "@/app/components/ui/page-header"; @@ -91,16 +92,13 @@ function CompanyDialog({ state, onClose, onSaved }: { state: DialogState; onClos )}
- +
)} diff --git a/solvway-admin-portal/app/companyScope.forms.test.tsx b/solvway-admin-portal/app/companyScope.forms.test.tsx index fc5f1b2..a17926c 100644 --- a/solvway-admin-portal/app/companyScope.forms.test.tsx +++ b/solvway-admin-portal/app/companyScope.forms.test.tsx @@ -49,7 +49,7 @@ describe("UserForm company", () => { const user = userEvent.setup(); render(); const company = await screen.findByRole("combobox", { name: "Company" }); - expect(company).toHaveValue("2"); + expect(company).toHaveTextContent("CV"); await fillUser(user); await user.click(screen.getByLabelText("HQ")); await user.click(screen.getByRole("button", { name: /create|save/i })); @@ -60,7 +60,8 @@ describe("UserForm company", () => { const onSubmit = vi.fn().mockResolvedValue(undefined); const user = userEvent.setup(); render(); - await user.selectOptions(await screen.findByRole("combobox", { name: "Company" }), "super"); + await user.click(await screen.findByRole("combobox", { name: "Company" })); + await user.click(await screen.findByRole("option", { name: "Super admin (no company)" })); await fillUser(user); await user.click(screen.getByLabelText("HQ")); await user.click(screen.getByRole("button", { name: /create|save/i })); @@ -113,7 +114,7 @@ describe("EventForm company", () => { const onSubmit = vi.fn().mockResolvedValue(undefined); const user = userEvent.setup(); render(); - expect(await screen.findByRole("combobox", { name: "Company" })).toHaveValue("2"); + expect(await screen.findByRole("combobox", { name: "Company" })).toHaveTextContent("CV"); await user.type(screen.getByLabelText("Name"), "Expo"); await user.type(screen.getByLabelText("Location"), "KL"); pickDate("Start date", "2026-12-01"); @@ -133,7 +134,8 @@ describe("EventForm company", () => { const user = userEvent.setup(); const { unmount } = render(); await waitFor(() => expect(mocks.listSalespersonOptions).toHaveBeenLastCalledWith(2)); - await user.selectOptions(screen.getByRole("combobox", { name: "Company" }), "1"); + await user.click(screen.getByRole("combobox", { name: "Company" })); + await user.click(await screen.findByRole("option", { name: "INS" })); await waitFor(() => expect(mocks.listSalespersonOptions).toHaveBeenLastCalledWith(1)); unmount(); mocks.useCompanyScope.mockReturnValue(scope(1)); diff --git a/solvway-admin-portal/app/components/events/EventForm.tsx b/solvway-admin-portal/app/components/events/EventForm.tsx index 58af2c5..b6118a3 100644 --- a/solvway-admin-portal/app/components/events/EventForm.tsx +++ b/solvway-admin-portal/app/components/events/EventForm.tsx @@ -5,6 +5,7 @@ import { Button } from "@/app/components/ui/button"; import { Checkbox } from "@/app/components/ui/checkbox"; import { Input } from "@/app/components/ui/input"; import { Label } from "@/app/components/ui/label"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/components/ui/select"; import { Switch } from "@/app/components/ui/switch"; import { DatePicker } from "@/app/components/ui/date-picker"; import { ErrorState } from "@/app/components/ui/states"; @@ -15,6 +16,9 @@ import { useT } from "@/app/lib/i18n/MessagesProvider"; import type { AdminEvent, AdminEventPayload, SalespersonOption } from "@/app/lib/types"; import type { ApiError } from "@/app/lib/clientApi"; +// Radix Select rejects "" as an item value, so "no company" is this sentinel, mapped back to "". +const NONE = "none"; + interface SalespersonOptionExtended extends SalespersonOption { active: boolean; } @@ -179,22 +183,24 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) { {showCompany && (
- { + setCompanyChoice(v === NONE ? "" : v); setSelectedIds(new Set()); // the team is company-specific }} disabled={saving} - aria-invalid={!!fieldErrors.company} - className="h-9 w-full rounded-md border bg-background px-2 text-sm" > - - ))} - + + + + + {" "} + {scope.companies.map((c) => ( + {c.code} + ))} + + {fieldErrors.company && (

{fieldErrors.company} diff --git a/solvway-admin-portal/app/components/users/UserForm.tsx b/solvway-admin-portal/app/components/users/UserForm.tsx index 3eafbf3..a3a5457 100644 --- a/solvway-admin-portal/app/components/users/UserForm.tsx +++ b/solvway-admin-portal/app/components/users/UserForm.tsx @@ -7,6 +7,7 @@ import { Button } from "@/app/components/ui/button"; import { Checkbox } from "@/app/components/ui/checkbox"; import { Input } from "@/app/components/ui/input"; import { Label } from "@/app/components/ui/label"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/components/ui/select"; import { Switch } from "@/app/components/ui/switch"; import { ErrorState } from "@/app/components/ui/states"; import { roleLabel } from "@/app/lib/roleLabel"; @@ -22,6 +23,9 @@ import { PasswordFields } from "./PasswordFields"; // add/edit-user form"). The Roles picker is populated from the admin roles list // endpoint; the backend sets the branch from the creating admin. +// Radix Select rejects "" as an item value, so "no company" is this sentinel, mapped back to "". +const NONE = "none"; + // Deliberately basic (RFC-exhaustive email validation is out of scope) — mirrors // the "basic email validation" requirement in the plan. const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; @@ -220,20 +224,18 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF {showCompany && (

- + {fieldErrors.company && (

{fieldErrors.company} diff --git a/solvway-admin-portal/app/event-leads/[eventUuid]/[eventLeadUuid]/page.test.tsx b/solvway-admin-portal/app/event-leads/[eventUuid]/[eventLeadUuid]/page.test.tsx index 93d3a74..7dbf5ff 100644 --- a/solvway-admin-portal/app/event-leads/[eventUuid]/[eventLeadUuid]/page.test.tsx +++ b/solvway-admin-portal/app/event-leads/[eventUuid]/[eventLeadUuid]/page.test.tsx @@ -59,6 +59,12 @@ beforeEach(() => { mocks.useAdminAuth.mockReset().mockReturnValue({ loading: false, hasModule: () => true }); }); +// Radix selects: open the combobox, then click the option (a native selectOptions no longer applies). +const pick = async (user: ReturnType, label: string, option: string) => { + await user.click(screen.getByLabelText(label)); + await user.click(await screen.findByRole("option", { name: option })); +}; + describe("EventLeadPage", { timeout: 20000 }, () => { it("renders NotAuthorized when the module is absent", () => { mocks.useAdminAuth.mockReturnValue({ loading: false, hasModule: () => false }); @@ -86,9 +92,9 @@ describe("EventLeadPage", { timeout: 20000 }, () => { it("prefills the editable fields from the event lead", async () => { await open(); - expect(screen.getByLabelText("Salesperson")).toHaveValue("7"); - expect(screen.getByLabelText("Temperature")).toHaveValue("WARM"); - expect(screen.getByLabelText("Status")).toHaveValue("CONTACTED"); + expect(screen.getByLabelText("Salesperson")).toHaveTextContent("Jane Sales"); + expect(screen.getByLabelText("Temperature")).toHaveTextContent("Warm"); + expect(screen.getByLabelText("Status")).toHaveTextContent("Contacted"); expect(screen.getByLabelText("Product A")).toBeChecked(); expect(screen.getByLabelText("Next follow-up")).toHaveValue("01/12/2026"); expect(screen.getByLabelText("Notes")).toHaveValue("Call back"); @@ -96,7 +102,8 @@ describe("EventLeadPage", { timeout: 20000 }, () => { it("keeps the current salesperson selectable when not on the event team list", async () => { await open(); - const select = screen.getByLabelText("Salesperson"); + await userEvent.setup().click(screen.getByLabelText("Salesperson")); + const select = await screen.findByRole("listbox"); expect(within(select).getByRole("option", { name: "Jane Sales" })).toBeInTheDocument(); expect(within(select).getByRole("option", { name: "Bob Other" })).toBeInTheDocument(); expect(within(select).getByRole("option", { name: "None" })).toBeInTheDocument(); @@ -128,9 +135,9 @@ describe("EventLeadPage", { timeout: 20000 }, () => { it("saves edited values", async () => { const user = await open(); - await user.selectOptions(screen.getByLabelText("Salesperson"), "8"); - await user.selectOptions(screen.getByLabelText("Temperature"), "HOT"); - await user.selectOptions(screen.getByLabelText("Status"), "WON"); + await pick(user, "Salesperson", "Bob Other"); + await pick(user, "Temperature", "Hot"); + await pick(user, "Status", "Won"); await user.click(screen.getByLabelText("Product B")); await user.click(screen.getByLabelText("Product C")); pickDate("Next follow-up", "2026-12-05"); @@ -146,8 +153,8 @@ describe("EventLeadPage", { timeout: 20000 }, () => { it("sends null for emptied fields", async () => { const user = await open(); - await user.selectOptions(screen.getByLabelText("Salesperson"), ""); - await user.selectOptions(screen.getByLabelText("Temperature"), ""); + await pick(user, "Salesperson", "None"); + await pick(user, "Temperature", "None"); await user.clear(screen.getByLabelText("Notes")); await user.click(screen.getByLabelText("Product A")); await user.click(screen.getByLabelText("Product B")); diff --git a/solvway-admin-portal/app/event-leads/[eventUuid]/[eventLeadUuid]/page.tsx b/solvway-admin-portal/app/event-leads/[eventUuid]/[eventLeadUuid]/page.tsx index 5bc3ed0..5c9de77 100644 --- a/solvway-admin-portal/app/event-leads/[eventUuid]/[eventLeadUuid]/page.tsx +++ b/solvway-admin-portal/app/event-leads/[eventUuid]/[eventLeadUuid]/page.tsx @@ -7,6 +7,7 @@ import { Badge } from "@/app/components/ui/badge"; import { Button } from "@/app/components/ui/button"; import { DatePicker } from "@/app/components/ui/date-picker"; import { Label } from "@/app/components/ui/label"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/components/ui/select"; import { PageHeader } from "@/app/components/ui/page-header"; import { EmptyState, ErrorState, TableSkeleton } from "@/app/components/ui/states"; import { useAdminAuth } from "@/app/lib/AdminAuthContext"; @@ -27,6 +28,8 @@ const CODE_MESSAGE: Record = { INVALID_VALUE: "LeadErrInvalidValue", }; const FIELDS = ["salespersonId", "temperature", "status", "interestIds", "nextFollowUpDate", "notes"]; +// Radix Select rejects "" as an item value, so "None" is this sentinel, mapped back to "". +const NONE = "none"; const SELECT_CLASS = "min-h-11 w-full rounded-md border border-input bg-transparent px-3 text-base shadow-sm outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-[invalid=true]:border-destructive dark:bg-input/30"; const TALL = "min-h-11"; @@ -156,19 +159,28 @@ function EventLead() {

{field("salespersonId", t("LeadSalesperson"), - )} + )} {field("temperature", t("LeadTemperature"), - )} + )} {field("status", t("LeadStatus"), - )} + )}
{t("LeadInterests")} diff --git a/solvway-admin-portal/app/event-leads/[eventUuid]/new/page.test.tsx b/solvway-admin-portal/app/event-leads/[eventUuid]/new/page.test.tsx index d9806b8..73a7e6f 100644 --- a/solvway-admin-portal/app/event-leads/[eventUuid]/new/page.test.tsx +++ b/solvway-admin-portal/app/event-leads/[eventUuid]/new/page.test.tsx @@ -27,6 +27,11 @@ import { ApiError } from "@/app/lib/clientApi"; import { memoryRouter } from "@/test/memoryRouter"; import NewEventLeadPage from "./page"; +// Radix selects: open the combobox, then click the option (a native selectOptions no longer applies). +const pick = async (user: ReturnType, label: string, option: string) => { + await user.click(screen.getByLabelText(label)); + await user.click(await screen.findByRole("option", { name: option })); +}; const SERVER_MSG = "Server says: internal detail xyz"; const apiError = (code: string, extra: { errors?: string[]; details?: Record } = {}) => new ApiError(SERVER_MSG, 400, { code, errors: [], details: {}, ...extra }); @@ -171,13 +176,17 @@ describe("NewEventLeadPage", { timeout: 20000 }, () => { await user.type(screen.getByLabelText("Company"), "Initech"); await user.type(screen.getByLabelText("Job title"), "COO"); await user.type(screen.getByLabelText("Notes"), "Met at booth"); - expect(screen.getByLabelText("Status")).toHaveValue("OPEN"); + expect(screen.getByLabelText("Status")).toHaveTextContent("Open"); expect(screen.getByLabelText("Status")).toHaveClass("min-h-11"); - expect(within(screen.getByLabelText("Temperature")).getByRole("option", { name: "Hot" })).toBeInTheDocument(); + await user.click(screen.getByLabelText("Temperature")); + expect(within(await screen.findByRole("listbox")).getByRole("option", { name: "Hot" })).toBeInTheDocument(); + await user.keyboard("{Escape}"); + await user.click(screen.getByLabelText("Salesperson")); expect(await screen.findByRole("option", { name: "Jane Sales" })).toBeInTheDocument(); - await user.selectOptions(screen.getByLabelText("Salesperson"), "7"); - await user.selectOptions(screen.getByLabelText("Temperature"), "HOT"); - await user.selectOptions(screen.getByLabelText("Status"), "QUALIFIED"); + await user.keyboard("{Escape}"); + await pick(user, "Salesperson", "Jane Sales"); + await pick(user, "Temperature", "Hot"); + await pick(user, "Status", "Qualified"); expect(screen.queryByLabelText("Product B")).toBeNull(); await user.click(await screen.findByLabelText("Product A")); pickDate("Next follow-up", "2026-12-05"); @@ -199,6 +208,42 @@ describe("NewEventLeadPage", { timeout: 20000 }, () => { await waitFor(() => expect(memoryRouter.push).toHaveBeenCalledWith("/event-leads/evt-1")); }); + it("opens styled menus for salesperson, temperature and status, and saves the chosen values", async () => { + const user = await toStep1Match([]); + await user.type(await screen.findByLabelText("Name"), "Dee Menu"); + const menu = async (label: string) => { + await user.click(screen.getByLabelText(label)); + return within(await screen.findByRole("listbox")).getAllByRole("option").map((o) => o.textContent); + }; + expect(await menu("Salesperson")).toEqual(["None", "Jane Sales"]); + await user.keyboard("{Escape}"); + expect(await menu("Temperature")).toEqual(["None", "Hot", "Warm", "Cold"]); + await user.keyboard("{Escape}"); + expect(await menu("Status")).toEqual(["Open", "Contacted", "Qualified", "Won", "Lost"]); + await user.keyboard("{Escape}"); + await pick(user, "Salesperson", "Jane Sales"); + await pick(user, "Temperature", "Warm"); + await pick(user, "Status", "Won"); + await user.click(screen.getByRole("button", { name: "Save" })); + await waitFor(() => expect(mocks.captureEventLead).toHaveBeenCalledTimes(1)); + expect(mocks.captureEventLead.mock.calls[0][1]).toMatchObject({ salespersonId: 7, temperature: "WARM", status: "WON" }); + }); + + it("a dropdown opens with Space, moves with the arrow keys and chooses with Enter", async () => { + const user = await toStep1Match([]); + await user.type(await screen.findByLabelText("Name"), "Kay Board"); + await screen.findByLabelText("Temperature"); + await user.tab(); + screen.getByLabelText("Temperature").focus(); + await user.keyboard(" "); + expect(await screen.findByRole("listbox")).toBeVisible(); + await user.keyboard("{ArrowDown}{Enter}"); + expect(screen.getByLabelText("Temperature")).toHaveTextContent("Hot"); + await user.click(screen.getByRole("button", { name: "Save" })); + await waitFor(() => expect(mocks.captureEventLead).toHaveBeenCalledTimes(1)); + expect(mocks.captureEventLead.mock.calls[0][1]).toMatchObject({ temperature: "HOT" }); + }); + it("Back returns to step 1", async () => { const user = await toStep1Match([]); await user.click(await screen.findByRole("button", { name: "Back" })); @@ -298,17 +343,17 @@ describe("NewEventLeadPage", { timeout: 20000 }, () => { it("preselects the capturing user as salesperson when on the team", async () => { mocks.useAdminAuth.mockReturnValue({ loading: false, hasModule: () => true, id: 7 }); const user = await toStep1Match([]); - await screen.findByRole("option", { name: "Jane Sales" }); - await waitFor(() => expect(screen.getByLabelText("Salesperson")).toHaveValue("7")); + await waitFor(() => expect(screen.getByLabelText("Salesperson")).toHaveTextContent("Jane Sales")); await user.click(screen.getByRole("button", { name: "Save" })); await waitFor(() => expect(mocks.captureEventLead).toHaveBeenCalledWith("evt-1", expect.objectContaining({ salespersonId: 7 }))); }); it("leaves the salesperson empty when the capturing user is not on the team", async () => { mocks.useAdminAuth.mockReturnValue({ loading: false, hasModule: () => true, id: 99 }); - await toStep1Match([]); + const user = await toStep1Match([]); + await user.click(await screen.findByLabelText("Salesperson")); await screen.findByRole("option", { name: "Jane Sales" }); - expect(screen.getByLabelText("Salesperson")).toHaveValue(""); + expect(screen.getByLabelText("Salesperson")).toHaveTextContent("None"); }); it("keeps the options-load failure visible after matching", async () => { diff --git a/solvway-admin-portal/app/event-leads/[eventUuid]/new/page.tsx b/solvway-admin-portal/app/event-leads/[eventUuid]/new/page.tsx index 5049cb2..1610a57 100644 --- a/solvway-admin-portal/app/event-leads/[eventUuid]/new/page.tsx +++ b/solvway-admin-portal/app/event-leads/[eventUuid]/new/page.tsx @@ -7,6 +7,7 @@ import { Button } from "@/app/components/ui/button"; import { DatePicker } from "@/app/components/ui/date-picker"; import { Input } from "@/app/components/ui/input"; import { Label } from "@/app/components/ui/label"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/components/ui/select"; import { PageHeader } from "@/app/components/ui/page-header"; import { ErrorState } from "@/app/components/ui/states"; import { RequireModule } from "@/app/lib/RequireModule"; @@ -30,6 +31,8 @@ const CODE_MESSAGE: Record = { }; // Codes that name their field themselves when the server omits details.field. const IMPLIED_FIELD: Record = { INVALID_MOBILE: "mobile", INVALID_EMAIL: "email" }; +// Radix Select rejects "" as an item value, so "None" is this sentinel, mapped back to "". +const NONE = "none"; const SELECT_CLASS = "min-h-11 w-full rounded-md border border-input bg-transparent px-3 text-base shadow-sm outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-[invalid=true]:border-destructive dark:bg-input/30"; const TALL = "min-h-11"; @@ -272,19 +275,28 @@ function NewEventLead() { )} {field("salespersonId", t("LeadSalesperson"), - )} + )} {field("temperature", t("LeadTemperature"), - )} + )} {field("status", t("LeadStatus"), - )} + )}
{t("LeadInterests")}