@umituz/web-dashboard 7.8.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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/domains/organization/components/OrganizationMembersPanel.test.tsx +84 -5
- package/src/domains/organization/components/OrganizationMembersPanel.tsx +138 -12
- package/src/domains/organization/components/OrganizationSwitcher.test.tsx +30 -1
- package/src/domains/organization/components/OrganizationSwitcher.tsx +21 -8
- package/src/domains/organization/components/index.ts +1 -1
- package/src/domains/organization/index.ts +4 -2
- package/src/domains/organization/types.ts +27 -5
- package/src/domains/organization/vocab.test.ts +18 -1
- package/src/domains/organization/vocab.ts +32 -1
- package/src/domains/settings/components/UserManagementTable.tsx +25 -14
- package/src/styles/chrome.css +70 -0
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ hosts set dark values on the DS variables under `[data-theme="dark"]` /
|
|
|
45
45
|
```bash
|
|
46
46
|
@umituz/web-dashboard/styles.css # component stylesheet (udb-* BEM, incl. udb-onb-*)
|
|
47
47
|
@umituz/web-dashboard/permissions # PermissionMatrix, hasPermission, guards
|
|
48
|
-
@umituz/web-dashboard/organization # OrganizationProvider, members
|
|
48
|
+
@umituz/web-dashboard/organization # OrganizationProvider, members + invitations, seats, switcher
|
|
49
49
|
@umituz/web-dashboard/modules # DashboardModule, buildRoutes, buildNav
|
|
50
50
|
@umituz/web-dashboard/layouts # DashboardLayout, DashboardSidebar, DashboardHeader
|
|
51
51
|
@umituz/web-dashboard/settings # SettingsLayout, admin skeletons (users, matrix, audit)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.9.0",
|
|
4
4
|
"description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow permissions/module registry; udb-* stylesheet on design-system tokens",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
3
|
import { OrganizationMembersPanel } from "./OrganizationMembersPanel";
|
|
4
|
-
import type { OrgMember } from "../types";
|
|
4
|
+
import type { OrgInvitation, OrgMember } from "../types";
|
|
5
5
|
import type { RoleInfo } from "../../permissions/types";
|
|
6
6
|
|
|
7
7
|
const ROLES: readonly RoleInfo[] = [
|
|
@@ -23,7 +23,7 @@ const MEMBERS: readonly OrgMember[] = [
|
|
|
23
23
|
name: "Grace Hopper",
|
|
24
24
|
email: "grace@example.com",
|
|
25
25
|
role: "member",
|
|
26
|
-
status: "
|
|
26
|
+
status: "active",
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
id: "u-3",
|
|
@@ -34,6 +34,21 @@ const MEMBERS: readonly OrgMember[] = [
|
|
|
34
34
|
},
|
|
35
35
|
];
|
|
36
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
|
+
|
|
37
52
|
const mount = (props: Partial<Parameters<typeof OrganizationMembersPanel>[0]> = {}) =>
|
|
38
53
|
render(
|
|
39
54
|
<OrganizationMembersPanel members={MEMBERS} roles={ROLES} currentMemberId="u-2" {...props} />,
|
|
@@ -43,8 +58,7 @@ describe("OrganizationMembersPanel", () => {
|
|
|
43
58
|
it("renders member rows with status badges and the member count", () => {
|
|
44
59
|
mount();
|
|
45
60
|
expect(screen.getByText(/Members/).textContent).toContain("(3)");
|
|
46
|
-
expect(screen.
|
|
47
|
-
expect(screen.getAllByText("Active")).toHaveLength(2);
|
|
61
|
+
expect(screen.getAllByText("Active")).toHaveLength(3);
|
|
48
62
|
expect(screen.getByText("ada@example.com")).not.toBeNull();
|
|
49
63
|
});
|
|
50
64
|
|
|
@@ -68,7 +82,7 @@ describe("OrganizationMembersPanel", () => {
|
|
|
68
82
|
mount({ onRemove, onRoleChange });
|
|
69
83
|
|
|
70
84
|
const removeButtons = screen
|
|
71
|
-
.
|
|
85
|
+
.queryAllByRole("button")
|
|
72
86
|
.filter((b) => b.textContent === "Remove");
|
|
73
87
|
expect(removeButtons).toHaveLength(1);
|
|
74
88
|
fireEvent.click(removeButtons[0]!);
|
|
@@ -85,4 +99,69 @@ describe("OrganizationMembersPanel", () => {
|
|
|
85
99
|
expect(screen.queryByText("Invite member")).toBeNull();
|
|
86
100
|
expect(screen.queryAllByRole("button")).toHaveLength(0);
|
|
87
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
|
+
});
|
|
88
167
|
});
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { useMemo, useState } from "react";
|
|
2
2
|
import { Button } from "@umituz/web-design-system/atoms";
|
|
3
|
+
import { StatusBadge } from "@umituz/web-design-system/organisms";
|
|
3
4
|
import type { RoleInfo, RoleKey } from "../../permissions/types";
|
|
4
5
|
import { UserManagementTable } from "../../settings/components/UserManagementTable";
|
|
5
|
-
import type {
|
|
6
|
-
|
|
6
|
+
import type {
|
|
7
|
+
InvitationStatus,
|
|
8
|
+
MemberStatus,
|
|
9
|
+
OrgInviteInput,
|
|
10
|
+
OrgInvitation,
|
|
11
|
+
OrgMember,
|
|
12
|
+
} from "../types";
|
|
13
|
+
import { invitationStatusVocab, memberStatusVocab } from "../vocab";
|
|
7
14
|
import { InviteForm } from "./InviteForm";
|
|
8
15
|
|
|
9
16
|
export interface OrganizationMembersPanelLabels {
|
|
10
17
|
title: string;
|
|
11
18
|
invite: string;
|
|
19
|
+
seatsPattern: string;
|
|
20
|
+
seatsFull: string;
|
|
21
|
+
leave: string;
|
|
22
|
+
invitationsTitle: string;
|
|
23
|
+
resendLabel: string;
|
|
24
|
+
revokeLabel: string;
|
|
25
|
+
makeOwnerLabel: string;
|
|
12
26
|
nameColumn: string;
|
|
13
27
|
emailColumn: string;
|
|
14
28
|
roleColumn: string;
|
|
@@ -22,17 +36,35 @@ export interface OrganizationMembersPanelProps {
|
|
|
22
36
|
roles: readonly RoleInfo[];
|
|
23
37
|
/** Self rows are always locked; owner rows lock by default. */
|
|
24
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;
|
|
25
43
|
onRoleChange?: (memberId: string, role: RoleKey) => void;
|
|
26
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;
|
|
27
49
|
onInvite?: (input: OrgInviteInput) => void;
|
|
50
|
+
onRevokeInvitation?: (invitationId: string) => void;
|
|
51
|
+
onResendInvitation?: (invitationId: string) => void;
|
|
28
52
|
inviteBusy?: boolean;
|
|
29
|
-
statusLabels?: Partial<Record<
|
|
53
|
+
statusLabels?: Partial<Record<MemberStatus, string>>;
|
|
54
|
+
invitationStatusLabels?: Partial<Record<InvitationStatus, string>>;
|
|
30
55
|
labels?: Partial<OrganizationMembersPanelLabels>;
|
|
31
56
|
}
|
|
32
57
|
|
|
33
58
|
const DEFAULT_LABELS: OrganizationMembersPanelLabels = {
|
|
34
59
|
title: "Members",
|
|
35
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",
|
|
36
68
|
nameColumn: "Name",
|
|
37
69
|
emailColumn: "Email",
|
|
38
70
|
roleColumn: "Role",
|
|
@@ -41,23 +73,61 @@ const DEFAULT_LABELS: OrganizationMembersPanelLabels = {
|
|
|
41
73
|
empty: "No members yet",
|
|
42
74
|
};
|
|
43
75
|
|
|
76
|
+
const formatSeats = (pattern: string, used: number, limit: number): string =>
|
|
77
|
+
pattern.replace("{used}", String(used)).replace("{limit}", String(limit));
|
|
78
|
+
|
|
44
79
|
export const OrganizationMembersPanel = ({
|
|
45
80
|
members,
|
|
46
81
|
roles,
|
|
47
82
|
currentMemberId,
|
|
83
|
+
invitations,
|
|
84
|
+
seatLimit,
|
|
48
85
|
onRoleChange,
|
|
49
86
|
onRemove,
|
|
87
|
+
onTransferOwnership,
|
|
88
|
+
onLeave,
|
|
50
89
|
onInvite,
|
|
90
|
+
onRevokeInvitation,
|
|
91
|
+
onResendInvitation,
|
|
51
92
|
inviteBusy = false,
|
|
52
93
|
statusLabels,
|
|
94
|
+
invitationStatusLabels,
|
|
53
95
|
labels,
|
|
54
96
|
}: OrganizationMembersPanelProps) => {
|
|
55
97
|
const text = { ...DEFAULT_LABELS, ...labels };
|
|
56
98
|
const [inviting, setInviting] = useState(false);
|
|
57
99
|
|
|
58
|
-
const
|
|
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;
|
|
59
130
|
|
|
60
|
-
const showInvite = Boolean(onInvite);
|
|
61
131
|
const toggleInviting = () => setInviting((open) => !open);
|
|
62
132
|
|
|
63
133
|
return (
|
|
@@ -66,14 +136,26 @@ export const OrganizationMembersPanel = ({
|
|
|
66
136
|
<h3 className="udb-members__title">
|
|
67
137
|
{text.title} <span className="udb-members__count">({members.length})</span>
|
|
68
138
|
</h3>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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>
|
|
74
156
|
</header>
|
|
75
157
|
|
|
76
|
-
{
|
|
158
|
+
{inviteEnabled && inviting && (
|
|
77
159
|
<div className="udb-members__invite">
|
|
78
160
|
<InviteForm
|
|
79
161
|
roles={roles}
|
|
@@ -95,11 +177,55 @@ export const OrganizationMembersPanel = ({
|
|
|
95
177
|
removeLabel: text.removeLabel,
|
|
96
178
|
empty: text.empty,
|
|
97
179
|
}}
|
|
98
|
-
statusVocab={
|
|
180
|
+
statusVocab={memberVocab}
|
|
99
181
|
onRoleChange={onRoleChange}
|
|
100
182
|
onRemove={onRemove}
|
|
183
|
+
rowActions={rowActions}
|
|
101
184
|
isRowLocked={(user) => user.id === currentMemberId || Boolean(user.isOwner)}
|
|
102
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
|
+
)}
|
|
103
229
|
</section>
|
|
104
230
|
);
|
|
105
231
|
};
|
|
@@ -29,9 +29,38 @@ describe("OrganizationSwitcher", () => {
|
|
|
29
29
|
onSwitch={onSwitch}
|
|
30
30
|
/>,
|
|
31
31
|
);
|
|
32
|
-
const select = screen.getByLabelText("
|
|
32
|
+
const select = screen.getByLabelText("Workspace") as HTMLSelectElement;
|
|
33
33
|
expect(select.value).toBe("org-1");
|
|
34
34
|
fireEvent.change(select, { target: { value: "org-2" } });
|
|
35
35
|
expect(onSwitch).toHaveBeenCalledWith("org-2");
|
|
36
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
|
+
});
|
|
37
66
|
});
|
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
import { NativeSelect } from "@umituz/web-design-system/atoms";
|
|
2
2
|
import type { OrganizationRecord } from "../types";
|
|
3
3
|
|
|
4
|
+
export interface PersonalWorkspace {
|
|
5
|
+
/** Stable id the host uses to scope data outside any organization. */
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
4
10
|
export interface OrganizationSwitcherProps {
|
|
5
11
|
organizations: readonly OrganizationRecord[];
|
|
6
12
|
activeOrganizationId?: string;
|
|
7
13
|
onSwitch: (organizationId: string) => void;
|
|
8
14
|
label?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Side-by-side architecture (Clerk/GitHub style): the personal workspace
|
|
17
|
+
* stays intact next to team organizations and leads the switcher.
|
|
18
|
+
*/
|
|
19
|
+
personalWorkspace?: PersonalWorkspace;
|
|
9
20
|
}
|
|
10
21
|
|
|
11
|
-
/**
|
|
12
|
-
* Minimal org picker — renders nothing below two organizations. Hosts keep
|
|
13
|
-
* multi-org state; this only emits the selection.
|
|
14
|
-
*/
|
|
15
22
|
export const OrganizationSwitcher = ({
|
|
16
23
|
organizations,
|
|
17
24
|
activeOrganizationId,
|
|
18
25
|
onSwitch,
|
|
19
|
-
label = "
|
|
26
|
+
label = "Workspace",
|
|
27
|
+
personalWorkspace,
|
|
20
28
|
}: OrganizationSwitcherProps) => {
|
|
21
|
-
|
|
29
|
+
const options = [
|
|
30
|
+
...(personalWorkspace ? [{ value: personalWorkspace.id, label: personalWorkspace.label }] : []),
|
|
31
|
+
...organizations.map((org) => ({ value: org.id, label: org.name })),
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
if (options.length < 2) return null;
|
|
22
35
|
|
|
23
36
|
return (
|
|
24
37
|
<div className="udb-org-switcher">
|
|
25
38
|
<NativeSelect
|
|
26
39
|
label={label}
|
|
27
|
-
value={activeOrganizationId ??
|
|
28
|
-
options={
|
|
40
|
+
value={activeOrganizationId ?? options[0]?.value ?? ""}
|
|
41
|
+
options={options}
|
|
29
42
|
onValueChange={onSwitch}
|
|
30
43
|
/>
|
|
31
44
|
</div>
|
|
@@ -8,4 +8,4 @@ export type {
|
|
|
8
8
|
OrganizationMembersPanelProps,
|
|
9
9
|
} from "./OrganizationMembersPanel";
|
|
10
10
|
export { OrganizationSwitcher } from "./OrganizationSwitcher";
|
|
11
|
-
export type { OrganizationSwitcherProps } from "./OrganizationSwitcher";
|
|
11
|
+
export type { OrganizationSwitcherProps, PersonalWorkspace } from "./OrganizationSwitcher";
|
|
@@ -3,7 +3,7 @@ export type {
|
|
|
3
3
|
OrganizationProviderProps,
|
|
4
4
|
OrganizationContextValue,
|
|
5
5
|
} from "./OrganizationContext";
|
|
6
|
-
export { initialsOf, memberStatusVocab } from "./vocab";
|
|
6
|
+
export { initialsOf, memberStatusVocab, invitationStatusVocab } from "./vocab";
|
|
7
7
|
export {
|
|
8
8
|
InviteForm,
|
|
9
9
|
OrganizationCard,
|
|
@@ -18,12 +18,14 @@ export type {
|
|
|
18
18
|
OrganizationMembersPanelLabels,
|
|
19
19
|
OrganizationMembersPanelProps,
|
|
20
20
|
OrganizationSwitcherProps,
|
|
21
|
+
PersonalWorkspace,
|
|
21
22
|
} from "./components";
|
|
22
23
|
export type {
|
|
24
|
+
InvitationStatus,
|
|
23
25
|
OrganizationPermissionBridge,
|
|
24
26
|
OrganizationRecord,
|
|
25
27
|
OrgInviteInput,
|
|
28
|
+
OrgInvitation,
|
|
26
29
|
OrgMember,
|
|
27
|
-
MemberRoleSource,
|
|
28
30
|
MemberStatus,
|
|
29
31
|
} from "./types";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PermissionMatrix, RoleKey
|
|
1
|
+
import type { PermissionMatrix, RoleKey } from "../permissions/types";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Organization record — the tenant entity a signed-in user belongs to.
|
|
@@ -21,10 +21,35 @@ export interface OrganizationRecord {
|
|
|
21
21
|
/** Fleet-wide membership vocabulary (invite flow: invited -> active -> suspended). */
|
|
22
22
|
export type MemberStatus = "invited" | "active" | "suspended";
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Invitation lifecycle — the industry state machine
|
|
26
|
+
* (pending -> accepted | revoked | expired | declined). Invitations are
|
|
27
|
+
* first-class records, separate from memberships: they key on email, carry
|
|
28
|
+
* an expiry, and can be revoked or resent while pending.
|
|
29
|
+
*/
|
|
30
|
+
export type InvitationStatus = "pending" | "accepted" | "revoked" | "expired" | "declined";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* An outstanding (or settled) invitation. The host owns the backend record
|
|
34
|
+
* (token, redemption route); the panel renders and emits revoke/resend.
|
|
35
|
+
*/
|
|
36
|
+
export interface OrgInvitation {
|
|
37
|
+
id: string;
|
|
38
|
+
email: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
role: RoleKey;
|
|
41
|
+
status: InvitationStatus;
|
|
42
|
+
invitedBy?: string;
|
|
43
|
+
invitedAt?: string;
|
|
44
|
+
expiresAt?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
24
47
|
/**
|
|
25
48
|
* A member row as the organization module consumes it. `role` is a RoleKey
|
|
26
49
|
* resolved against the host's RoleInfo list; owners carry `isOwner` so UIs
|
|
27
|
-
* can protect the last owner from removal/role changes.
|
|
50
|
+
* can protect the last owner from removal/role changes. By convention `id`
|
|
51
|
+
* is the member's user id — pre-acceptance people belong in `OrgInvitation`,
|
|
52
|
+
* not here.
|
|
28
53
|
*/
|
|
29
54
|
export interface OrgMember {
|
|
30
55
|
id: string;
|
|
@@ -43,9 +68,6 @@ export interface OrgInviteInput {
|
|
|
43
68
|
role: RoleKey;
|
|
44
69
|
}
|
|
45
70
|
|
|
46
|
-
/** Roles the host exposes for membership management (labelled RoleKey list). */
|
|
47
|
-
export type MemberRoleSource = readonly RoleInfo[];
|
|
48
|
-
|
|
49
71
|
/** Permission bridge — ties membership role to a 7.6.0 permission matrix. */
|
|
50
72
|
export interface OrganizationPermissionBridge {
|
|
51
73
|
matrix: PermissionMatrix;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { initialsOf, memberStatusVocab } from "./vocab";
|
|
2
|
+
import { initialsOf, invitationStatusVocab, memberStatusVocab } from "./vocab";
|
|
3
3
|
|
|
4
4
|
describe("initialsOf", () => {
|
|
5
5
|
it("takes up to two leading initials", () => {
|
|
@@ -30,3 +30,20 @@ describe("memberStatusVocab", () => {
|
|
|
30
30
|
expect(vocab.suspended?.label).toBe("Suspended");
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
|
+
|
|
34
|
+
describe("invitationStatusVocab", () => {
|
|
35
|
+
it("covers the full invitation lifecycle with tones", () => {
|
|
36
|
+
const vocab = invitationStatusVocab();
|
|
37
|
+
expect(vocab.pending).toEqual({ label: "Pending", tone: "info" });
|
|
38
|
+
expect(vocab.accepted).toEqual({ label: "Accepted", tone: "success" });
|
|
39
|
+
expect(vocab.revoked).toEqual({ label: "Revoked", tone: "neutral" });
|
|
40
|
+
expect(vocab.expired).toEqual({ label: "Expired", tone: "warning" });
|
|
41
|
+
expect(vocab.declined).toEqual({ label: "Declined", tone: "neutral" });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("merges label overrides over the defaults", () => {
|
|
45
|
+
const vocab = invitationStatusVocab({ pending: "Bekliyor" });
|
|
46
|
+
expect(vocab.pending?.label).toBe("Bekliyor");
|
|
47
|
+
expect(vocab.pending?.tone).toBe("info");
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { statusVocab, type StatusVocab } from "@umituz/web-design-system/organisms";
|
|
2
|
-
import type { MemberStatus } from "./types";
|
|
2
|
+
import type { InvitationStatus, MemberStatus } from "./types";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Up to two leading initials from a display name ("Northwind Labs" -> "NL",
|
|
@@ -37,3 +37,34 @@ export const memberStatusVocab = (
|
|
|
37
37
|
{ ...DEFAULT_MEMBER_STATUS_LABELS, ...labelOverrides },
|
|
38
38
|
MEMBER_STATUS_TONES,
|
|
39
39
|
);
|
|
40
|
+
|
|
41
|
+
const DEFAULT_INVITATION_STATUS_LABELS: Record<InvitationStatus, string> = {
|
|
42
|
+
pending: "Pending",
|
|
43
|
+
accepted: "Accepted",
|
|
44
|
+
revoked: "Revoked",
|
|
45
|
+
expired: "Expired",
|
|
46
|
+
declined: "Declined",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const INVITATION_STATUS_TONES: Record<
|
|
50
|
+
InvitationStatus,
|
|
51
|
+
"info" | "success" | "neutral" | "warning"
|
|
52
|
+
> = {
|
|
53
|
+
pending: "info",
|
|
54
|
+
accepted: "success",
|
|
55
|
+
revoked: "neutral",
|
|
56
|
+
expired: "warning",
|
|
57
|
+
declined: "neutral",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Status vocab for invitation rows — label overrides merge over the
|
|
62
|
+
* industry lifecycle defaults (pending/accepted/revoked/expired/declined).
|
|
63
|
+
*/
|
|
64
|
+
export const invitationStatusVocab = (
|
|
65
|
+
labelOverrides?: Partial<Record<InvitationStatus, string>>,
|
|
66
|
+
): StatusVocab =>
|
|
67
|
+
statusVocab(
|
|
68
|
+
{ ...DEFAULT_INVITATION_STATUS_LABELS, ...labelOverrides },
|
|
69
|
+
INVITATION_STATUS_TONES,
|
|
70
|
+
);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
1
2
|
import { DataTable, type Column } from "@umituz/web-design-system/organisms";
|
|
2
3
|
import { StatusBadge, type StatusVocab } from "@umituz/web-design-system/organisms";
|
|
3
4
|
import type { RoleKey, RoleInfo } from "../../permissions/types";
|
|
@@ -18,6 +19,8 @@ export interface UserManagementTableLabels {
|
|
|
18
19
|
roleColumn: string;
|
|
19
20
|
empty: string;
|
|
20
21
|
statusColumn?: string;
|
|
22
|
+
actionsColumn?: string;
|
|
23
|
+
/** @deprecated use actionsColumn — the column now hosts every row action. */
|
|
21
24
|
removeColumn?: string;
|
|
22
25
|
removeLabel?: string;
|
|
23
26
|
}
|
|
@@ -31,6 +34,8 @@ export interface UserManagementTableProps {
|
|
|
31
34
|
statusVocab?: StatusVocab;
|
|
32
35
|
/** Renders a remove action column when provided; guarded rows stay hidden. */
|
|
33
36
|
onRemove?: (userId: string) => void;
|
|
37
|
+
/** Extra row-level actions (e.g. "Make owner"), rendered before Remove. */
|
|
38
|
+
rowActions?: (user: ManagedUser) => ReactNode;
|
|
34
39
|
/** Rows that must never be removed or role-changed; defaults to owner rows. */
|
|
35
40
|
isRowLocked?: (user: ManagedUser) => boolean;
|
|
36
41
|
}
|
|
@@ -42,6 +47,7 @@ export const UserManagementTable = ({
|
|
|
42
47
|
onRoleChange,
|
|
43
48
|
statusVocab,
|
|
44
49
|
onRemove,
|
|
50
|
+
rowActions,
|
|
45
51
|
isRowLocked = (user) => Boolean(user.isOwner),
|
|
46
52
|
}: UserManagementTableProps) => {
|
|
47
53
|
const columns: Column<ManagedUser>[] = [
|
|
@@ -51,7 +57,7 @@ export const UserManagementTable = ({
|
|
|
51
57
|
id: "role",
|
|
52
58
|
header: labels.roleColumn,
|
|
53
59
|
accessor: (user) =>
|
|
54
|
-
onRoleChange && !
|
|
60
|
+
onRoleChange && !isRowLocked(user) ? (
|
|
55
61
|
<select
|
|
56
62
|
className="udb-period-select__select"
|
|
57
63
|
value={user.role}
|
|
@@ -81,21 +87,26 @@ export const UserManagementTable = ({
|
|
|
81
87
|
});
|
|
82
88
|
}
|
|
83
89
|
|
|
84
|
-
if (onRemove) {
|
|
90
|
+
if (onRemove || rowActions) {
|
|
85
91
|
columns.push({
|
|
86
|
-
id: "
|
|
87
|
-
header: labels.removeColumn ?? "",
|
|
92
|
+
id: "actions",
|
|
93
|
+
header: labels.actionsColumn ?? labels.removeColumn ?? "",
|
|
88
94
|
align: "right",
|
|
89
|
-
accessor: (user) =>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
accessor: (user) => {
|
|
96
|
+
const extra = rowActions?.(user);
|
|
97
|
+
const remove =
|
|
98
|
+
onRemove && !isRowLocked(user) ? (
|
|
99
|
+
<button
|
|
100
|
+
type="button"
|
|
101
|
+
className="udb-link-button"
|
|
102
|
+
onClick={() => onRemove(user.id)}
|
|
103
|
+
>
|
|
104
|
+
{labels.removeLabel ?? "Remove"}
|
|
105
|
+
</button>
|
|
106
|
+
) : null;
|
|
107
|
+
if (!extra && !remove) return null;
|
|
108
|
+
return <div className="udb-row-actions">{extra}{remove}</div>;
|
|
109
|
+
},
|
|
99
110
|
});
|
|
100
111
|
}
|
|
101
112
|
|
package/src/styles/chrome.css
CHANGED
|
@@ -1388,12 +1388,79 @@
|
|
|
1388
1388
|
color: var(--color-muted-foreground);
|
|
1389
1389
|
font-weight: var(--font-weight-normal);
|
|
1390
1390
|
}
|
|
1391
|
+
.udb-members__head-actions {
|
|
1392
|
+
display: flex;
|
|
1393
|
+
align-items: center;
|
|
1394
|
+
gap: var(--udb-space-2);
|
|
1395
|
+
}
|
|
1396
|
+
.udb-members__seats {
|
|
1397
|
+
font-size: var(--udb-font-size-sm);
|
|
1398
|
+
color: var(--color-muted-foreground);
|
|
1399
|
+
white-space: nowrap;
|
|
1400
|
+
}
|
|
1391
1401
|
.udb-members__invite {
|
|
1392
1402
|
padding: var(--udb-space-4);
|
|
1393
1403
|
border: 1px solid var(--color-border);
|
|
1394
1404
|
border-radius: var(--radius-md);
|
|
1395
1405
|
background: var(--color-muted);
|
|
1396
1406
|
}
|
|
1407
|
+
.udb-members__invitations {
|
|
1408
|
+
display: flex;
|
|
1409
|
+
flex-direction: column;
|
|
1410
|
+
gap: var(--udb-space-2);
|
|
1411
|
+
}
|
|
1412
|
+
.udb-members__invitations-title {
|
|
1413
|
+
margin: 0;
|
|
1414
|
+
font-size: var(--udb-font-size-sm);
|
|
1415
|
+
font-weight: var(--font-weight-semibold);
|
|
1416
|
+
color: var(--color-muted-foreground);
|
|
1417
|
+
}
|
|
1418
|
+
.udb-members__invitation-list {
|
|
1419
|
+
display: flex;
|
|
1420
|
+
flex-direction: column;
|
|
1421
|
+
gap: var(--udb-space-2);
|
|
1422
|
+
margin: 0;
|
|
1423
|
+
padding: 0;
|
|
1424
|
+
list-style: none;
|
|
1425
|
+
}
|
|
1426
|
+
.udb-members__invitation {
|
|
1427
|
+
display: flex;
|
|
1428
|
+
align-items: center;
|
|
1429
|
+
justify-content: space-between;
|
|
1430
|
+
gap: var(--udb-space-3);
|
|
1431
|
+
padding: var(--udb-space-2) var(--udb-space-3);
|
|
1432
|
+
border: 1px solid var(--color-border);
|
|
1433
|
+
border-radius: var(--radius-md);
|
|
1434
|
+
}
|
|
1435
|
+
.udb-members__invitation-info {
|
|
1436
|
+
display: flex;
|
|
1437
|
+
flex-direction: column;
|
|
1438
|
+
gap: var(--udb-space-1);
|
|
1439
|
+
}
|
|
1440
|
+
.udb-members__invitation-email {
|
|
1441
|
+
font-size: var(--udb-font-size-sm);
|
|
1442
|
+
font-weight: var(--font-weight-medium);
|
|
1443
|
+
}
|
|
1444
|
+
.udb-members__invitation-role {
|
|
1445
|
+
font-size: var(--udb-font-size-xs);
|
|
1446
|
+
color: var(--color-muted-foreground);
|
|
1447
|
+
}
|
|
1448
|
+
.udb-members__invitation-side {
|
|
1449
|
+
display: flex;
|
|
1450
|
+
align-items: center;
|
|
1451
|
+
gap: var(--udb-space-3);
|
|
1452
|
+
}
|
|
1453
|
+
.udb-members__invitation-actions {
|
|
1454
|
+
display: flex;
|
|
1455
|
+
align-items: center;
|
|
1456
|
+
gap: var(--udb-space-2);
|
|
1457
|
+
}
|
|
1458
|
+
.udb-row-actions {
|
|
1459
|
+
display: inline-flex;
|
|
1460
|
+
align-items: center;
|
|
1461
|
+
justify-content: flex-end;
|
|
1462
|
+
gap: var(--udb-space-2);
|
|
1463
|
+
}
|
|
1397
1464
|
.udb-invite {
|
|
1398
1465
|
display: flex;
|
|
1399
1466
|
flex-direction: column;
|
|
@@ -1425,6 +1492,9 @@
|
|
|
1425
1492
|
.udb-link-button:hover {
|
|
1426
1493
|
text-decoration: underline;
|
|
1427
1494
|
}
|
|
1495
|
+
.udb-link-button--muted {
|
|
1496
|
+
color: var(--color-muted-foreground);
|
|
1497
|
+
}
|
|
1428
1498
|
.udb-matrix__group-row th {
|
|
1429
1499
|
font-size: var(--udb-font-size-xs);
|
|
1430
1500
|
font-weight: var(--font-weight-bold);
|