@umituz/web-dashboard 7.6.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 (32) 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/OrganizationProfileForm.test.tsx +114 -0
  29. package/src/domains/settings/components/OrganizationProfileForm.tsx +164 -0
  30. package/src/domains/settings/components/UserManagementTable.tsx +43 -1
  31. package/src/domains/settings/components/index.ts +9 -0
  32. package/src/styles/chrome.css +158 -0
@@ -0,0 +1,114 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { OrganizationProfileForm } from "./OrganizationProfileForm";
4
+
5
+ const ORG = {
6
+ name: "Northwind Labs",
7
+ legalName: "Northwind Laboratories GmbH",
8
+ timezone: "Europe/Berlin",
9
+ email: "ops@northwind.example",
10
+ };
11
+
12
+ const mount = (props: Partial<Parameters<typeof OrganizationProfileForm>[0]> = {}) =>
13
+ render(
14
+ <OrganizationProfileForm value={ORG} onSave={() => undefined} {...props} />,
15
+ );
16
+
17
+ const saveButton = () =>
18
+ screen.getByText("Save changes").closest("button") as HTMLButtonElement;
19
+
20
+ const resetButton = () =>
21
+ screen.getByText("Reset").closest("button") as HTMLButtonElement;
22
+
23
+ describe("OrganizationProfileForm", () => {
24
+ it("renders the fields present in value by default, in canonical order", () => {
25
+ mount();
26
+ expect(screen.getByLabelText("Organization name")).not.toBeNull();
27
+ expect(screen.getByLabelText("Legal name")).not.toBeNull();
28
+ expect(screen.getByLabelText("Timezone")).not.toBeNull();
29
+ expect(screen.getByLabelText("Email")).not.toBeNull();
30
+ expect(screen.queryByLabelText("City")).toBeNull();
31
+ expect(screen.queryByLabelText("Website")).toBeNull();
32
+ });
33
+
34
+ it("limits the form to the fields prop when given", () => {
35
+ mount({ fields: ["name", "timezone"] });
36
+ expect(screen.getByLabelText("Organization name")).not.toBeNull();
37
+ expect(screen.getByLabelText("Timezone")).not.toBeNull();
38
+ expect(screen.queryByLabelText("Legal name")).toBeNull();
39
+ });
40
+
41
+ it("overrides labels", () => {
42
+ mount({ labels: { name: "Kurum adı", save: "Kaydet" } });
43
+ expect(screen.getByLabelText("Kurum adı")).not.toBeNull();
44
+ expect(screen.getByText("Kaydet")).not.toBeNull();
45
+ });
46
+
47
+ it("starts clean and enables save only after an edit", () => {
48
+ mount();
49
+ expect(saveButton().disabled).toBe(true);
50
+ expect(resetButton().disabled).toBe(true);
51
+
52
+ fireEvent.change(screen.getByLabelText("Legal name"), {
53
+ target: { value: "Northwind Labs AG" },
54
+ });
55
+ expect(saveButton().disabled).toBe(false);
56
+ expect(resetButton().disabled).toBe(false);
57
+ });
58
+
59
+ it("hands the edited draft to onSave and keeps untouched fields", () => {
60
+ const onSave = vi.fn();
61
+ mount({ onSave });
62
+ fireEvent.change(screen.getByLabelText("Organization name"), {
63
+ target: { value: "Northwind Group" },
64
+ });
65
+ fireEvent.click(saveButton());
66
+ expect(onSave).toHaveBeenCalledWith({
67
+ ...ORG,
68
+ name: "Northwind Group",
69
+ });
70
+ });
71
+
72
+ it("reset restores the initial values", () => {
73
+ mount();
74
+ const input = screen.getByLabelText("Organization name") as HTMLInputElement;
75
+ fireEvent.change(input, { target: { value: "Temporary" } });
76
+ fireEvent.click(resetButton());
77
+ expect(input.value).toBe("Northwind Labs");
78
+ expect(saveButton().disabled).toBe(true);
79
+ });
80
+
81
+ it("blocks save while the name is blank", () => {
82
+ mount();
83
+ fireEvent.change(screen.getByLabelText("Organization name"), {
84
+ target: { value: " " },
85
+ });
86
+ expect(saveButton().disabled).toBe(true);
87
+ });
88
+
89
+ it("renders a select for fields with options", () => {
90
+ mount({
91
+ selects: {
92
+ timezone: [
93
+ { value: "Europe/Berlin", label: "Berlin" },
94
+ { value: "Europe/Istanbul", label: "Istanbul" },
95
+ ],
96
+ },
97
+ });
98
+ const select = screen.getByLabelText("Timezone") as HTMLSelectElement;
99
+ expect(select.tagName).toBe("SELECT");
100
+ expect(select.value).toBe("Europe/Berlin");
101
+ expect(
102
+ withinOptions(select).some((option) => option.textContent === "Istanbul"),
103
+ ).toBe(true);
104
+ });
105
+
106
+ it("disables both actions while busy", () => {
107
+ mount({ busy: true });
108
+ expect(saveButton().disabled).toBe(true);
109
+ expect(resetButton().disabled).toBe(true);
110
+ });
111
+ });
112
+
113
+ const withinOptions = (select: HTMLSelectElement): HTMLOptionElement[] =>
114
+ Array.from(select.querySelectorAll("option"));
@@ -0,0 +1,164 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import {
3
+ Button,
4
+ Input,
5
+ NativeSelect,
6
+ } from "@umituz/web-design-system/atoms";
7
+
8
+ export interface OrganizationProfile {
9
+ name: string;
10
+ legalName?: string;
11
+ timezone?: string;
12
+ locale?: string;
13
+ currency?: string;
14
+ address?: string;
15
+ city?: string;
16
+ country?: string;
17
+ phone?: string;
18
+ email?: string;
19
+ website?: string;
20
+ }
21
+
22
+ export type OrganizationFieldKey = keyof OrganizationProfile;
23
+
24
+ export type OrganizationSelectKey = "timezone" | "locale" | "currency";
25
+
26
+ export interface OrganizationSelectOption {
27
+ value: string;
28
+ label: string;
29
+ }
30
+
31
+ export interface OrganizationFormLabels {
32
+ name: string;
33
+ legalName: string;
34
+ timezone: string;
35
+ locale: string;
36
+ currency: string;
37
+ address: string;
38
+ city: string;
39
+ country: string;
40
+ phone: string;
41
+ email: string;
42
+ website: string;
43
+ save: string;
44
+ reset: string;
45
+ }
46
+
47
+ export interface OrganizationProfileFormProps {
48
+ value: OrganizationProfile;
49
+ fields?: readonly OrganizationFieldKey[];
50
+ selects?: Partial<
51
+ Record<OrganizationSelectKey, readonly OrganizationSelectOption[]>
52
+ >;
53
+ labels?: Partial<OrganizationFormLabels>;
54
+ busy?: boolean;
55
+ onSave: (next: OrganizationProfile) => void;
56
+ }
57
+
58
+ const FIELD_ORDER: readonly OrganizationFieldKey[] = [
59
+ "name",
60
+ "legalName",
61
+ "timezone",
62
+ "locale",
63
+ "currency",
64
+ "address",
65
+ "city",
66
+ "country",
67
+ "phone",
68
+ "email",
69
+ "website",
70
+ ];
71
+
72
+ const DEFAULT_LABELS: OrganizationFormLabels = {
73
+ name: "Organization name",
74
+ legalName: "Legal name",
75
+ timezone: "Timezone",
76
+ locale: "Language",
77
+ currency: "Currency",
78
+ address: "Address",
79
+ city: "City",
80
+ country: "Country",
81
+ phone: "Phone",
82
+ email: "Email",
83
+ website: "Website",
84
+ save: "Save changes",
85
+ reset: "Reset",
86
+ };
87
+
88
+ export const OrganizationProfileForm = ({
89
+ value,
90
+ fields,
91
+ selects,
92
+ labels,
93
+ busy = false,
94
+ onSave,
95
+ }: OrganizationProfileFormProps) => {
96
+ const text = { ...DEFAULT_LABELS, ...labels };
97
+ const [draft, setDraft] = useState<OrganizationProfile>(value);
98
+
99
+ useEffect(() => {
100
+ setDraft(value);
101
+ }, [value]);
102
+
103
+ const rendered = useMemo(
104
+ () =>
105
+ fields ??
106
+ FIELD_ORDER.filter((key) => key === "name" || value[key] !== undefined),
107
+ [fields, value],
108
+ );
109
+
110
+ const dirty = rendered.some(
111
+ (key) => (draft[key] ?? "") !== (value[key] ?? ""),
112
+ );
113
+ const nameEmpty = draft.name.trim().length === 0;
114
+
115
+ const setField = (key: OrganizationFieldKey, next: string) =>
116
+ setDraft((current) => ({ ...current, [key]: next }));
117
+
118
+ return (
119
+ <div className="udb-org-form">
120
+ <div className="udb-org-form__grid">
121
+ {rendered.map((key) => {
122
+ const options = selects?.[key as OrganizationSelectKey];
123
+ if (options) {
124
+ return (
125
+ <NativeSelect
126
+ key={key}
127
+ label={text[key]}
128
+ value={draft[key] ?? ""}
129
+ options={options}
130
+ onValueChange={(next) => setField(key, next)}
131
+ />
132
+ );
133
+ }
134
+ return (
135
+ <Input
136
+ key={key}
137
+ label={text[key]}
138
+ value={draft[key] ?? ""}
139
+ onChange={(event) => setField(key, event.target.value)}
140
+ />
141
+ );
142
+ })}
143
+ </div>
144
+ <div className="udb-org-form__actions">
145
+ <Button
146
+ variant="secondary"
147
+ disabled={!dirty || busy}
148
+ onClick={() => setDraft(value)}
149
+ >
150
+ {text.reset}
151
+ </Button>
152
+ <Button
153
+ loading={busy}
154
+ disabled={!dirty || busy || nameEmpty}
155
+ onClick={() => onSave(draft)}
156
+ >
157
+ {text.save}
158
+ </Button>
159
+ </div>
160
+ </div>
161
+ );
162
+ };
163
+
164
+ export default OrganizationProfileForm;
@@ -1,4 +1,5 @@
1
1
  import { DataTable, type Column } from "@umituz/web-design-system/organisms";
2
+ import { StatusBadge, type StatusVocab } from "@umituz/web-design-system/organisms";
2
3
  import type { RoleKey, RoleInfo } from "../../permissions/types";
3
4
 
4
5
  export interface ManagedUser {
@@ -7,6 +8,8 @@ export interface ManagedUser {
7
8
  email: string;
8
9
  role: RoleKey;
9
10
  status?: string;
11
+ /** Owner rows are shielded from removal/role changes when `isRowLocked` is not overridden. */
12
+ isOwner?: boolean;
10
13
  }
11
14
 
12
15
  export interface UserManagementTableLabels {
@@ -14,6 +17,9 @@ export interface UserManagementTableLabels {
14
17
  emailColumn: string;
15
18
  roleColumn: string;
16
19
  empty: string;
20
+ statusColumn?: string;
21
+ removeColumn?: string;
22
+ removeLabel?: string;
17
23
  }
18
24
 
19
25
  export interface UserManagementTableProps {
@@ -21,6 +27,12 @@ export interface UserManagementTableProps {
21
27
  roles: RoleInfo[];
22
28
  labels: UserManagementTableLabels;
23
29
  onRoleChange?: (userId: string, role: RoleKey) => void;
30
+ /** Renders a status column with badges when provided. */
31
+ statusVocab?: StatusVocab;
32
+ /** Renders a remove action column when provided; guarded rows stay hidden. */
33
+ onRemove?: (userId: string) => void;
34
+ /** Rows that must never be removed or role-changed; defaults to owner rows. */
35
+ isRowLocked?: (user: ManagedUser) => boolean;
24
36
  }
25
37
 
26
38
  export const UserManagementTable = ({
@@ -28,6 +40,9 @@ export const UserManagementTable = ({
28
40
  roles,
29
41
  labels,
30
42
  onRoleChange,
43
+ statusVocab,
44
+ onRemove,
45
+ isRowLocked = (user) => Boolean(user.isOwner),
31
46
  }: UserManagementTableProps) => {
32
47
  const columns: Column<ManagedUser>[] = [
33
48
  { id: "name", header: labels.nameColumn, accessor: "name" },
@@ -36,7 +51,7 @@ export const UserManagementTable = ({
36
51
  id: "role",
37
52
  header: labels.roleColumn,
38
53
  accessor: (user) =>
39
- onRoleChange ? (
54
+ onRoleChange && !(isRowLocked?.(user) ?? false) ? (
40
55
  <select
41
56
  className="udb-period-select__select"
42
57
  value={user.role}
@@ -57,6 +72,33 @@ export const UserManagementTable = ({
57
72
  },
58
73
  ];
59
74
 
75
+ if (statusVocab) {
76
+ columns.push({
77
+ id: "status",
78
+ header: labels.statusColumn ?? "Status",
79
+ accessor: (user) =>
80
+ user.status ? <StatusBadge vocab={statusVocab} value={user.status} /> : null,
81
+ });
82
+ }
83
+
84
+ if (onRemove) {
85
+ columns.push({
86
+ id: "remove",
87
+ header: labels.removeColumn ?? "",
88
+ align: "right",
89
+ accessor: (user) =>
90
+ isRowLocked?.(user) ?? false ? null : (
91
+ <button
92
+ type="button"
93
+ className="udb-link-button"
94
+ onClick={() => onRemove(user.id)}
95
+ >
96
+ {labels.removeLabel ?? "Remove"}
97
+ </button>
98
+ ),
99
+ });
100
+ }
101
+
60
102
  return (
61
103
  <DataTable
62
104
  data={users}
@@ -10,3 +10,12 @@ export {
10
10
  type PermissionMatrixScreenProps,
11
11
  } from './PermissionMatrixScreen';
12
12
  export { AuditLogList, type AuditLogListProps, type AuditEntry } from './AuditLogList';
13
+ export {
14
+ OrganizationProfileForm,
15
+ type OrganizationProfileFormProps,
16
+ type OrganizationProfile,
17
+ type OrganizationFieldKey,
18
+ type OrganizationSelectKey,
19
+ type OrganizationSelectOption,
20
+ type OrganizationFormLabels,
21
+ } from './OrganizationProfileForm';
@@ -1275,6 +1275,156 @@
1275
1275
  font-size: var(--udb-font-size-sm);
1276
1276
  color: var(--color-muted-foreground);
1277
1277
  }
1278
+ .udb-org-form {
1279
+ display: flex;
1280
+ flex-direction: column;
1281
+ gap: var(--udb-space-4);
1282
+ }
1283
+ .udb-org-form__grid {
1284
+ display: grid;
1285
+ grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
1286
+ gap: var(--udb-space-3) var(--udb-space-4);
1287
+ }
1288
+ .udb-org-form__actions {
1289
+ display: flex;
1290
+ justify-content: flex-end;
1291
+ gap: var(--udb-space-2);
1292
+ }
1293
+ .udb-org-card {
1294
+ display: flex;
1295
+ flex-direction: column;
1296
+ border: 1px solid var(--color-border);
1297
+ border-radius: var(--radius-lg);
1298
+ background: var(--color-card);
1299
+ overflow: hidden;
1300
+ text-align: left;
1301
+ }
1302
+ .udb-org-card--clickable {
1303
+ cursor: pointer;
1304
+ transition: border-color 0.15s ease;
1305
+ }
1306
+ .udb-org-card--clickable:hover {
1307
+ border-color: var(--color-primary);
1308
+ }
1309
+ .udb-org-card__initials {
1310
+ display: flex;
1311
+ align-items: center;
1312
+ justify-content: center;
1313
+ width: 100%;
1314
+ height: 100%;
1315
+ font-size: var(--udb-font-size-2xl);
1316
+ font-weight: var(--font-weight-bold);
1317
+ color: #fff;
1318
+ text-shadow: 0 1px 2px rgb(0 0 0 / 0.35);
1319
+ }
1320
+ .udb-org-card__body {
1321
+ display: flex;
1322
+ flex-direction: column;
1323
+ gap: var(--udb-space-2);
1324
+ padding: var(--udb-space-4);
1325
+ }
1326
+ .udb-org-card__head {
1327
+ display: flex;
1328
+ align-items: flex-start;
1329
+ justify-content: space-between;
1330
+ gap: var(--udb-space-3);
1331
+ }
1332
+ .udb-org-card__name {
1333
+ margin: 0;
1334
+ font-size: var(--udb-font-size-lg);
1335
+ font-weight: var(--font-weight-semibold);
1336
+ }
1337
+ .udb-org-card__legal {
1338
+ margin: 0;
1339
+ font-size: var(--udb-font-size-sm);
1340
+ color: var(--color-muted-foreground);
1341
+ }
1342
+ .udb-org-card__plan {
1343
+ flex-shrink: 0;
1344
+ font-size: var(--udb-font-size-xs);
1345
+ font-weight: var(--font-weight-semibold);
1346
+ padding: var(--udb-space-1) var(--udb-space-2);
1347
+ border-radius: 999px;
1348
+ background: var(--color-secondary);
1349
+ color: var(--color-secondary-foreground);
1350
+ white-space: nowrap;
1351
+ }
1352
+ .udb-org-card__meta {
1353
+ margin: 0;
1354
+ font-size: var(--udb-font-size-sm);
1355
+ color: var(--color-muted-foreground);
1356
+ }
1357
+ .udb-org-card__hint {
1358
+ display: flex;
1359
+ flex-direction: column;
1360
+ align-items: flex-start;
1361
+ gap: var(--udb-space-2);
1362
+ padding: var(--udb-space-3);
1363
+ border-radius: var(--radius-md);
1364
+ background: var(--color-muted);
1365
+ }
1366
+ .udb-org-card__hint p {
1367
+ margin: 0;
1368
+ font-size: var(--udb-font-size-sm);
1369
+ color: var(--color-muted-foreground);
1370
+ }
1371
+ .udb-members {
1372
+ display: flex;
1373
+ flex-direction: column;
1374
+ gap: var(--udb-space-3);
1375
+ }
1376
+ .udb-members__head {
1377
+ display: flex;
1378
+ align-items: center;
1379
+ justify-content: space-between;
1380
+ gap: var(--udb-space-3);
1381
+ }
1382
+ .udb-members__title {
1383
+ margin: 0;
1384
+ font-size: var(--udb-font-size-md);
1385
+ font-weight: var(--font-weight-semibold);
1386
+ }
1387
+ .udb-members__count {
1388
+ color: var(--color-muted-foreground);
1389
+ font-weight: var(--font-weight-normal);
1390
+ }
1391
+ .udb-members__invite {
1392
+ padding: var(--udb-space-4);
1393
+ border: 1px solid var(--color-border);
1394
+ border-radius: var(--radius-md);
1395
+ background: var(--color-muted);
1396
+ }
1397
+ .udb-invite {
1398
+ display: flex;
1399
+ flex-direction: column;
1400
+ gap: var(--udb-space-3);
1401
+ }
1402
+ .udb-invite__grid {
1403
+ display: grid;
1404
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
1405
+ gap: var(--udb-space-3) var(--udb-space-4);
1406
+ }
1407
+ .udb-invite__actions {
1408
+ display: flex;
1409
+ justify-content: flex-end;
1410
+ gap: var(--udb-space-2);
1411
+ }
1412
+ .udb-org-switcher {
1413
+ max-width: 260px;
1414
+ }
1415
+ .udb-link-button {
1416
+ appearance: none;
1417
+ background: none;
1418
+ border: none;
1419
+ padding: 0;
1420
+ font: inherit;
1421
+ font-size: var(--udb-font-size-sm);
1422
+ color: var(--color-destructive);
1423
+ cursor: pointer;
1424
+ }
1425
+ .udb-link-button:hover {
1426
+ text-decoration: underline;
1427
+ }
1278
1428
  .udb-matrix__group-row th {
1279
1429
  font-size: var(--udb-font-size-xs);
1280
1430
  font-weight: var(--font-weight-bold);
@@ -2382,6 +2532,14 @@
2382
2532
  background: var(--color-card);
2383
2533
  font-size: var(--udb-font-size-sm);
2384
2534
  }
2535
+ .udb-onb-input {
2536
+ width: 100%;
2537
+ padding: var(--udb-space-2);
2538
+ border: 1px solid var(--color-border);
2539
+ border-radius: var(--radius-md);
2540
+ background: var(--color-card);
2541
+ font-size: var(--udb-font-size-sm);
2542
+ }
2385
2543
  .udb-onb-chips {
2386
2544
  display: flex;
2387
2545
  flex-wrap: wrap;