fix: no empty row in the company dropdowns

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 19:53:22 +08:00
1 parent a84128cb83
commit 91675ffb30
3 files changed
+18 -9

No files matched your search

@@ -107,6 +107,13 @@ describe("UserForm company", () => {
await user.click(screen.getByRole("button", { name: /create|save/i }));
expect(await screen.findByText("Choose a company.")).toBeInTheDocument();
});
it("lists only the company codes and Super admin in the Company menu, with no blank option", async () => {
mocks.useCompanyScope.mockReturnValue(scope(undefined));
const user = userEvent.setup();
render(<UserForm onSubmit={vi.fn()} />);
await user.click(await screen.findByRole("combobox", { name: "Company" }));
expect((await screen.findAllByRole("option")).map((o) => o.textContent)).toEqual(["INS", "CV", "Super admin (no company)"]);
});
});
describe("EventForm company", () => {
@@ -163,4 +170,12 @@ describe("EventForm company required", () => {
expect(onSubmit).not.toHaveBeenCalled();
expect(await screen.findByText("Choose a company.")).toBeInTheDocument();
});
it("lists only the company codes in the Company menu, with no blank option", async () => {
mocks.useCompanyScope.mockReturnValue(scope(undefined));
const user = userEvent.setup();
render(<EventForm onSubmit={vi.fn()} />);
await user.click(await screen.findByRole("combobox", { name: "Company" }));
expect((await screen.findAllByRole("option")).map((o) => o.textContent)).toEqual(["INS", "CV"]);
});
});
@@ -16,8 +16,6 @@ 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;
@@ -184,9 +182,9 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
<div className="space-y-1.5">
<Label htmlFor="evt-company">{t("Company")}</Label>
<Select
value={companyChoice || NONE}
value={companyChoice}
onValueChange={(v) => {
setCompanyChoice(v === NONE ? "" : v);
setCompanyChoice(v);
setSelectedIds(new Set()); // the team is company-specific
}}
disabled={saving}
@@ -195,7 +193,6 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value={NONE}>{" "}</SelectItem>
{scope.companies.map((c) => (
<SelectItem key={c.id} value={String(c.id)}>{c.code}</SelectItem>
))}
@@ -23,8 +23,6 @@ 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.
@@ -224,12 +222,11 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF
{showCompany && (
<div className="space-y-1.5">
<Label htmlFor="user-company">{t("Company")}</Label>
<Select value={company || NONE} onValueChange={(v) => setCompany(v === NONE ? "" : v)} disabled={saving}>
<Select value={company} onValueChange={(v) => setCompany(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>
))}