@umituz/web-dashboard 7.7.0 → 7.8.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 +88 -0
  20. package/src/domains/organization/components/OrganizationMembersPanel.tsx +105 -0
  21. package/src/domains/organization/components/OrganizationSwitcher.test.tsx +37 -0
  22. package/src/domains/organization/components/OrganizationSwitcher.tsx +33 -0
  23. package/src/domains/organization/components/index.ts +11 -0
  24. package/src/domains/organization/index.ts +29 -0
  25. package/src/domains/organization/types.ts +59 -0
  26. package/src/domains/organization/vocab.test.ts +32 -0
  27. package/src/domains/organization/vocab.ts +39 -0
  28. package/src/domains/settings/components/UserManagementTable.tsx +43 -1
  29. package/src/styles/chrome.css +143 -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,88 @@
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 { 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: "invited",
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 mount = (props: Partial<Parameters<typeof OrganizationMembersPanel>[0]> = {}) =>
38
+ render(
39
+ <OrganizationMembersPanel members={MEMBERS} roles={ROLES} currentMemberId="u-2" {...props} />,
40
+ );
41
+
42
+ describe("OrganizationMembersPanel", () => {
43
+ it("renders member rows with status badges and the member count", () => {
44
+ mount();
45
+ expect(screen.getByText(/Members/).textContent).toContain("(3)");
46
+ expect(screen.getByText("Invited")).not.toBeNull();
47
+ expect(screen.getAllByText("Active")).toHaveLength(2);
48
+ expect(screen.getByText("ada@example.com")).not.toBeNull();
49
+ });
50
+
51
+ it("opens the invite form on demand and hands the payload to onInvite", () => {
52
+ const onInvite = vi.fn();
53
+ mount({ onInvite });
54
+ fireEvent.click(screen.getByText("Invite member"));
55
+ fireEvent.change(screen.getByLabelText("Email"), {
56
+ target: { value: "new@example.com" },
57
+ });
58
+ fireEvent.click(screen.getByText("Send invite"));
59
+ expect(onInvite).toHaveBeenCalledWith({
60
+ email: "new@example.com",
61
+ role: "owner",
62
+ });
63
+ });
64
+
65
+ it("locks the self row and owner rows against removal and role changes", () => {
66
+ const onRemove = vi.fn();
67
+ const onRoleChange = vi.fn();
68
+ mount({ onRemove, onRoleChange });
69
+
70
+ const removeButtons = screen
71
+ .getAllByRole("button")
72
+ .filter((b) => b.textContent === "Remove");
73
+ expect(removeButtons).toHaveLength(1);
74
+ fireEvent.click(removeButtons[0]!);
75
+ expect(onRemove).toHaveBeenCalledWith("u-3");
76
+
77
+ const selects = screen.getAllByLabelText("Role");
78
+ expect(selects).toHaveLength(1);
79
+ fireEvent.change(selects[0]!, { target: { value: "owner" } });
80
+ expect(onRoleChange).toHaveBeenCalledWith("u-3", "owner");
81
+ });
82
+
83
+ it("hides invite and remove affordances when handlers are absent", () => {
84
+ mount();
85
+ expect(screen.queryByText("Invite member")).toBeNull();
86
+ expect(screen.queryAllByRole("button")).toHaveLength(0);
87
+ });
88
+ });
@@ -0,0 +1,105 @@
1
+ import { useMemo, useState } from "react";
2
+ import { Button } from "@umituz/web-design-system/atoms";
3
+ import type { RoleInfo, RoleKey } from "../../permissions/types";
4
+ import { UserManagementTable } from "../../settings/components/UserManagementTable";
5
+ import type { OrgInviteInput, OrgMember } from "../types";
6
+ import { memberStatusVocab } from "../vocab";
7
+ import { InviteForm } from "./InviteForm";
8
+
9
+ export interface OrganizationMembersPanelLabels {
10
+ title: string;
11
+ invite: string;
12
+ nameColumn: string;
13
+ emailColumn: string;
14
+ roleColumn: string;
15
+ statusColumn: string;
16
+ removeLabel: string;
17
+ empty: string;
18
+ }
19
+
20
+ export interface OrganizationMembersPanelProps {
21
+ members: readonly OrgMember[];
22
+ roles: readonly RoleInfo[];
23
+ /** Self rows are always locked; owner rows lock by default. */
24
+ currentMemberId?: string;
25
+ onRoleChange?: (memberId: string, role: RoleKey) => void;
26
+ onRemove?: (memberId: string) => void;
27
+ onInvite?: (input: OrgInviteInput) => void;
28
+ inviteBusy?: boolean;
29
+ statusLabels?: Partial<Record<OrgMember["status"] & string, string>>;
30
+ labels?: Partial<OrganizationMembersPanelLabels>;
31
+ }
32
+
33
+ const DEFAULT_LABELS: OrganizationMembersPanelLabels = {
34
+ title: "Members",
35
+ invite: "Invite member",
36
+ nameColumn: "Name",
37
+ emailColumn: "Email",
38
+ roleColumn: "Role",
39
+ statusColumn: "Status",
40
+ removeLabel: "Remove",
41
+ empty: "No members yet",
42
+ };
43
+
44
+ export const OrganizationMembersPanel = ({
45
+ members,
46
+ roles,
47
+ currentMemberId,
48
+ onRoleChange,
49
+ onRemove,
50
+ onInvite,
51
+ inviteBusy = false,
52
+ statusLabels,
53
+ labels,
54
+ }: OrganizationMembersPanelProps) => {
55
+ const text = { ...DEFAULT_LABELS, ...labels };
56
+ const [inviting, setInviting] = useState(false);
57
+
58
+ const vocab = useMemo(() => memberStatusVocab(statusLabels), [statusLabels]);
59
+
60
+ const showInvite = Boolean(onInvite);
61
+ const toggleInviting = () => setInviting((open) => !open);
62
+
63
+ return (
64
+ <section className="udb-members">
65
+ <header className="udb-members__head">
66
+ <h3 className="udb-members__title">
67
+ {text.title} <span className="udb-members__count">({members.length})</span>
68
+ </h3>
69
+ {showInvite && (
70
+ <Button size="sm" variant="secondary" onClick={toggleInviting}>
71
+ {text.invite}
72
+ </Button>
73
+ )}
74
+ </header>
75
+
76
+ {showInvite && inviting && (
77
+ <div className="udb-members__invite">
78
+ <InviteForm
79
+ roles={roles}
80
+ busy={inviteBusy}
81
+ onInvite={(input) => onInvite?.(input)}
82
+ onCancel={toggleInviting}
83
+ />
84
+ </div>
85
+ )}
86
+
87
+ <UserManagementTable
88
+ users={[...members]}
89
+ roles={[...roles]}
90
+ labels={{
91
+ nameColumn: text.nameColumn,
92
+ emailColumn: text.emailColumn,
93
+ roleColumn: text.roleColumn,
94
+ statusColumn: text.statusColumn,
95
+ removeLabel: text.removeLabel,
96
+ empty: text.empty,
97
+ }}
98
+ statusVocab={vocab}
99
+ onRoleChange={onRoleChange}
100
+ onRemove={onRemove}
101
+ isRowLocked={(user) => user.id === currentMemberId || Boolean(user.isOwner)}
102
+ />
103
+ </section>
104
+ );
105
+ };
@@ -0,0 +1,37 @@
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("Organization") 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
+ });
@@ -0,0 +1,33 @@
1
+ import { NativeSelect } from "@umituz/web-design-system/atoms";
2
+ import type { OrganizationRecord } from "../types";
3
+
4
+ export interface OrganizationSwitcherProps {
5
+ organizations: readonly OrganizationRecord[];
6
+ activeOrganizationId?: string;
7
+ onSwitch: (organizationId: string) => void;
8
+ label?: string;
9
+ }
10
+
11
+ /**
12
+ * Minimal org picker — renders nothing below two organizations. Hosts keep
13
+ * multi-org state; this only emits the selection.
14
+ */
15
+ export const OrganizationSwitcher = ({
16
+ organizations,
17
+ activeOrganizationId,
18
+ onSwitch,
19
+ label = "Organization",
20
+ }: OrganizationSwitcherProps) => {
21
+ if (organizations.length < 2) return null;
22
+
23
+ return (
24
+ <div className="udb-org-switcher">
25
+ <NativeSelect
26
+ label={label}
27
+ value={activeOrganizationId ?? organizations[0]?.id ?? ""}
28
+ options={organizations.map((org) => ({ value: org.id, label: org.name }))}
29
+ onValueChange={onSwitch}
30
+ />
31
+ </div>
32
+ );
33
+ };
@@ -0,0 +1,11 @@
1
+ export { InviteForm } from "./InviteForm";
2
+ export type { InviteFormLabels, InviteFormProps } from "./InviteForm";
3
+ export { OrganizationCard } from "./OrganizationCard";
4
+ export type { OrganizationCardLabels, OrganizationCardProps } from "./OrganizationCard";
5
+ export { OrganizationMembersPanel } from "./OrganizationMembersPanel";
6
+ export type {
7
+ OrganizationMembersPanelLabels,
8
+ OrganizationMembersPanelProps,
9
+ } from "./OrganizationMembersPanel";
10
+ export { OrganizationSwitcher } from "./OrganizationSwitcher";
11
+ export type { OrganizationSwitcherProps } from "./OrganizationSwitcher";
@@ -0,0 +1,29 @@
1
+ export { OrganizationProvider, useOrganization } from "./OrganizationContext";
2
+ export type {
3
+ OrganizationProviderProps,
4
+ OrganizationContextValue,
5
+ } from "./OrganizationContext";
6
+ export { initialsOf, memberStatusVocab } from "./vocab";
7
+ export {
8
+ InviteForm,
9
+ OrganizationCard,
10
+ OrganizationMembersPanel,
11
+ OrganizationSwitcher,
12
+ } from "./components";
13
+ export type {
14
+ InviteFormLabels,
15
+ InviteFormProps,
16
+ OrganizationCardLabels,
17
+ OrganizationCardProps,
18
+ OrganizationMembersPanelLabels,
19
+ OrganizationMembersPanelProps,
20
+ OrganizationSwitcherProps,
21
+ } from "./components";
22
+ export type {
23
+ OrganizationPermissionBridge,
24
+ OrganizationRecord,
25
+ OrgInviteInput,
26
+ OrgMember,
27
+ MemberRoleSource,
28
+ MemberStatus,
29
+ } from "./types";
@@ -0,0 +1,59 @@
1
+ import type { PermissionMatrix, RoleKey, RoleInfo } from "../permissions/types";
2
+
3
+ /**
4
+ * Organization record — the tenant entity a signed-in user belongs to.
5
+ * Field set follows the fleet consensus (id/name/legalName/plan/status +
6
+ * locale trio); every field beyond id/name is optional so single-person
7
+ * organizations and partially-provisioned tenants stay representable.
8
+ */
9
+ export interface OrganizationRecord {
10
+ id: string;
11
+ name: string;
12
+ legalName?: string;
13
+ plan?: string;
14
+ status?: string;
15
+ country?: string;
16
+ currency?: string;
17
+ locale?: string;
18
+ timezone?: string;
19
+ }
20
+
21
+ /** Fleet-wide membership vocabulary (invite flow: invited -> active -> suspended). */
22
+ export type MemberStatus = "invited" | "active" | "suspended";
23
+
24
+ /**
25
+ * A member row as the organization module consumes it. `role` is a RoleKey
26
+ * resolved against the host's RoleInfo list; owners carry `isOwner` so UIs
27
+ * can protect the last owner from removal/role changes.
28
+ */
29
+ export interface OrgMember {
30
+ id: string;
31
+ name: string;
32
+ email: string;
33
+ role: RoleKey;
34
+ status?: MemberStatus;
35
+ isOwner?: boolean;
36
+ joinedAt?: string;
37
+ }
38
+
39
+ /** Payload handed to the host when InviteForm validates. */
40
+ export interface OrgInviteInput {
41
+ name?: string;
42
+ email: string;
43
+ role: RoleKey;
44
+ }
45
+
46
+ /** Roles the host exposes for membership management (labelled RoleKey list). */
47
+ export type MemberRoleSource = readonly RoleInfo[];
48
+
49
+ /** Permission bridge — ties membership role to a 7.6.0 permission matrix. */
50
+ export interface OrganizationPermissionBridge {
51
+ matrix: PermissionMatrix;
52
+ /** Defaults to the current member's role when omitted. */
53
+ role?: RoleKey;
54
+ /** Extra grant/revoke applied on top of the matrix (visora-style overrides). */
55
+ overrides?: {
56
+ grant?: readonly string[];
57
+ revoke?: readonly string[];
58
+ };
59
+ }
@@ -0,0 +1,32 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { initialsOf, memberStatusVocab } from "./vocab";
3
+
4
+ describe("initialsOf", () => {
5
+ it("takes up to two leading initials", () => {
6
+ expect(initialsOf("Northwind Labs")).toBe("NL");
7
+ expect(initialsOf("madeline")).toBe("M");
8
+ expect(initialsOf(" a berry owens ")).toBe("AB");
9
+ });
10
+
11
+ it("survives empty and blank names", () => {
12
+ expect(initialsOf("")).toBe("");
13
+ expect(initialsOf(" ")).toBe("");
14
+ });
15
+ });
16
+
17
+ describe("memberStatusVocab", () => {
18
+ it("covers the fleet membership vocabulary with tones", () => {
19
+ const vocab = memberStatusVocab();
20
+ expect(vocab.invited).toEqual({ label: "Invited", tone: "info" });
21
+ expect(vocab.active).toEqual({ label: "Active", tone: "success" });
22
+ expect(vocab.suspended).toEqual({ label: "Suspended", tone: "warning" });
23
+ });
24
+
25
+ it("merges label overrides over the defaults", () => {
26
+ const vocab = memberStatusVocab({ invited: "Davetli", active: "Aktif" });
27
+ expect(vocab.invited?.label).toBe("Davetli");
28
+ expect(vocab.invited?.tone).toBe("info");
29
+ expect(vocab.active?.label).toBe("Aktif");
30
+ expect(vocab.suspended?.label).toBe("Suspended");
31
+ });
32
+ });
@@ -0,0 +1,39 @@
1
+ import { statusVocab, type StatusVocab } from "@umituz/web-design-system/organisms";
2
+ import type { MemberStatus } from "./types";
3
+
4
+ /**
5
+ * Up to two leading initials from a display name ("Northwind Labs" -> "NL",
6
+ * "madeline" -> "M"). Used wherever an avatar block needs stable letters.
7
+ */
8
+ export const initialsOf = (name: string): string =>
9
+ name
10
+ .trim()
11
+ .split(/\s+/)
12
+ .filter(Boolean)
13
+ .slice(0, 2)
14
+ .map((part) => part[0]?.toUpperCase() ?? "")
15
+ .join("");
16
+
17
+ const DEFAULT_MEMBER_STATUS_LABELS: Record<MemberStatus, string> = {
18
+ invited: "Invited",
19
+ active: "Active",
20
+ suspended: "Suspended",
21
+ };
22
+
23
+ const MEMBER_STATUS_TONES: Record<MemberStatus, "info" | "success" | "warning"> = {
24
+ invited: "info",
25
+ active: "success",
26
+ suspended: "warning",
27
+ };
28
+
29
+ /**
30
+ * Status vocab for membership rows — label overrides merge over the
31
+ * fleet-wide defaults (invited/active/suspended).
32
+ */
33
+ export const memberStatusVocab = (
34
+ labelOverrides?: Partial<Record<MemberStatus, string>>,
35
+ ): StatusVocab =>
36
+ statusVocab(
37
+ { ...DEFAULT_MEMBER_STATUS_LABELS, ...labelOverrides },
38
+ MEMBER_STATUS_TONES,
39
+ );