@umituz/web-dashboard 7.7.0 → 7.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +4 -2
  2. package/package.json +3 -1
  3. package/src/domains/onboarding/components/OnboardingFlow.tsx +9 -0
  4. package/src/domains/onboarding/components/screens/OrganizationDetailsScreen.test.tsx +115 -0
  5. package/src/domains/onboarding/components/screens/OrganizationDetailsScreen.tsx +74 -0
  6. package/src/domains/onboarding/components/screens/index.ts +2 -0
  7. package/src/domains/onboarding/index.ts +3 -0
  8. package/src/domains/onboarding/types/index.ts +7 -1
  9. package/src/domains/onboarding/types/labels.ts +4 -0
  10. package/src/domains/onboarding/types/screens.ts +12 -0
  11. package/src/domains/onboarding/validation/screen-config-check.ts +1 -0
  12. package/src/domains/onboarding/validation/validation.test.ts +7 -1
  13. package/src/domains/organization/OrganizationContext.test.tsx +113 -0
  14. package/src/domains/organization/OrganizationContext.tsx +111 -0
  15. package/src/domains/organization/components/InviteForm.test.tsx +72 -0
  16. package/src/domains/organization/components/InviteForm.tsx +101 -0
  17. package/src/domains/organization/components/OrganizationCard.test.tsx +44 -0
  18. package/src/domains/organization/components/OrganizationCard.tsx +87 -0
  19. package/src/domains/organization/components/OrganizationMembersPanel.test.tsx +167 -0
  20. package/src/domains/organization/components/OrganizationMembersPanel.tsx +231 -0
  21. package/src/domains/organization/components/OrganizationSwitcher.test.tsx +66 -0
  22. package/src/domains/organization/components/OrganizationSwitcher.tsx +46 -0
  23. package/src/domains/organization/components/index.ts +11 -0
  24. package/src/domains/organization/index.ts +31 -0
  25. package/src/domains/organization/types.ts +81 -0
  26. package/src/domains/organization/vocab.test.ts +49 -0
  27. package/src/domains/organization/vocab.ts +70 -0
  28. package/src/domains/settings/components/UserManagementTable.tsx +54 -1
  29. package/src/styles/chrome.css +213 -0
@@ -0,0 +1,101 @@
1
+ import { useState } from "react";
2
+ import { Button, Input, NativeSelect } from "@umituz/web-design-system/atoms";
3
+ import type { RoleInfo } from "../../permissions/types";
4
+ import type { OrgInviteInput } from "../types";
5
+
6
+ export interface InviteFormLabels {
7
+ name: string;
8
+ email: string;
9
+ role: string;
10
+ submit: string;
11
+ invalidEmail: string;
12
+ }
13
+
14
+ export interface InviteFormProps {
15
+ roles: readonly RoleInfo[];
16
+ defaultRole?: string;
17
+ labels?: Partial<InviteFormLabels>;
18
+ busy?: boolean;
19
+ onInvite: (input: OrgInviteInput) => void;
20
+ onCancel?: () => void;
21
+ cancelLabel?: string;
22
+ }
23
+
24
+ const DEFAULT_LABELS: InviteFormLabels = {
25
+ name: "Full name",
26
+ email: "Email",
27
+ role: "Role",
28
+ submit: "Send invite",
29
+ invalidEmail: "Enter a valid email address",
30
+ };
31
+
32
+ const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
33
+
34
+ export const InviteForm = ({
35
+ roles,
36
+ defaultRole,
37
+ labels,
38
+ busy = false,
39
+ onInvite,
40
+ onCancel,
41
+ cancelLabel = "Cancel",
42
+ }: InviteFormProps) => {
43
+ const text = { ...DEFAULT_LABELS, ...labels };
44
+ const [name, setName] = useState("");
45
+ const [email, setEmail] = useState("");
46
+ const [role, setRole] = useState(defaultRole ?? roles[0]?.key ?? "");
47
+
48
+ const emailValid = EMAIL_PATTERN.test(email.trim());
49
+ const touched = email.length > 0;
50
+ const canSubmit = emailValid && role.length > 0 && !busy;
51
+
52
+ const submit = () => {
53
+ if (!canSubmit) return;
54
+ onInvite({ email: email.trim(), ...(name.trim() ? { name: name.trim() } : {}), role });
55
+ setName("");
56
+ setEmail("");
57
+ };
58
+
59
+ return (
60
+ <form
61
+ className="udb-invite"
62
+ onSubmit={(event) => {
63
+ event.preventDefault();
64
+ submit();
65
+ }}
66
+ >
67
+ <div className="udb-invite__grid">
68
+ <Input
69
+ label={text.name}
70
+ value={name}
71
+ autoComplete="off"
72
+ onChange={(event) => setName(event.target.value)}
73
+ />
74
+ <Input
75
+ label={text.email}
76
+ type="email"
77
+ value={email}
78
+ error={touched && !emailValid ? text.invalidEmail : undefined}
79
+ autoComplete="off"
80
+ onChange={(event) => setEmail(event.target.value)}
81
+ />
82
+ <NativeSelect
83
+ label={text.role}
84
+ value={role}
85
+ options={roles.map((entry) => ({ value: entry.key, label: entry.label }))}
86
+ onValueChange={setRole}
87
+ />
88
+ </div>
89
+ <div className="udb-invite__actions">
90
+ <Button type="submit" disabled={!canSubmit} loading={busy}>
91
+ {text.submit}
92
+ </Button>
93
+ {onCancel && (
94
+ <Button type="button" variant="secondary" onClick={onCancel}>
95
+ {cancelLabel}
96
+ </Button>
97
+ )}
98
+ </div>
99
+ </form>
100
+ );
101
+ };
@@ -0,0 +1,44 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { OrganizationCard } from "./OrganizationCard";
4
+ import type { OrganizationRecord } from "../types";
5
+
6
+ const ORG: OrganizationRecord = {
7
+ id: "org-1",
8
+ name: "Northwind Labs",
9
+ legalName: "Northwind Laboratories GmbH",
10
+ plan: "pro",
11
+ };
12
+
13
+ describe("OrganizationCard", () => {
14
+ it("renders initials, plan, legal name and member count", () => {
15
+ render(<OrganizationCard organization={ORG} memberCount={4} />);
16
+ expect(screen.getByText("NL")).not.toBeNull();
17
+ expect(screen.getByText("Plan: pro")).not.toBeNull();
18
+ expect(screen.getByText("Northwind Laboratories GmbH")).not.toBeNull();
19
+ expect(screen.getByText("4 members")).not.toBeNull();
20
+ });
21
+
22
+ it("shows the sole-member hint with the invite CTA at one member", () => {
23
+ const onInvite = vi.fn();
24
+ render(<OrganizationCard organization={ORG} memberCount={1} onInvite={onInvite} />);
25
+ fireEvent.click(screen.getByText("Invite teammates"));
26
+ expect(onInvite).toHaveBeenCalledTimes(1);
27
+ });
28
+
29
+ it("hides the sole-member hint without an invite handler or with a team", () => {
30
+ const { rerender } = render(<OrganizationCard organization={ORG} memberCount={1} />);
31
+ expect(screen.queryByText("Invite teammates")).toBeNull();
32
+ rerender(
33
+ <OrganizationCard organization={ORG} memberCount={3} onInvite={() => undefined} />,
34
+ );
35
+ expect(screen.queryByText("Invite teammates")).toBeNull();
36
+ });
37
+
38
+ it("becomes a clickable card with onClick", () => {
39
+ const onClick = vi.fn();
40
+ render(<OrganizationCard organization={ORG} onClick={onClick} />);
41
+ fireEvent.click(screen.getByText("Northwind Labs"));
42
+ expect(onClick).toHaveBeenCalledTimes(1);
43
+ });
44
+ });
@@ -0,0 +1,87 @@
1
+ import { CoverArt } from "@umituz/web-design-system/organisms";
2
+ import { Button } from "@umituz/web-design-system/atoms";
3
+ import type { OrganizationRecord } from "../types";
4
+ import { initialsOf } from "../vocab";
5
+
6
+ export interface OrganizationCardLabels {
7
+ plan: string;
8
+ memberCountPattern: string;
9
+ soleOwnerHint: string;
10
+ inviteCta: string;
11
+ }
12
+
13
+ export interface OrganizationCardProps {
14
+ organization: OrganizationRecord;
15
+ memberCount?: number;
16
+ /** Shows the "invite your team" hint + CTA when memberCount is 1. */
17
+ onInvite?: () => void;
18
+ labels?: Partial<OrganizationCardLabels>;
19
+ onClick?: () => void;
20
+ }
21
+
22
+ const DEFAULT_LABELS: OrganizationCardLabels = {
23
+ plan: "Plan",
24
+ memberCountPattern: "{count} members",
25
+ soleOwnerHint: "You are a one-person organization — invite teammates to collaborate.",
26
+ inviteCta: "Invite teammates",
27
+ };
28
+
29
+ const formatCount = (pattern: string, count: number): string =>
30
+ pattern.replace("{count}", String(count));
31
+
32
+ export const OrganizationCard = ({
33
+ organization,
34
+ memberCount,
35
+ onInvite,
36
+ labels,
37
+ onClick,
38
+ }: OrganizationCardProps) => {
39
+ const text = { ...DEFAULT_LABELS, ...labels };
40
+ const soleMember = memberCount === 1 && Boolean(onInvite);
41
+
42
+ const body = (
43
+ <>
44
+ <CoverArt seed={organization.name} ratio="3/2" rounded="top">
45
+ <span className="udb-org-card__initials">{initialsOf(organization.name)}</span>
46
+ </CoverArt>
47
+ <div className="udb-org-card__body">
48
+ <div className="udb-org-card__head">
49
+ <div>
50
+ <h3 className="udb-org-card__name">{organization.name}</h3>
51
+ {organization.legalName && organization.legalName !== organization.name && (
52
+ <p className="udb-org-card__legal">{organization.legalName}</p>
53
+ )}
54
+ </div>
55
+ {organization.plan && (
56
+ <span className="udb-org-card__plan">
57
+ {text.plan}: {organization.plan}
58
+ </span>
59
+ )}
60
+ </div>
61
+ {memberCount !== undefined && (
62
+ <p className="udb-org-card__meta">
63
+ {formatCount(text.memberCountPattern, memberCount)}
64
+ </p>
65
+ )}
66
+ {soleMember && (
67
+ <div className="udb-org-card__hint">
68
+ <p>{text.soleOwnerHint}</p>
69
+ <Button size="sm" onClick={onInvite}>
70
+ {text.inviteCta}
71
+ </Button>
72
+ </div>
73
+ )}
74
+ </div>
75
+ </>
76
+ );
77
+
78
+ if (onClick) {
79
+ return (
80
+ <button type="button" className="udb-org-card udb-org-card--clickable" onClick={onClick}>
81
+ {body}
82
+ </button>
83
+ );
84
+ }
85
+
86
+ return <div className="udb-org-card">{body}</div>;
87
+ };
@@ -0,0 +1,167 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { OrganizationMembersPanel } from "./OrganizationMembersPanel";
4
+ import type { OrgInvitation, OrgMember } from "../types";
5
+ import type { RoleInfo } from "../../permissions/types";
6
+
7
+ const ROLES: readonly RoleInfo[] = [
8
+ { key: "owner", label: "Owner" },
9
+ { key: "member", label: "Member" },
10
+ ];
11
+
12
+ const MEMBERS: readonly OrgMember[] = [
13
+ {
14
+ id: "u-1",
15
+ name: "Ada Lovelace",
16
+ email: "ada@example.com",
17
+ role: "owner",
18
+ status: "active",
19
+ isOwner: true,
20
+ },
21
+ {
22
+ id: "u-2",
23
+ name: "Grace Hopper",
24
+ email: "grace@example.com",
25
+ role: "member",
26
+ status: "active",
27
+ },
28
+ {
29
+ id: "u-3",
30
+ name: "Katherine Johnson",
31
+ email: "katherine@example.com",
32
+ role: "member",
33
+ status: "active",
34
+ },
35
+ ];
36
+
37
+ const INVITATIONS: readonly OrgInvitation[] = [
38
+ {
39
+ id: "inv-1",
40
+ email: "new@example.com",
41
+ role: "member",
42
+ status: "pending",
43
+ },
44
+ {
45
+ id: "inv-2",
46
+ email: "gone@example.com",
47
+ role: "member",
48
+ status: "revoked",
49
+ },
50
+ ];
51
+
52
+ const mount = (props: Partial<Parameters<typeof OrganizationMembersPanel>[0]> = {}) =>
53
+ render(
54
+ <OrganizationMembersPanel members={MEMBERS} roles={ROLES} currentMemberId="u-2" {...props} />,
55
+ );
56
+
57
+ describe("OrganizationMembersPanel", () => {
58
+ it("renders member rows with status badges and the member count", () => {
59
+ mount();
60
+ expect(screen.getByText(/Members/).textContent).toContain("(3)");
61
+ expect(screen.getAllByText("Active")).toHaveLength(3);
62
+ expect(screen.getByText("ada@example.com")).not.toBeNull();
63
+ });
64
+
65
+ it("opens the invite form on demand and hands the payload to onInvite", () => {
66
+ const onInvite = vi.fn();
67
+ mount({ onInvite });
68
+ fireEvent.click(screen.getByText("Invite member"));
69
+ fireEvent.change(screen.getByLabelText("Email"), {
70
+ target: { value: "new@example.com" },
71
+ });
72
+ fireEvent.click(screen.getByText("Send invite"));
73
+ expect(onInvite).toHaveBeenCalledWith({
74
+ email: "new@example.com",
75
+ role: "owner",
76
+ });
77
+ });
78
+
79
+ it("locks the self row and owner rows against removal and role changes", () => {
80
+ const onRemove = vi.fn();
81
+ const onRoleChange = vi.fn();
82
+ mount({ onRemove, onRoleChange });
83
+
84
+ const removeButtons = screen
85
+ .queryAllByRole("button")
86
+ .filter((b) => b.textContent === "Remove");
87
+ expect(removeButtons).toHaveLength(1);
88
+ fireEvent.click(removeButtons[0]!);
89
+ expect(onRemove).toHaveBeenCalledWith("u-3");
90
+
91
+ const selects = screen.getAllByLabelText("Role");
92
+ expect(selects).toHaveLength(1);
93
+ fireEvent.change(selects[0]!, { target: { value: "owner" } });
94
+ expect(onRoleChange).toHaveBeenCalledWith("u-3", "owner");
95
+ });
96
+
97
+ it("hides invite and remove affordances when handlers are absent", () => {
98
+ mount();
99
+ expect(screen.queryByText("Invite member")).toBeNull();
100
+ expect(screen.queryAllByRole("button")).toHaveLength(0);
101
+ });
102
+
103
+ it("offers ownership transfer only to owners, never on self or owner rows", () => {
104
+ const onTransferOwnership = vi.fn();
105
+
106
+ const { unmount } = mount({ onTransferOwnership });
107
+ expect(screen.queryByText("Make owner")).toBeNull();
108
+ unmount();
109
+
110
+ mount({ onTransferOwnership, currentMemberId: "u-1" });
111
+ const transferButtons = screen
112
+ .queryAllByRole("button")
113
+ .filter((b) => b.textContent === "Make owner");
114
+ expect(transferButtons).toHaveLength(2);
115
+ fireEvent.click(transferButtons[0]!);
116
+ expect(onTransferOwnership).toHaveBeenCalledWith("u-2");
117
+ });
118
+
119
+ it("lets non-owners leave but never the owner", () => {
120
+ const onLeave = vi.fn();
121
+
122
+ mount({ onLeave });
123
+ fireEvent.click(screen.getByText("Leave organization"));
124
+ expect(onLeave).toHaveBeenCalledTimes(1);
125
+
126
+ const { unmount } = mount({ onLeave });
127
+ unmount();
128
+ const { container } = mount({ onLeave, currentMemberId: "u-1" });
129
+ expect(
130
+ Array.from(container.querySelectorAll("button")).filter(
131
+ (b) => b.textContent === "Leave organization",
132
+ ),
133
+ ).toHaveLength(0);
134
+ });
135
+
136
+ it("shows seat usage and blocks the invite form at the limit", () => {
137
+ mount({ onInvite: () => undefined, seatLimit: 3 });
138
+ expect(screen.getByText("Seat limit reached")).not.toBeNull();
139
+ expect(screen.queryByText("Invite member")).toBeNull();
140
+
141
+ const { unmount } = mount({ onInvite: () => undefined, seatLimit: 5 });
142
+ unmount();
143
+ mount({ onInvite: () => undefined, seatLimit: 5 });
144
+ expect(screen.getByText("3 of 5 seats used")).not.toBeNull();
145
+ expect(screen.getByText("Invite member")).not.toBeNull();
146
+ });
147
+
148
+ it("renders invitations in their own section with pending-only actions", () => {
149
+ const onRevoke = vi.fn();
150
+ const onResend = vi.fn();
151
+ mount({ invitations: INVITATIONS, onRevokeInvitation: onRevoke, onResendInvitation: onResend });
152
+
153
+ expect(screen.getByText("Invitations")).not.toBeNull();
154
+ expect(screen.getByText("new@example.com")).not.toBeNull();
155
+ expect(screen.getByText("Pending")).not.toBeNull();
156
+ expect(screen.getByText("Revoked")).not.toBeNull();
157
+
158
+ fireEvent.click(screen.getByText("Resend"));
159
+ expect(onResend).toHaveBeenCalledWith("inv-1");
160
+ fireEvent.click(screen.getByText("Revoke"));
161
+ expect(onRevoke).toHaveBeenCalledWith("inv-1");
162
+
163
+ expect(
164
+ screen.queryAllByRole("button").filter((b) => b.textContent === "Resend"),
165
+ ).toHaveLength(1);
166
+ });
167
+ });
@@ -0,0 +1,231 @@
1
+ import { useMemo, useState } from "react";
2
+ import { Button } from "@umituz/web-design-system/atoms";
3
+ import { StatusBadge } from "@umituz/web-design-system/organisms";
4
+ import type { RoleInfo, RoleKey } from "../../permissions/types";
5
+ import { UserManagementTable } from "../../settings/components/UserManagementTable";
6
+ import type {
7
+ InvitationStatus,
8
+ MemberStatus,
9
+ OrgInviteInput,
10
+ OrgInvitation,
11
+ OrgMember,
12
+ } from "../types";
13
+ import { invitationStatusVocab, memberStatusVocab } from "../vocab";
14
+ import { InviteForm } from "./InviteForm";
15
+
16
+ export interface OrganizationMembersPanelLabels {
17
+ title: string;
18
+ invite: string;
19
+ seatsPattern: string;
20
+ seatsFull: string;
21
+ leave: string;
22
+ invitationsTitle: string;
23
+ resendLabel: string;
24
+ revokeLabel: string;
25
+ makeOwnerLabel: string;
26
+ nameColumn: string;
27
+ emailColumn: string;
28
+ roleColumn: string;
29
+ statusColumn: string;
30
+ removeLabel: string;
31
+ empty: string;
32
+ }
33
+
34
+ export interface OrganizationMembersPanelProps {
35
+ members: readonly OrgMember[];
36
+ roles: readonly RoleInfo[];
37
+ /** Self rows are always locked; owner rows lock by default. */
38
+ currentMemberId?: string;
39
+ /** Outstanding invitations, rendered in their own section. */
40
+ invitations?: readonly OrgInvitation[];
41
+ /** Blocks the invite form once members reach the seat limit. */
42
+ seatLimit?: number;
43
+ onRoleChange?: (memberId: string, role: RoleKey) => void;
44
+ onRemove?: (memberId: string) => void;
45
+ /** Atomic backend transfer is the host's job; the old owner usually drops to admin. */
46
+ onTransferOwnership?: (memberId: string) => void;
47
+ /** Self-service exit; hide it for owners — the last owner cannot leave. */
48
+ onLeave?: () => void;
49
+ onInvite?: (input: OrgInviteInput) => void;
50
+ onRevokeInvitation?: (invitationId: string) => void;
51
+ onResendInvitation?: (invitationId: string) => void;
52
+ inviteBusy?: boolean;
53
+ statusLabels?: Partial<Record<MemberStatus, string>>;
54
+ invitationStatusLabels?: Partial<Record<InvitationStatus, string>>;
55
+ labels?: Partial<OrganizationMembersPanelLabels>;
56
+ }
57
+
58
+ const DEFAULT_LABELS: OrganizationMembersPanelLabels = {
59
+ title: "Members",
60
+ invite: "Invite member",
61
+ seatsPattern: "{used} of {limit} seats used",
62
+ seatsFull: "Seat limit reached",
63
+ leave: "Leave organization",
64
+ invitationsTitle: "Invitations",
65
+ resendLabel: "Resend",
66
+ revokeLabel: "Revoke",
67
+ makeOwnerLabel: "Make owner",
68
+ nameColumn: "Name",
69
+ emailColumn: "Email",
70
+ roleColumn: "Role",
71
+ statusColumn: "Status",
72
+ removeLabel: "Remove",
73
+ empty: "No members yet",
74
+ };
75
+
76
+ const formatSeats = (pattern: string, used: number, limit: number): string =>
77
+ pattern.replace("{used}", String(used)).replace("{limit}", String(limit));
78
+
79
+ export const OrganizationMembersPanel = ({
80
+ members,
81
+ roles,
82
+ currentMemberId,
83
+ invitations,
84
+ seatLimit,
85
+ onRoleChange,
86
+ onRemove,
87
+ onTransferOwnership,
88
+ onLeave,
89
+ onInvite,
90
+ onRevokeInvitation,
91
+ onResendInvitation,
92
+ inviteBusy = false,
93
+ statusLabels,
94
+ invitationStatusLabels,
95
+ labels,
96
+ }: OrganizationMembersPanelProps) => {
97
+ const text = { ...DEFAULT_LABELS, ...labels };
98
+ const [inviting, setInviting] = useState(false);
99
+
100
+ const memberVocab = useMemo(() => memberStatusVocab(statusLabels), [statusLabels]);
101
+ const inviteVocab = useMemo(
102
+ () => invitationStatusVocab(invitationStatusLabels),
103
+ [invitationStatusLabels],
104
+ );
105
+
106
+ const selfMember = useMemo(
107
+ () => (currentMemberId ? members.find((m) => m.id === currentMemberId) : undefined),
108
+ [members, currentMemberId],
109
+ );
110
+ const viewerIsOwner = Boolean(selfMember?.isOwner);
111
+
112
+ const seatsFull = seatLimit !== undefined && members.length >= seatLimit;
113
+ const inviteEnabled = Boolean(onInvite) && !seatsFull;
114
+ const canLeave = Boolean(onLeave) && Boolean(selfMember) && !viewerIsOwner;
115
+ const showInvitations = Boolean(invitations && invitations.length > 0);
116
+
117
+ const rowActions =
118
+ onTransferOwnership && viewerIsOwner
119
+ ? (member: { id: string; isOwner?: boolean }) =>
120
+ member.isOwner || member.id === currentMemberId ? null : (
121
+ <button
122
+ type="button"
123
+ className="udb-link-button udb-link-button--muted"
124
+ onClick={() => onTransferOwnership(member.id)}
125
+ >
126
+ {text.makeOwnerLabel}
127
+ </button>
128
+ )
129
+ : undefined;
130
+
131
+ const toggleInviting = () => setInviting((open) => !open);
132
+
133
+ return (
134
+ <section className="udb-members">
135
+ <header className="udb-members__head">
136
+ <h3 className="udb-members__title">
137
+ {text.title} <span className="udb-members__count">({members.length})</span>
138
+ </h3>
139
+ <div className="udb-members__head-actions">
140
+ {seatLimit !== undefined && (
141
+ <span className="udb-members__seats">
142
+ {seatsFull ? text.seatsFull : formatSeats(text.seatsPattern, members.length, seatLimit)}
143
+ </span>
144
+ )}
145
+ {inviteEnabled && (
146
+ <Button size="sm" variant="secondary" onClick={toggleInviting}>
147
+ {text.invite}
148
+ </Button>
149
+ )}
150
+ {canLeave && (
151
+ <Button size="sm" variant="ghost" onClick={onLeave}>
152
+ {text.leave}
153
+ </Button>
154
+ )}
155
+ </div>
156
+ </header>
157
+
158
+ {inviteEnabled && inviting && (
159
+ <div className="udb-members__invite">
160
+ <InviteForm
161
+ roles={roles}
162
+ busy={inviteBusy}
163
+ onInvite={(input) => onInvite?.(input)}
164
+ onCancel={toggleInviting}
165
+ />
166
+ </div>
167
+ )}
168
+
169
+ <UserManagementTable
170
+ users={[...members]}
171
+ roles={[...roles]}
172
+ labels={{
173
+ nameColumn: text.nameColumn,
174
+ emailColumn: text.emailColumn,
175
+ roleColumn: text.roleColumn,
176
+ statusColumn: text.statusColumn,
177
+ removeLabel: text.removeLabel,
178
+ empty: text.empty,
179
+ }}
180
+ statusVocab={memberVocab}
181
+ onRoleChange={onRoleChange}
182
+ onRemove={onRemove}
183
+ rowActions={rowActions}
184
+ isRowLocked={(user) => user.id === currentMemberId || Boolean(user.isOwner)}
185
+ />
186
+
187
+ {showInvitations && (
188
+ <div className="udb-members__invitations">
189
+ <h4 className="udb-members__invitations-title">{text.invitationsTitle}</h4>
190
+ <ul className="udb-members__invitation-list">
191
+ {invitations!.map((invitation) => (
192
+ <li key={invitation.id} className="udb-members__invitation">
193
+ <div className="udb-members__invitation-info">
194
+ <span className="udb-members__invitation-email">{invitation.email}</span>
195
+ <span className="udb-members__invitation-role">
196
+ {roles.find((role) => role.key === invitation.role)?.label ?? invitation.role}
197
+ </span>
198
+ </div>
199
+ <div className="udb-members__invitation-side">
200
+ <StatusBadge vocab={inviteVocab} value={invitation.status} />
201
+ {invitation.status === "pending" && (
202
+ <div className="udb-members__invitation-actions">
203
+ {onResendInvitation && (
204
+ <button
205
+ type="button"
206
+ className="udb-link-button udb-link-button--muted"
207
+ onClick={() => onResendInvitation(invitation.id)}
208
+ >
209
+ {text.resendLabel}
210
+ </button>
211
+ )}
212
+ {onRevokeInvitation && (
213
+ <button
214
+ type="button"
215
+ className="udb-link-button"
216
+ onClick={() => onRevokeInvitation(invitation.id)}
217
+ >
218
+ {text.revokeLabel}
219
+ </button>
220
+ )}
221
+ </div>
222
+ )}
223
+ </div>
224
+ </li>
225
+ ))}
226
+ </ul>
227
+ </div>
228
+ )}
229
+ </section>
230
+ );
231
+ };
@@ -0,0 +1,66 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { OrganizationSwitcher } from "./OrganizationSwitcher";
4
+ import type { OrganizationRecord } from "../types";
5
+
6
+ const ORGS: readonly OrganizationRecord[] = [
7
+ { id: "org-1", name: "Northwind Labs" },
8
+ { id: "org-2", name: "Contoso" },
9
+ ];
10
+
11
+ describe("OrganizationSwitcher", () => {
12
+ it("renders nothing below two organizations", () => {
13
+ const { container } = render(
14
+ <OrganizationSwitcher
15
+ organizations={[ORGS[0]!]}
16
+ activeOrganizationId="org-1"
17
+ onSwitch={() => undefined}
18
+ />,
19
+ );
20
+ expect(container.firstChild).toBeNull();
21
+ });
22
+
23
+ it("lists the organizations and emits switches", () => {
24
+ const onSwitch = vi.fn();
25
+ render(
26
+ <OrganizationSwitcher
27
+ organizations={ORGS}
28
+ activeOrganizationId="org-1"
29
+ onSwitch={onSwitch}
30
+ />,
31
+ );
32
+ const select = screen.getByLabelText("Workspace") as HTMLSelectElement;
33
+ expect(select.value).toBe("org-1");
34
+ fireEvent.change(select, { target: { value: "org-2" } });
35
+ expect(onSwitch).toHaveBeenCalledWith("org-2");
36
+ });
37
+
38
+ it("leads with the personal workspace when given", () => {
39
+ const onSwitch = vi.fn();
40
+ render(
41
+ <OrganizationSwitcher
42
+ organizations={ORGS}
43
+ personalWorkspace={{ id: "personal", label: "Personal workspace" }}
44
+ activeOrganizationId="personal"
45
+ onSwitch={onSwitch}
46
+ />,
47
+ );
48
+ const select = screen.getByLabelText("Workspace") as HTMLSelectElement;
49
+ const options = Array.from(select.querySelectorAll("option"));
50
+ expect(options[0]?.textContent).toBe("Personal workspace");
51
+ expect(options).toHaveLength(3);
52
+ fireEvent.change(select, { target: { value: "org-1" } });
53
+ expect(onSwitch).toHaveBeenCalledWith("org-1");
54
+ });
55
+
56
+ it("stays hidden with a single organization and no personal workspace", () => {
57
+ const { container } = render(
58
+ <OrganizationSwitcher
59
+ organizations={[ORGS[0]!]}
60
+ personalWorkspace={{ id: "personal", label: "Personal workspace" }}
61
+ onSwitch={() => undefined}
62
+ />,
63
+ );
64
+ expect(container.firstChild).not.toBeNull();
65
+ });
66
+ });