@umituz/web-dashboard 7.6.0 → 7.7.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.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",
|
|
@@ -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;
|
|
@@ -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';
|
package/src/styles/chrome.css
CHANGED
|
@@ -1275,6 +1275,21 @@
|
|
|
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
|
+
}
|
|
1278
1293
|
.udb-matrix__group-row th {
|
|
1279
1294
|
font-size: var(--udb-font-size-xs);
|
|
1280
1295
|
font-weight: var(--font-weight-bold);
|