fix(ui): drop the leftover organization setter calls in the key edit team handler

The previous commit derived the organization from the form and removed the
useState behind it, but handleTeamChange still called the deleted setter, so
the dashboard build failed to type check and picking a team with an
organization threw at runtime.

The form.setValue calls next to them already carry the organization, so the
setter calls only had to go. Adds a test that picks a team with an
organization and asserts the form adopts and submits it.
This commit is contained in:
mateo-berri 2026-09-03 03:15:47 -07:00
parent ce8179b2c0
commit 2223084ce6
2 changed files with 37 additions and 2 deletions

View file

@ -1502,6 +1502,43 @@ describe("KeyEditView", () => {
expect(screen.queryByRole("option", { name: /Alpha/ })).not.toBeInTheDocument();
});
it("should adopt the organization of a team picked in the form", async () => {
const onSubmitMock = vi.fn().mockResolvedValue(undefined);
renderWithProviders(
<KeyEditView
keyData={{ ...MOCK_KEY_DATA, organization_id: null, org_id: null }}
teams={[
{ team_id: "team-a", team_alias: "Alpha", organization_id: "org-1" },
{ team_id: "team-b", team_alias: "Beta", organization_id: "org-2" },
]}
onCancel={() => {}}
onSubmit={onSubmitMock}
accessToken=""
userID=""
userRole="Admin"
premiumUser={false}
/>,
);
await screen.findByRole("button", { name: /save changes/i });
expect(screen.getByLabelText("Organization")).toHaveValue("");
await userEvent.click(screen.getByLabelText("Team ID"));
await userEvent.click(await screen.findByRole("option", { name: /Beta/ }));
await waitFor(() => {
expect(screen.getByLabelText("Organization")).toHaveValue("Sales");
});
await userEvent.click(screen.getByRole("button", { name: /save changes/i }));
await waitFor(() => {
expect(onSubmitMock).toHaveBeenCalled();
});
expect(onSubmitMock.mock.calls[0][0].organization_id).toBe("org-2");
});
it("should initialize organization from keyData", async () => {
const keyWithOrg = {
...MOCK_KEY_DATA,

View file

@ -312,10 +312,8 @@ export function KeyEditView({
setField(teamId);
const selectedTeam = teams?.find((t) => t.team_id === teamId) || null;
if (selectedTeam?.organization_id) {
setSelectedOrganizationId(selectedTeam.organization_id);
form.setValue("organization_id", selectedTeam.organization_id);
} else if (!teamId) {
setSelectedOrganizationId(null);
form.setValue("organization_id", undefined);
}
};