feat: styled dropdown menus in admin forms
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
0710571894
commit
a84128cb83
10 files changed
+178
-81
No files matched your search
@@ -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`
|
||||
|
||||
@@ -46,6 +46,19 @@ describe("CompaniesPage", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("saves the status chosen in the styled dropdown", async () => {
|
||||
mocks.apiPost.mockResolvedValue({ id: 1 });
|
||||
render(<CompaniesPage />);
|
||||
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(<CompaniesPage />);
|
||||
|
||||
@@ -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
|
||||
)}
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="company-status">{t("Status")}</Label>
|
||||
<select
|
||||
id="company-status"
|
||||
value={form.status}
|
||||
onChange={(e) => setForm((f) => ({ ...f, status: e.target.value as AdminCompany["status"] }))}
|
||||
disabled={saving}
|
||||
className="h-9 w-full rounded-md border border-input bg-transparent px-3 text-sm"
|
||||
>
|
||||
<option value="A">{t("CompActive")}</option>
|
||||
<option value="I">{t("CompInactive")}</option>
|
||||
</select>
|
||||
<Select value={form.status} onValueChange={(v) => setForm((f) => ({ ...f, status: v as AdminCompany["status"] }))} disabled={saving}>
|
||||
<SelectTrigger id="company-status" className="w-full"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="A">{t("CompActive")}</SelectItem>
|
||||
<SelectItem value="I">{t("CompInactive")}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -49,7 +49,7 @@ describe("UserForm company", () => {
|
||||
const user = userEvent.setup();
|
||||
render(<UserForm onSubmit={onSubmit} />);
|
||||
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(<UserForm onSubmit={onSubmit} />);
|
||||
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(<EventForm onSubmit={onSubmit} />);
|
||||
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(<EventForm onSubmit={vi.fn()} />);
|
||||
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));
|
||||
|
||||
@@ -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 && (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="evt-company">{t("Company")}</Label>
|
||||
<select
|
||||
id="evt-company"
|
||||
value={companyChoice}
|
||||
onChange={(e) => {
|
||||
setCompanyChoice(e.target.value);
|
||||
<Select
|
||||
value={companyChoice || NONE}
|
||||
onValueChange={(v) => {
|
||||
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"
|
||||
>
|
||||
<option value="" />
|
||||
{scope.companies.map((c) => (
|
||||
<option key={c.id} value={c.id}>{c.code}</option>
|
||||
))}
|
||||
</select>
|
||||
<SelectTrigger id="evt-company" aria-invalid={!!fieldErrors.company} className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={NONE}>{" "}</SelectItem>
|
||||
{scope.companies.map((c) => (
|
||||
<SelectItem key={c.id} value={String(c.id)}>{c.code}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{fieldErrors.company && (
|
||||
<p role="alert" className="text-sm text-destructive">
|
||||
{fieldErrors.company}
|
||||
|
||||
@@ -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 && (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="user-company">{t("Company")}</Label>
|
||||
<select
|
||||
id="user-company"
|
||||
value={company}
|
||||
onChange={(e) => setCompany(e.target.value)}
|
||||
disabled={saving}
|
||||
aria-invalid={!!fieldErrors.company}
|
||||
className="h-9 w-full rounded-md border bg-background px-2 text-sm"
|
||||
>
|
||||
<option value="" />
|
||||
{scope.companies.map((c) => (
|
||||
<option key={c.id} value={c.id}>{c.code}</option>
|
||||
))}
|
||||
<option value="super">{t("CompanySuperAdmin")}</option>
|
||||
</select>
|
||||
<Select value={company || NONE} onValueChange={(v) => setCompany(v === NONE ? "" : v)} disabled={saving}>
|
||||
<SelectTrigger id="user-company" aria-invalid={!!fieldErrors.company} className="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={NONE}>{" "}</SelectItem>
|
||||
{scope.companies.map((c) => (
|
||||
<SelectItem key={c.id} value={String(c.id)}>{c.code}</SelectItem>
|
||||
))}
|
||||
<SelectItem value="super">{t("CompanySuperAdmin")}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{fieldErrors.company && (
|
||||
<p role="alert" className="text-sm text-destructive">
|
||||
{fieldErrors.company}
|
||||
|
||||
@@ -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<typeof userEvent.setup>, 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"));
|
||||
|
||||
@@ -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<string, string> = {
|
||||
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() {
|
||||
</div>
|
||||
|
||||
{field("salespersonId", t("LeadSalesperson"),
|
||||
<select {...fieldProps("salespersonId")} className={SELECT_CLASS} value={salespersonId} onChange={(e) => setSalespersonId(e.target.value)} disabled={busy}>
|
||||
<option value="">{t("LeadNone")}</option>
|
||||
{salespeople.map((s) => <option key={s.id} value={String(s.id)}>{s.name}</option>)}
|
||||
</select>)}
|
||||
<Select value={salespersonId || NONE} onValueChange={(v) => setSalespersonId(v === NONE ? "" : v)} disabled={busy}>
|
||||
<SelectTrigger {...fieldProps("salespersonId")} className="min-h-11 w-full"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={NONE}>{t("LeadNone")}</SelectItem>
|
||||
{salespeople.map((s) => <SelectItem key={s.id} value={String(s.id)}>{s.name}</SelectItem>)}
|
||||
</SelectContent>
|
||||
</Select>)}
|
||||
{field("temperature", t("LeadTemperature"),
|
||||
<select {...fieldProps("temperature")} className={SELECT_CLASS} value={temperature} onChange={(e) => setTemperature(e.target.value)} disabled={busy}>
|
||||
<option value="">{t("LeadNone")}</option>
|
||||
{TEMPERATURES.map(([v, k]) => <option key={v} value={v}>{t(k)}</option>)}
|
||||
</select>)}
|
||||
<Select value={temperature || NONE} onValueChange={(v) => setTemperature(v === NONE ? "" : v)} disabled={busy}>
|
||||
<SelectTrigger {...fieldProps("temperature")} className="min-h-11 w-full"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={NONE}>{t("LeadNone")}</SelectItem>
|
||||
{TEMPERATURES.map(([v, k]) => <SelectItem key={v} value={v}>{t(k)}</SelectItem>)}
|
||||
</SelectContent>
|
||||
</Select>)}
|
||||
{field("status", t("LeadStatus"),
|
||||
<select {...fieldProps("status")} className={SELECT_CLASS} value={status} onChange={(e) => setStatus(e.target.value)} disabled={busy}>
|
||||
{STATUSES.map(([v, k]) => <option key={v} value={v}>{t(k)}</option>)}
|
||||
</select>)}
|
||||
<Select value={status} onValueChange={setStatus} disabled={busy}>
|
||||
<SelectTrigger {...fieldProps("status")} className="min-h-11 w-full"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
{STATUSES.map(([v, k]) => <SelectItem key={v} value={v}>{t(k)}</SelectItem>)}
|
||||
</SelectContent>
|
||||
</Select>)}
|
||||
|
||||
<fieldset {...fieldProps("interestIds")} className="space-y-1">
|
||||
<legend className="mb-1.5 text-sm font-medium">{t("LeadInterests")}</legend>
|
||||
|
||||
@@ -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<typeof userEvent.setup>, 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<string, unknown> } = {}) =>
|
||||
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 () => {
|
||||
|
||||
@@ -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<string, string> = {
|
||||
};
|
||||
// Codes that name their field themselves when the server omits details.field.
|
||||
const IMPLIED_FIELD: Record<string, string> = { 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"),
|
||||
<select {...fieldProps("salespersonId")} className={SELECT_CLASS} value={salespersonId} onChange={(e) => setSalespersonId(e.target.value)} disabled={busy}>
|
||||
<option value="">{t("LeadNone")}</option>
|
||||
{salespeople.map((s) => <option key={s.id} value={String(s.id)}>{s.name}</option>)}
|
||||
</select>)}
|
||||
<Select value={salespersonId || NONE} onValueChange={(v) => setSalespersonId(v === NONE ? "" : v)} disabled={busy}>
|
||||
<SelectTrigger {...fieldProps("salespersonId")} className="min-h-11 w-full"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={NONE}>{t("LeadNone")}</SelectItem>
|
||||
{salespeople.map((s) => <SelectItem key={s.id} value={String(s.id)}>{s.name}</SelectItem>)}
|
||||
</SelectContent>
|
||||
</Select>)}
|
||||
{field("temperature", t("LeadTemperature"),
|
||||
<select {...fieldProps("temperature")} className={SELECT_CLASS} value={temperature} onChange={(e) => setTemperature(e.target.value)} disabled={busy}>
|
||||
<option value="">{t("LeadNone")}</option>
|
||||
{TEMPERATURES.map(([v, k]) => <option key={v} value={v}>{t(k)}</option>)}
|
||||
</select>)}
|
||||
<Select value={temperature || NONE} onValueChange={(v) => setTemperature(v === NONE ? "" : v)} disabled={busy}>
|
||||
<SelectTrigger {...fieldProps("temperature")} className="min-h-11 w-full"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={NONE}>{t("LeadNone")}</SelectItem>
|
||||
{TEMPERATURES.map(([v, k]) => <SelectItem key={v} value={v}>{t(k)}</SelectItem>)}
|
||||
</SelectContent>
|
||||
</Select>)}
|
||||
{field("status", t("LeadStatus"),
|
||||
<select {...fieldProps("status")} className={SELECT_CLASS} value={status} onChange={(e) => setStatus(e.target.value)} disabled={busy}>
|
||||
{STATUSES.map(([v, k]) => <option key={v} value={v}>{t(k)}</option>)}
|
||||
</select>)}
|
||||
<Select value={status} onValueChange={setStatus} disabled={busy}>
|
||||
<SelectTrigger {...fieldProps("status")} className="min-h-11 w-full"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
{STATUSES.map(([v, k]) => <SelectItem key={v} value={v}>{t(k)}</SelectItem>)}
|
||||
</SelectContent>
|
||||
</Select>)}
|
||||
|
||||
<fieldset {...fieldProps("interestIds")} className="space-y-1">
|
||||
<legend className="mb-1.5 text-sm font-medium">{t("LeadInterests")}</legend>
|
||||
|
||||
Reference in new issue
Block a user