@jskit-ai/users-web 0.2.91 → 0.2.93
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/CHANGELOG.md +1 -0
- package/package.json +9 -9
- package/patterns/account-settings/PATTERN.md +12 -1
- package/patterns/account-settings/example/src/components/account/settings/AccountSettingsNotificationsSection.vue +16 -2
- package/patterns/account-settings/example/src/components/account/settings/AccountSettingsPreferencesSection.vue +33 -7
- package/patterns/account-settings/example/src/components/account/settings/AccountSettingsProfileSection.vue +11 -1
- package/src/client/composables/useAccountSettingsRuntime.js +84 -52
- package/test/accountSettings.browser.test.js +39 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Account settings read again (an `account.settings.changed` event, the window regaining focus, Retry) keep what the person changed and has not saved in each section, and take every other field. Before, each read and each section's save wrote all three forms, so a live update, or saving one section, replaced unsaved edits in every section. Each form now takes the settings through its own `useAddEdit()` runtime (http-web's `applyLoaded`), and a section's save answer becomes the settings read (`setQueryData`), which every form takes the same way. The runtime's `profile`, `preferences` and `notifications` each have `conflicts` (a ref of `{ key, value }`, the fields whose server value changed under the person's change), `acceptServerValue(key)` and `keepOwnValue(key)`, and the account-settings pattern's sections show them after their Save button with http-web's `EditConflictNotice`; their fields stay editable while the settings are read again. The pattern now requires `@jskit-ai/http-web`. Upgrading: an app's copy of the pattern's sections keeps working and now keeps edits; to say when the server changed a field and to keep fields open during the read, copy the sections' `conflictItems` and `<EditConflictNotice>` and drop `isRefreshing` from the fields' `readonly` and `disabled`.
|
|
5
6
|
- The account-settings pattern's Save buttons keep keyboard focus while their section saves and then reloads (shell-web's `v-pending`), instead of becoming disabled for the reload, which dropped focus to the page body.
|
|
6
7
|
- Account settings read their operations from users-core's `userProfileContract` and `userSettingsContract`.
|
|
7
8
|
- Account settings sections are pages in Material 3's list-detail layout (shell-web's `ShellListDetail`): `/account` lists the sections and `/account/<section>` opens one, instead of `?section=` on one page. `AccountSettingsClientElement` reads the route's `section` param and links each section to its path, keeping `returnTo`; on compact and medium windows it shows the list or one section, whose Up returns to the list, and on expanded and large windows the list beside the open section (or the first section on the list's own page), where Done replaces Up as the way out. The `users/account-settings` pattern adds `src/pages/account/[section].vue`, with parent `"/"`. Upgrading: add that page beside `src/pages/account/index.vue`, and change links to `/account?section=<value>` into `/account/<value>`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/users-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.93",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
"./locales/en.json": "./locales/en.json"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@jskit-ai/uploads-image-web": "0.2.
|
|
17
|
-
"@jskit-ai/users-core": "0.2.
|
|
16
|
+
"@jskit-ai/uploads-image-web": "0.2.36",
|
|
17
|
+
"@jskit-ai/users-core": "0.2.73"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@jskit-ai/auth-web": "0.2.
|
|
21
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
22
|
-
"@jskit-ai/http-web": "0.2.
|
|
23
|
-
"@jskit-ai/kernel": "0.2.
|
|
24
|
-
"@jskit-ai/shell-web": "0.2.
|
|
20
|
+
"@jskit-ai/auth-web": "0.2.67",
|
|
21
|
+
"@jskit-ai/http-runtime": "0.2.37",
|
|
22
|
+
"@jskit-ai/http-web": "0.2.68",
|
|
23
|
+
"@jskit-ai/kernel": "0.2.36",
|
|
24
|
+
"@jskit-ai/shell-web": "0.2.59",
|
|
25
25
|
"@tanstack/vue-query": "^5.90.5",
|
|
26
26
|
"vue": "^3.5.13",
|
|
27
27
|
"vue-router": "^5.0.4",
|
|
@@ -230,6 +230,6 @@
|
|
|
230
230
|
}
|
|
231
231
|
},
|
|
232
232
|
"devDependencies": {
|
|
233
|
-
"@jskit-ai/material-web": "0.1.
|
|
233
|
+
"@jskit-ai/material-web": "0.1.17"
|
|
234
234
|
}
|
|
235
235
|
}
|
|
@@ -3,7 +3,7 @@ id: users/account-settings
|
|
|
3
3
|
title: Account settings surface
|
|
4
4
|
summary: Compose an account settings route and profile, preference, notification, and sign-in method sections from JSKIT user web components.
|
|
5
5
|
keywords: account, notifications, preferences, profile, settings, sign-in methods, oauth, link provider, user, vue
|
|
6
|
-
requires: @jskit-ai/users-core, @jskit-ai/users-web, @jskit-ai/shell-web
|
|
6
|
+
requires: @jskit-ai/users-core, @jskit-ai/users-web, @jskit-ai/shell-web, @jskit-ai/http-web
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
# Account settings surface
|
|
@@ -38,6 +38,17 @@ app's language; the app does, for example
|
|
|
38
38
|
`watch(useAccountLocale(), (code) => { if (code) i18n.global.locale.value = code; }, { immediate: true })`.
|
|
39
39
|
Section titles may be plain text, a message key or `{ key, fallback }`.
|
|
40
40
|
|
|
41
|
+
The settings are read again on `account.settings.changed`, when the window
|
|
42
|
+
regains focus and on Retry, and each form's save answers with them all. Each
|
|
43
|
+
section keeps what the person changed and has not saved, and takes every other
|
|
44
|
+
field; its fields stay editable while the read runs. A section's `conflicts`
|
|
45
|
+
(a ref) lists the fields whose server value changed under the person's change,
|
|
46
|
+
as `{ key, value }` with the server's value; `acceptServerValue(key)` takes it
|
|
47
|
+
and `keepOwnValue(key)` keeps theirs. The example sections show them after
|
|
48
|
+
their Save button with `EditConflictNotice` from
|
|
49
|
+
`@jskit-ai/http-web/client/components/EditConflictNotice`, which takes
|
|
50
|
+
`{ key, label, value }` items, `value` the server's value as the field shows it.
|
|
51
|
+
|
|
41
52
|
Sections are pages of the account surface, in Material 3's list-detail layout
|
|
42
53
|
(shell-web's `ShellListDetail`): `/account` is the section list
|
|
43
54
|
(`src/pages/account/index.vue`) and `/account/<section>` one section
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import EditConflictNotice from "@jskit-ai/http-web/client/components/EditConflictNotice";
|
|
2
4
|
import { vPending } from "@jskit-ai/shell-web/client/directives/vPending";
|
|
3
5
|
|
|
4
6
|
const props = defineProps({
|
|
@@ -9,6 +11,13 @@ const props = defineProps({
|
|
|
9
11
|
});
|
|
10
12
|
|
|
11
13
|
const notifications = props.runtime.notifications;
|
|
14
|
+
|
|
15
|
+
// The settings read again (another session saved them) keep what the person switched; the notice names each switch
|
|
16
|
+
// whose server value changed meanwhile.
|
|
17
|
+
const FIELD_LABELS = Object.freeze({ productUpdates: "Product updates", accountActivity: "Account activity alerts" });
|
|
18
|
+
const conflictItems = computed(() =>
|
|
19
|
+
notifications.conflicts.value.map(({ key, value }) => ({ key, label: FIELD_LABELS[key] || key, value: value ? "On" : "Off" }))
|
|
20
|
+
);
|
|
12
21
|
</script>
|
|
13
22
|
|
|
14
23
|
<template>
|
|
@@ -20,7 +29,7 @@ const notifications = props.runtime.notifications;
|
|
|
20
29
|
label="Product updates"
|
|
21
30
|
color="primary"
|
|
22
31
|
hide-details
|
|
23
|
-
:disabled="notifications.isSaving.value
|
|
32
|
+
:disabled="notifications.isSaving.value"
|
|
24
33
|
class="mb-2"
|
|
25
34
|
/>
|
|
26
35
|
<v-switch
|
|
@@ -28,7 +37,7 @@ const notifications = props.runtime.notifications;
|
|
|
28
37
|
label="Account activity alerts"
|
|
29
38
|
color="primary"
|
|
30
39
|
hide-details
|
|
31
|
-
:disabled="notifications.isSaving.value
|
|
40
|
+
:disabled="notifications.isSaving.value"
|
|
32
41
|
class="mb-2"
|
|
33
42
|
/>
|
|
34
43
|
<v-switch
|
|
@@ -47,6 +56,11 @@ const notifications = props.runtime.notifications;
|
|
|
47
56
|
>
|
|
48
57
|
Save notification settings
|
|
49
58
|
</v-btn>
|
|
59
|
+
<EditConflictNotice
|
|
60
|
+
:items="conflictItems"
|
|
61
|
+
@accept="notifications.acceptServerValue"
|
|
62
|
+
@keep="notifications.keepOwnValue"
|
|
63
|
+
/>
|
|
50
64
|
</v-form>
|
|
51
65
|
</div>
|
|
52
66
|
</div>
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import EditConflictNotice from "@jskit-ai/http-web/client/components/EditConflictNotice";
|
|
2
4
|
import { vPending } from "@jskit-ai/shell-web/client/directives/vPending";
|
|
3
5
|
|
|
4
6
|
const props = defineProps({
|
|
@@ -9,6 +11,25 @@ const props = defineProps({
|
|
|
9
11
|
});
|
|
10
12
|
|
|
11
13
|
const preferences = props.runtime.preferences;
|
|
14
|
+
|
|
15
|
+
// The settings read again (another session saved them) keep what the person chose; the notice names each field whose
|
|
16
|
+
// server value changed meanwhile, with that value as its list shows it.
|
|
17
|
+
const FIELDS = Object.freeze({
|
|
18
|
+
theme: { label: "Theme", options: "theme" },
|
|
19
|
+
locale: { label: "Language / locale", options: "locale" },
|
|
20
|
+
timeZone: { label: "Time zone", options: "timeZone" },
|
|
21
|
+
dateFormat: { label: "Date format", options: "dateFormat" },
|
|
22
|
+
numberFormat: { label: "Number format", options: "numberFormat" },
|
|
23
|
+
currencyCode: { label: "Currency", options: "currency" },
|
|
24
|
+
avatarSize: { label: "Avatar size", options: "avatarSize" }
|
|
25
|
+
});
|
|
26
|
+
const conflictItems = computed(() =>
|
|
27
|
+
preferences.conflicts.value.map(({ key, value }) => {
|
|
28
|
+
const field = FIELDS[key] || { label: key, options: "" };
|
|
29
|
+
const option = (preferences.options[field.options] || []).find((entry) => entry?.value === value);
|
|
30
|
+
return { key, label: field.label, value: String(option?.title ?? value ?? "") };
|
|
31
|
+
})
|
|
32
|
+
);
|
|
12
33
|
</script>
|
|
13
34
|
|
|
14
35
|
<template>
|
|
@@ -26,7 +47,7 @@ const preferences = props.runtime.preferences;
|
|
|
26
47
|
item-value="value"
|
|
27
48
|
variant="outlined"
|
|
28
49
|
density="comfortable"
|
|
29
|
-
:disabled="preferences.isSaving.value
|
|
50
|
+
:disabled="preferences.isSaving.value"
|
|
30
51
|
:error-messages="preferences.fieldErrors.theme"
|
|
31
52
|
/>
|
|
32
53
|
</v-col>
|
|
@@ -41,7 +62,7 @@ const preferences = props.runtime.preferences;
|
|
|
41
62
|
item-value="value"
|
|
42
63
|
variant="outlined"
|
|
43
64
|
density="comfortable"
|
|
44
|
-
:disabled="preferences.isSaving.value
|
|
65
|
+
:disabled="preferences.isSaving.value"
|
|
45
66
|
:error-messages="preferences.fieldErrors.locale"
|
|
46
67
|
/>
|
|
47
68
|
</v-col>
|
|
@@ -54,7 +75,7 @@ const preferences = props.runtime.preferences;
|
|
|
54
75
|
:items="preferences.options.timeZone"
|
|
55
76
|
variant="outlined"
|
|
56
77
|
density="comfortable"
|
|
57
|
-
:disabled="preferences.isSaving.value
|
|
78
|
+
:disabled="preferences.isSaving.value"
|
|
58
79
|
:error-messages="preferences.fieldErrors.timeZone"
|
|
59
80
|
/>
|
|
60
81
|
</v-col>
|
|
@@ -69,7 +90,7 @@ const preferences = props.runtime.preferences;
|
|
|
69
90
|
item-value="value"
|
|
70
91
|
variant="outlined"
|
|
71
92
|
density="comfortable"
|
|
72
|
-
:disabled="preferences.isSaving.value
|
|
93
|
+
:disabled="preferences.isSaving.value"
|
|
73
94
|
:error-messages="preferences.fieldErrors.dateFormat"
|
|
74
95
|
/>
|
|
75
96
|
</v-col>
|
|
@@ -84,7 +105,7 @@ const preferences = props.runtime.preferences;
|
|
|
84
105
|
item-value="value"
|
|
85
106
|
variant="outlined"
|
|
86
107
|
density="comfortable"
|
|
87
|
-
:disabled="preferences.isSaving.value
|
|
108
|
+
:disabled="preferences.isSaving.value"
|
|
88
109
|
:error-messages="preferences.fieldErrors.numberFormat"
|
|
89
110
|
/>
|
|
90
111
|
</v-col>
|
|
@@ -97,7 +118,7 @@ const preferences = props.runtime.preferences;
|
|
|
97
118
|
:items="preferences.options.currency"
|
|
98
119
|
variant="outlined"
|
|
99
120
|
density="comfortable"
|
|
100
|
-
:disabled="preferences.isSaving.value
|
|
121
|
+
:disabled="preferences.isSaving.value"
|
|
101
122
|
:error-messages="preferences.fieldErrors.currencyCode"
|
|
102
123
|
/>
|
|
103
124
|
</v-col>
|
|
@@ -110,7 +131,7 @@ const preferences = props.runtime.preferences;
|
|
|
110
131
|
:items="preferences.options.avatarSize"
|
|
111
132
|
variant="outlined"
|
|
112
133
|
density="comfortable"
|
|
113
|
-
:disabled="preferences.isSaving.value
|
|
134
|
+
:disabled="preferences.isSaving.value"
|
|
114
135
|
:error-messages="preferences.fieldErrors.avatarSize"
|
|
115
136
|
/>
|
|
116
137
|
</v-col>
|
|
@@ -125,6 +146,11 @@ const preferences = props.runtime.preferences;
|
|
|
125
146
|
>
|
|
126
147
|
Save preferences
|
|
127
148
|
</v-btn>
|
|
149
|
+
<EditConflictNotice
|
|
150
|
+
:items="conflictItems"
|
|
151
|
+
@accept="preferences.acceptServerValue"
|
|
152
|
+
@keep="preferences.keepOwnValue"
|
|
153
|
+
/>
|
|
128
154
|
</v-form>
|
|
129
155
|
</div>
|
|
130
156
|
</div>
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import EditConflictNotice from "@jskit-ai/http-web/client/components/EditConflictNotice";
|
|
2
4
|
import { vPending } from "@jskit-ai/shell-web/client/directives/vPending";
|
|
3
5
|
|
|
4
6
|
const props = defineProps({
|
|
@@ -9,6 +11,13 @@ const props = defineProps({
|
|
|
9
11
|
});
|
|
10
12
|
|
|
11
13
|
const profile = props.runtime.profile;
|
|
14
|
+
|
|
15
|
+
// The settings read again (another session saved them) keep what the person typed; the notice names each field whose
|
|
16
|
+
// server value changed meanwhile.
|
|
17
|
+
const FIELD_LABELS = Object.freeze({ displayName: "Display name", email: "Email" });
|
|
18
|
+
const conflictItems = computed(() =>
|
|
19
|
+
profile.conflicts.value.map(({ key, value }) => ({ key, label: FIELD_LABELS[key] || key, value: String(value ?? "") }))
|
|
20
|
+
);
|
|
12
21
|
</script>
|
|
13
22
|
|
|
14
23
|
<template>
|
|
@@ -60,7 +69,7 @@ const profile = props.runtime.profile;
|
|
|
60
69
|
variant="outlined"
|
|
61
70
|
density="comfortable"
|
|
62
71
|
autocomplete="nickname"
|
|
63
|
-
:readonly="profile.isSaving.value
|
|
72
|
+
:readonly="profile.isSaving.value"
|
|
64
73
|
:error-messages="profile.fieldErrors.displayName"
|
|
65
74
|
/>
|
|
66
75
|
</v-col>
|
|
@@ -88,6 +97,7 @@ const profile = props.runtime.profile;
|
|
|
88
97
|
>
|
|
89
98
|
Save profile
|
|
90
99
|
</v-btn>
|
|
100
|
+
<EditConflictNotice :items="conflictItems" @accept="profile.acceptServerValue" @keep="profile.keepOwnValue" />
|
|
91
101
|
</v-form>
|
|
92
102
|
</div>
|
|
93
103
|
</div>
|
|
@@ -195,58 +195,36 @@ function useAccountSettingsRuntime() {
|
|
|
195
195
|
}));
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
// Each form's fields from a settings document. Each writes only the record it is given: its form's runtime passes a
|
|
199
|
+
// copy, and gives the form only the fields the person has not changed and not saved.
|
|
200
|
+
function writeProfileFields(target, payload) {
|
|
199
201
|
const data = normalizeSettingsPayload(payload);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
profileForm.email = String(data.profile?.email || "");
|
|
203
|
-
applyAvatarData(data.profile?.avatar);
|
|
204
|
-
|
|
205
|
-
preferencesForm.theme = String(data.preferences?.theme || ACCOUNT_SETTINGS_DEFAULTS.preferences.theme);
|
|
206
|
-
preferencesForm.locale = String(data.preferences?.locale || ACCOUNT_SETTINGS_DEFAULTS.preferences.locale);
|
|
207
|
-
preferencesForm.timeZone = String(data.preferences?.timeZone || ACCOUNT_SETTINGS_DEFAULTS.preferences.timeZone);
|
|
208
|
-
preferencesForm.dateFormat = String(data.preferences?.dateFormat || ACCOUNT_SETTINGS_DEFAULTS.preferences.dateFormat);
|
|
209
|
-
preferencesForm.numberFormat = String(data.preferences?.numberFormat || ACCOUNT_SETTINGS_DEFAULTS.preferences.numberFormat);
|
|
210
|
-
preferencesForm.currencyCode = String(data.preferences?.currencyCode || ACCOUNT_SETTINGS_DEFAULTS.preferences.currencyCode);
|
|
211
|
-
preferencesForm.avatarSize = normalizeAvatarSize(data.preferences?.avatarSize || ACCOUNT_SETTINGS_DEFAULTS.preferences.avatarSize);
|
|
212
|
-
|
|
213
|
-
notificationsForm.productUpdates = Boolean(data.notifications?.productUpdates);
|
|
214
|
-
notificationsForm.accountActivity = Boolean(data.notifications?.accountActivity);
|
|
215
|
-
notificationsForm.securityAlerts = ACCOUNT_SETTINGS_DEFAULTS.notifications.securityAlerts;
|
|
216
|
-
|
|
217
|
-
applySignInMethods(data.security);
|
|
218
|
-
|
|
219
|
-
applyThemePreference(preferencesForm.theme);
|
|
220
|
-
if (data.preferences?.locale) {
|
|
221
|
-
savedLocale.value = preferencesForm.locale;
|
|
222
|
-
setAccountLocale(preferencesForm.locale);
|
|
223
|
-
}
|
|
202
|
+
target.displayName = String(data.profile?.displayName || "");
|
|
203
|
+
target.email = String(data.profile?.email || "");
|
|
224
204
|
}
|
|
225
205
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
206
|
+
function writePreferenceFields(target, payload) {
|
|
207
|
+
const data = normalizeSettingsPayload(payload);
|
|
208
|
+
target.theme = String(data.preferences?.theme || ACCOUNT_SETTINGS_DEFAULTS.preferences.theme);
|
|
209
|
+
target.locale = String(data.preferences?.locale || ACCOUNT_SETTINGS_DEFAULTS.preferences.locale);
|
|
210
|
+
target.timeZone = String(data.preferences?.timeZone || ACCOUNT_SETTINGS_DEFAULTS.preferences.timeZone);
|
|
211
|
+
target.dateFormat = String(data.preferences?.dateFormat || ACCOUNT_SETTINGS_DEFAULTS.preferences.dateFormat);
|
|
212
|
+
target.numberFormat = String(data.preferences?.numberFormat || ACCOUNT_SETTINGS_DEFAULTS.preferences.numberFormat);
|
|
213
|
+
target.currencyCode = String(data.preferences?.currencyCode || ACCOUNT_SETTINGS_DEFAULTS.preferences.currencyCode);
|
|
214
|
+
target.avatarSize = normalizeAvatarSize(data.preferences?.avatarSize || ACCOUNT_SETTINGS_DEFAULTS.preferences.avatarSize);
|
|
215
|
+
}
|
|
234
216
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
217
|
+
function writeNotificationFields(target, payload) {
|
|
218
|
+
const data = normalizeSettingsPayload(payload);
|
|
219
|
+
target.productUpdates = Boolean(data.notifications?.productUpdates);
|
|
220
|
+
target.accountActivity = Boolean(data.notifications?.accountActivity);
|
|
221
|
+
target.securityAlerts = ACCOUNT_SETTINGS_DEFAULTS.notifications.securityAlerts;
|
|
222
|
+
}
|
|
238
223
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
transport: USER_SETTINGS_TRANSPORT,
|
|
244
|
-
realtime: {
|
|
245
|
-
event: "account.settings.changed"
|
|
246
|
-
},
|
|
247
|
-
fallbackLoadError: t("jskit.users.accountSettings.loadFailed"),
|
|
248
|
-
mapLoadedToModel: mapAccountSettingsPayload
|
|
249
|
-
});
|
|
224
|
+
// A form's save answers with the whole settings document: it becomes the settings read, which every form then takes.
|
|
225
|
+
function storeSettings(payload) {
|
|
226
|
+
queryClient.setQueryData(accountSettingsQueryKey, payload);
|
|
227
|
+
}
|
|
250
228
|
|
|
251
229
|
const profileAddEdit = useAddEdit({
|
|
252
230
|
ownershipFilter: OWNERSHIP_PUBLIC,
|
|
@@ -259,7 +237,8 @@ function useAccountSettingsRuntime() {
|
|
|
259
237
|
fallbackSaveError: t("jskit.users.accountSettings.profile.saveFailed"),
|
|
260
238
|
fieldErrorKeys: ["displayName"],
|
|
261
239
|
model: profileForm,
|
|
262
|
-
mapLoadedToModel:
|
|
240
|
+
mapLoadedToModel: writeProfileFields,
|
|
241
|
+
onSaveSuccess: storeSettings,
|
|
263
242
|
input: userProfileContract.operations.patch.body,
|
|
264
243
|
buildRawPayload: (model) => ({
|
|
265
244
|
displayName: String(model.displayName || "").trim()
|
|
@@ -277,9 +256,9 @@ function useAccountSettingsRuntime() {
|
|
|
277
256
|
transport: USER_PROFILE_AVATAR_DELETE_TRANSPORT,
|
|
278
257
|
fallbackRunError: t("jskit.users.accountSettings.avatar.removeFailed"),
|
|
279
258
|
model: profileForm,
|
|
280
|
-
onRunSuccess: (payload
|
|
259
|
+
onRunSuccess: (payload) => {
|
|
281
260
|
applySettingsData(payload);
|
|
282
|
-
|
|
261
|
+
storeSettings(payload);
|
|
283
262
|
},
|
|
284
263
|
messages: {
|
|
285
264
|
success: t("jskit.users.accountSettings.avatar.removed"),
|
|
@@ -298,7 +277,8 @@ function useAccountSettingsRuntime() {
|
|
|
298
277
|
fallbackSaveError: t("jskit.users.accountSettings.preferences.saveFailed"),
|
|
299
278
|
fieldErrorKeys: ["theme", "locale", "timeZone", "dateFormat", "numberFormat", "currencyCode", "avatarSize"],
|
|
300
279
|
model: preferencesForm,
|
|
301
|
-
mapLoadedToModel:
|
|
280
|
+
mapLoadedToModel: writePreferenceFields,
|
|
281
|
+
onSaveSuccess: storeSettings,
|
|
302
282
|
input: userSettingsContract.operations.preferencesUpdate.body,
|
|
303
283
|
buildRawPayload: (model) => ({
|
|
304
284
|
theme: model.theme,
|
|
@@ -325,7 +305,8 @@ function useAccountSettingsRuntime() {
|
|
|
325
305
|
transport: USER_NOTIFICATION_SETTINGS_UPDATE_TRANSPORT,
|
|
326
306
|
fallbackSaveError: t("jskit.users.accountSettings.notifications.saveFailed"),
|
|
327
307
|
model: notificationsForm,
|
|
328
|
-
mapLoadedToModel:
|
|
308
|
+
mapLoadedToModel: writeNotificationFields,
|
|
309
|
+
onSaveSuccess: storeSettings,
|
|
329
310
|
input: userSettingsContract.operations.notificationsUpdate.body,
|
|
330
311
|
buildRawPayload: (model) => ({
|
|
331
312
|
productUpdates: Boolean(model.productUpdates),
|
|
@@ -357,6 +338,47 @@ function useAccountSettingsRuntime() {
|
|
|
357
338
|
}
|
|
358
339
|
});
|
|
359
340
|
|
|
341
|
+
// A settings document, from the settings read (its first load, a read again on `account.settings.changed` or the
|
|
342
|
+
// window regaining focus, Retry) or a command's answer: each form takes it through its own runtime, which keeps
|
|
343
|
+
// what the person changed and has not saved, and the rest of the page shows what the server holds.
|
|
344
|
+
function applySettingsData(payload) {
|
|
345
|
+
const data = normalizeSettingsPayload(payload);
|
|
346
|
+
profileAddEdit.applyLoaded(data);
|
|
347
|
+
preferencesAddEdit.applyLoaded(data);
|
|
348
|
+
notificationsAddEdit.applyLoaded(data);
|
|
349
|
+
|
|
350
|
+
applyAvatarData(data.profile?.avatar);
|
|
351
|
+
applySignInMethods(data.security);
|
|
352
|
+
applyThemePreference(String(data.preferences?.theme || ACCOUNT_SETTINGS_DEFAULTS.preferences.theme));
|
|
353
|
+
if (data.preferences?.locale) {
|
|
354
|
+
savedLocale.value = String(data.preferences.locale);
|
|
355
|
+
setAccountLocale(savedLocale.value);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const avatarUploadRuntime = createAccountSettingsAvatarUploadRuntime({
|
|
360
|
+
queryClient,
|
|
361
|
+
sessionQueryKey,
|
|
362
|
+
accountSettingsQueryKey,
|
|
363
|
+
selectedAvatarFileName,
|
|
364
|
+
applySettingsData,
|
|
365
|
+
reportAccountFeedback
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const settingsView = useView({
|
|
369
|
+
ownershipFilter: OWNERSHIP_PUBLIC,
|
|
370
|
+
apiSuffix: "/settings",
|
|
371
|
+
queryKeyFactory: () => accountSettingsQueryKey,
|
|
372
|
+
transport: USER_SETTINGS_TRANSPORT,
|
|
373
|
+
realtime: {
|
|
374
|
+
event: "account.settings.changed"
|
|
375
|
+
},
|
|
376
|
+
fallbackLoadError: t("jskit.users.accountSettings.loadFailed"),
|
|
377
|
+
mapLoadedToModel: (_model, payload = {}) => {
|
|
378
|
+
applySettingsData(payload);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
360
382
|
const loadingSettings = computed(() => Boolean(settingsView.isLoading));
|
|
361
383
|
const refreshingSettings = computed(() => Boolean(settingsView.isRefetching));
|
|
362
384
|
const savingProfile = computed(() => Boolean(profileAddEdit.isSaving));
|
|
@@ -432,6 +454,10 @@ function useAccountSettingsRuntime() {
|
|
|
432
454
|
initials: profileInitials,
|
|
433
455
|
selectedAvatarFileName,
|
|
434
456
|
fieldErrors: profileAddEdit.fieldErrors,
|
|
457
|
+
// The fields whose server value changed while the person was editing them, and their choice for each.
|
|
458
|
+
conflicts: computed(() => profileAddEdit.conflicts),
|
|
459
|
+
acceptServerValue: profileAddEdit.acceptServerValue,
|
|
460
|
+
keepOwnValue: profileAddEdit.keepOwnValue,
|
|
435
461
|
isSaving: savingProfile,
|
|
436
462
|
isDeletingAvatar: deletingAvatar,
|
|
437
463
|
isRefreshing: refreshingSettings,
|
|
@@ -443,6 +469,9 @@ function useAccountSettingsRuntime() {
|
|
|
443
469
|
const preferences = {
|
|
444
470
|
form: preferencesForm,
|
|
445
471
|
fieldErrors: preferencesAddEdit.fieldErrors,
|
|
472
|
+
conflicts: computed(() => preferencesAddEdit.conflicts),
|
|
473
|
+
acceptServerValue: preferencesAddEdit.acceptServerValue,
|
|
474
|
+
keepOwnValue: preferencesAddEdit.keepOwnValue,
|
|
446
475
|
isSaving: savingPreferences,
|
|
447
476
|
isRefreshing: refreshingSettings,
|
|
448
477
|
// Plain arrays for v-select items; the getters follow the active language.
|
|
@@ -468,6 +497,9 @@ function useAccountSettingsRuntime() {
|
|
|
468
497
|
|
|
469
498
|
const notifications = {
|
|
470
499
|
form: notificationsForm,
|
|
500
|
+
conflicts: computed(() => notificationsAddEdit.conflicts),
|
|
501
|
+
acceptServerValue: notificationsAddEdit.acceptServerValue,
|
|
502
|
+
keepOwnValue: notificationsAddEdit.keepOwnValue,
|
|
471
503
|
isSaving: savingNotifications,
|
|
472
504
|
isRefreshing: refreshingSettings,
|
|
473
505
|
submit: submitNotifications
|
|
@@ -170,6 +170,45 @@ test("the profile section loads, saves, shows a refused field and removes the av
|
|
|
170
170
|
await finish(api);
|
|
171
171
|
});
|
|
172
172
|
|
|
173
|
+
// The settings are read again while the person edits them: an `account.settings.changed` event, or here the window
|
|
174
|
+
// regaining focus (TanStack's refetchOnWindowFocus). Another session changed the settings meanwhile.
|
|
175
|
+
test("settings read again keep an unsaved display name, take the rest, and say when the server changed it", options, async () => {
|
|
176
|
+
let current = settings();
|
|
177
|
+
const api = await openApp({
|
|
178
|
+
routes: {
|
|
179
|
+
"GET /api/settings": () => document(current),
|
|
180
|
+
"PATCH /api/settings/profile": (body) => {
|
|
181
|
+
current = settings({ profile: { ...current.profile, displayName: body.data.attributes.displayName } });
|
|
182
|
+
return document(current);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
const { page } = api;
|
|
187
|
+
await page.goto("/account/profile");
|
|
188
|
+
const name = page.getByLabel("Display name");
|
|
189
|
+
const email = page.getByLabel("Email", { exact: true });
|
|
190
|
+
await expect(name).toHaveValue("Ada");
|
|
191
|
+
|
|
192
|
+
await name.fill("Ada Lovelace");
|
|
193
|
+
current = settings({ profile: { ...current.profile, displayName: "Countess Ada", email: "countess@example.com" } });
|
|
194
|
+
await page.evaluate(() => window.dispatchEvent(new Event("visibilitychange")));
|
|
195
|
+
|
|
196
|
+
await expect(email).toHaveValue("countess@example.com");
|
|
197
|
+
await expect(name).toHaveValue("Ada Lovelace");
|
|
198
|
+
const notice = page.locator(".account-settings-section").getByRole("status");
|
|
199
|
+
await expect(notice).toContainText("Display name changed to “Countess Ada” while you were editing.");
|
|
200
|
+
await notice.getByRole("button", { name: "Keep your Display name" }).click();
|
|
201
|
+
await expect(notice.getByRole("button")).toHaveCount(0);
|
|
202
|
+
await expect(name).toHaveValue("Ada Lovelace");
|
|
203
|
+
|
|
204
|
+
await page.getByRole("button", { name: "Save profile" }).click();
|
|
205
|
+
await expect.poll(() => lastReport(page)).toBe("Profile updated.");
|
|
206
|
+
const saved = api.requests.find((request) => request.key === "PATCH /api/settings/profile");
|
|
207
|
+
assert.deepEqual(saved.body.data.attributes, { displayName: "Ada Lovelace" });
|
|
208
|
+
await expect(name).toHaveValue("Ada Lovelace");
|
|
209
|
+
await finish(api);
|
|
210
|
+
});
|
|
211
|
+
|
|
173
212
|
// Material 3's list-detail layout: a phone shows the section list or one section, and Up returns from the section to
|
|
174
213
|
// the list and from the list to home; a wide window shows the list beside the open section, with no Up to the list.
|
|
175
214
|
test("a phone shows the section list and one section at a time, and Up returns to the list", options, async () => {
|