@rapidmx/web-client 0.9.0 → 0.10.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 +192 -88
- package/apps/shared/auth/accountUrl.ts +9 -0
- package/apps/shared/auth/adminAccess.ts +99 -0
- package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +2 -1
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +8 -2
- package/apps/shared/components/contacts/ContactsToolbar.tsx +125 -115
- package/apps/shared/components/contacts/layout/ContactsShell.tsx +15 -3
- package/apps/shared/components/layout/AppShell.tsx +411 -288
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -389
- package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -164
- package/apps/shared/components/layout/UserMenu.tsx +303 -185
- package/apps/shared/components/mail/ConversationList.tsx +269 -262
- package/apps/shared/components/mail/ConversationThreadPane.tsx +475 -434
- package/apps/shared/components/mail/LazyReadingPane.tsx +115 -0
- package/apps/shared/components/mail/MailSelectionBar.tsx +235 -222
- package/apps/shared/components/mail/MessageDetailPane.tsx +1458 -1387
- package/apps/shared/components/mail/NewMailToasts.tsx +141 -0
- package/apps/shared/components/mail/compose/ComposeContext.tsx +279 -160
- package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -418
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +1842 -1736
- package/apps/shared/components/mail/compose/ComposeWindowPlaceholder.tsx +111 -0
- package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -118
- package/apps/shared/components/mail/compose/composePerf.ts +46 -0
- package/apps/shared/components/mail/compose/quotedBody.ts +161 -100
- package/apps/shared/components/mail/layout/MailShell.tsx +476 -472
- package/apps/shared/components/mail/unreadStyle.tsx +75 -0
- package/apps/shared/components/settings/layout/SettingsShell.tsx +252 -240
- package/apps/shared/components/tasks/layout/TasksShell.tsx +15 -3
- package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -0
- package/apps/shared/keyboard/ShortcutProvider.tsx +62 -0
- package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -0
- package/apps/shared/keyboard/dispatch.ts +124 -0
- package/apps/shared/keyboard/format.ts +89 -0
- package/apps/shared/keyboard/keymap.ts +114 -0
- package/apps/shared/keyboard/match.ts +44 -0
- package/apps/shared/keyboard/parse.ts +136 -0
- package/apps/shared/keyboard/platform.ts +34 -0
- package/apps/shared/keyboard/registry.ts +65 -0
- package/apps/shared/keyboard/targets.ts +79 -0
- package/apps/shared/keyboard/useShortcut.ts +50 -0
- package/apps/shared/keyboard/useShortcutProps.ts +17 -0
- package/apps/shared/mail/folderCounts.ts +302 -0
- package/apps/shared/mail/listSnapshots.ts +87 -0
- package/apps/shared/mail/messageReadState.ts +85 -0
- package/apps/shared/mail/newMailNotifications.ts +183 -0
- package/apps/shared/mail/useMailConnection.ts +150 -0
- package/apps/shared/mail/useMailLiveUpdates.ts +232 -224
- package/apps/shared/mail/useMarkMessageRead.ts +47 -0
- package/apps/shared/mail/useNewMailNotifications.ts +163 -0
- package/apps/shared/mail/useUnreadTitle.ts +42 -0
- package/apps/shared/navigation/AppRouter.tsx +300 -0
- package/apps/shared/navigation/appHrefs.ts +23 -0
- package/apps/shared/navigation/frameContext.tsx +35 -0
- package/apps/shared/navigation/idle.ts +45 -0
- package/apps/shared/navigation/routerContext.tsx +83 -0
- package/apps/shared/navigation/routes.ts +72 -0
- package/apps/shared/search/LocalIndexLifecycle.tsx +114 -98
- package/apps/shared/styles/app.css +28 -10
- package/apps/www/_routedPage.tsx +24 -0
- package/apps/www/_routes.ts +35 -0
- package/apps/www/calendar/index.tsx +55 -19
- package/apps/www/contacts/[uid].tsx +112 -107
- package/apps/www/contacts/index.tsx +584 -567
- package/apps/www/index.tsx +2280 -1917
- package/apps/www/messages/[uid].tsx +106 -101
- package/apps/www/settings/auto-reply/index.tsx +4 -1
- package/apps/www/settings/encryption/index.tsx +1252 -1249
- package/apps/www/settings/filters/[uid].tsx +4 -1
- package/apps/www/settings/filters/index.tsx +102 -99
- package/apps/www/settings/filters/new/index.tsx +138 -133
- package/apps/www/settings/labels/index.tsx +204 -201
- package/apps/www/settings/privacy/index.tsx +4 -1
- package/apps/www/settings/read-receipts/index.tsx +4 -1
- package/apps/www/settings/sharing/index.tsx +277 -274
- package/apps/www/settings/signatures/[uid].tsx +170 -167
- package/apps/www/settings/signatures/index.tsx +88 -85
- package/apps/www/settings/signatures/new/index.tsx +134 -129
- package/apps/www/tasks/index.tsx +18 -2
- package/dist/apps/shared/auth/accountUrl.d.ts +2 -0
- package/dist/apps/shared/auth/accountUrl.js +8 -0
- package/dist/apps/shared/auth/adminAccess.d.ts +30 -0
- package/dist/apps/shared/auth/adminAccess.js +89 -0
- package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +1 -1
- package/dist/apps/shared/components/calendar/layout/CalendarShell.d.ts +1 -1
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +8 -4
- package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
- package/dist/apps/shared/components/contacts/ContactsToolbar.js +7 -4
- package/dist/apps/shared/components/contacts/layout/ContactsShell.d.ts +1 -1
- package/dist/apps/shared/components/contacts/layout/ContactsShell.js +15 -5
- package/dist/apps/shared/components/layout/AppShell.d.ts +29 -4
- package/dist/apps/shared/components/layout/AppShell.js +73 -14
- package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +10 -9
- package/dist/apps/shared/components/layout/MailboxProvisioning.js +3 -1
- package/dist/apps/shared/components/layout/UserMenu.d.ts +19 -3
- package/dist/apps/shared/components/layout/UserMenu.js +52 -5
- package/dist/apps/shared/components/mail/ConversationList.js +4 -11
- package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +4 -1
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +52 -27
- package/dist/apps/shared/components/mail/LazyReadingPane.d.ts +9 -0
- package/dist/apps/shared/components/mail/LazyReadingPane.js +82 -0
- package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +4 -1
- package/dist/apps/shared/components/mail/MailSelectionBar.js +11 -3
- package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +7 -1
- package/dist/apps/shared/components/mail/MessageDetailPane.js +83 -34
- package/dist/apps/shared/components/mail/NewMailToasts.d.ts +19 -0
- package/dist/apps/shared/components/mail/NewMailToasts.js +55 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +30 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +71 -5
- package/dist/apps/shared/components/mail/compose/ComposeToolbar.js +4 -3
- package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +1 -1
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +98 -22
- package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.d.ts +19 -0
- package/dist/apps/shared/components/mail/compose/ComposeWindowPlaceholder.js +33 -0
- package/dist/apps/shared/components/mail/compose/RichTextEditor.d.ts +9 -1
- package/dist/apps/shared/components/mail/compose/RichTextEditor.js +20 -2
- package/dist/apps/shared/components/mail/compose/composePerf.d.ts +16 -0
- package/dist/apps/shared/components/mail/compose/composePerf.js +41 -0
- package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +13 -0
- package/dist/apps/shared/components/mail/compose/quotedBody.js +67 -11
- package/dist/apps/shared/components/mail/layout/MailShell.d.ts +12 -4
- package/dist/apps/shared/components/mail/layout/MailShell.js +76 -96
- package/dist/apps/shared/components/mail/unreadStyle.d.ts +45 -0
- package/dist/apps/shared/components/mail/unreadStyle.js +61 -0
- package/dist/apps/shared/components/settings/layout/SettingsShell.d.ts +1 -1
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +15 -5
- package/dist/apps/shared/components/tasks/layout/TasksShell.d.ts +1 -1
- package/dist/apps/shared/components/tasks/layout/TasksShell.js +15 -5
- package/dist/apps/shared/keyboard/GlobalShortcuts.d.ts +14 -0
- package/dist/apps/shared/keyboard/GlobalShortcuts.js +37 -0
- package/dist/apps/shared/keyboard/ShortcutProvider.d.ts +20 -0
- package/dist/apps/shared/keyboard/ShortcutProvider.js +52 -0
- package/dist/apps/shared/keyboard/ShortcutsDialog.d.ts +14 -0
- package/dist/apps/shared/keyboard/ShortcutsDialog.js +42 -0
- package/dist/apps/shared/keyboard/dispatch.d.ts +16 -0
- package/dist/apps/shared/keyboard/dispatch.js +109 -0
- package/dist/apps/shared/keyboard/format.d.ts +12 -0
- package/dist/apps/shared/keyboard/format.js +74 -0
- package/dist/apps/shared/keyboard/keymap.d.ts +294 -0
- package/dist/apps/shared/keyboard/keymap.js +84 -0
- package/dist/apps/shared/keyboard/match.d.ts +20 -0
- package/dist/apps/shared/keyboard/match.js +31 -0
- package/dist/apps/shared/keyboard/parse.d.ts +31 -0
- package/dist/apps/shared/keyboard/parse.js +107 -0
- package/dist/apps/shared/keyboard/platform.d.ts +15 -0
- package/dist/apps/shared/keyboard/platform.js +22 -0
- package/dist/apps/shared/keyboard/registry.d.ts +39 -0
- package/dist/apps/shared/keyboard/registry.js +33 -0
- package/dist/apps/shared/keyboard/targets.d.ts +14 -0
- package/dist/apps/shared/keyboard/targets.js +67 -0
- package/dist/apps/shared/keyboard/useShortcut.d.ts +19 -0
- package/dist/apps/shared/keyboard/useShortcut.js +35 -0
- package/dist/apps/shared/keyboard/useShortcutProps.d.ts +10 -0
- package/dist/apps/shared/keyboard/useShortcutProps.js +15 -0
- package/dist/apps/shared/mail/folderCounts.d.ts +78 -0
- package/dist/apps/shared/mail/folderCounts.js +212 -0
- package/dist/apps/shared/mail/listSnapshots.d.ts +46 -0
- package/dist/apps/shared/mail/listSnapshots.js +43 -0
- package/dist/apps/shared/mail/messageReadState.d.ts +32 -0
- package/dist/apps/shared/mail/messageReadState.js +63 -0
- package/dist/apps/shared/mail/newMailNotifications.d.ts +62 -0
- package/dist/apps/shared/mail/newMailNotifications.js +138 -0
- package/dist/apps/shared/mail/useMailConnection.d.ts +55 -0
- package/dist/apps/shared/mail/useMailConnection.js +96 -0
- package/dist/apps/shared/mail/useMailLiveUpdates.d.ts +13 -6
- package/dist/apps/shared/mail/useMailLiveUpdates.js +28 -26
- package/dist/apps/shared/mail/useMarkMessageRead.d.ts +12 -0
- package/dist/apps/shared/mail/useMarkMessageRead.js +44 -0
- package/dist/apps/shared/mail/useNewMailNotifications.d.ts +41 -0
- package/dist/apps/shared/mail/useNewMailNotifications.js +110 -0
- package/dist/apps/shared/mail/useUnreadTitle.d.ts +18 -0
- package/dist/apps/shared/mail/useUnreadTitle.js +31 -0
- package/dist/apps/shared/navigation/AppRouter.d.ts +52 -0
- package/dist/apps/shared/navigation/AppRouter.js +242 -0
- package/dist/apps/shared/navigation/appHrefs.d.ts +14 -0
- package/dist/apps/shared/navigation/appHrefs.js +20 -0
- package/dist/apps/shared/navigation/frameContext.d.ts +19 -0
- package/dist/apps/shared/navigation/frameContext.js +24 -0
- package/dist/apps/shared/navigation/idle.d.ts +14 -0
- package/dist/apps/shared/navigation/idle.js +43 -0
- package/dist/apps/shared/navigation/routerContext.d.ts +37 -0
- package/dist/apps/shared/navigation/routerContext.js +56 -0
- package/dist/apps/shared/navigation/routes.d.ts +32 -0
- package/dist/apps/shared/navigation/routes.js +37 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.js +17 -3
- package/dist/apps/shared/styles/app.css +28 -10
- package/dist/apps/www/_routedPage.d.ts +12 -0
- package/dist/apps/www/_routedPage.js +19 -0
- package/dist/apps/www/_routes.d.ts +11 -0
- package/dist/apps/www/_routes.js +29 -0
- package/dist/apps/www/calendar/index.d.ts +2 -2
- package/dist/apps/www/calendar/index.js +39 -8
- package/dist/apps/www/contacts/[uid].d.ts +3 -9
- package/dist/apps/www/contacts/[uid].js +6 -2
- package/dist/apps/www/contacts/index.d.ts +2 -2
- package/dist/apps/www/contacts/index.js +17 -4
- package/dist/apps/www/index.d.ts +2 -2
- package/dist/apps/www/index.js +301 -35
- package/dist/apps/www/messages/[uid].d.ts +3 -7
- package/dist/apps/www/messages/[uid].js +7 -4
- package/dist/apps/www/settings/auto-reply/index.d.ts +2 -2
- package/dist/apps/www/settings/auto-reply/index.js +3 -1
- package/dist/apps/www/settings/encryption/index.d.ts +2 -2
- package/dist/apps/www/settings/encryption/index.js +3 -1
- package/dist/apps/www/settings/filters/[uid].d.ts +2 -2
- package/dist/apps/www/settings/filters/[uid].js +3 -1
- package/dist/apps/www/settings/filters/index.d.ts +2 -2
- package/dist/apps/www/settings/filters/index.js +3 -1
- package/dist/apps/www/settings/filters/new/index.d.ts +2 -2
- package/dist/apps/www/settings/filters/new/index.js +6 -2
- package/dist/apps/www/settings/labels/index.d.ts +2 -2
- package/dist/apps/www/settings/labels/index.js +3 -1
- package/dist/apps/www/settings/privacy/index.d.ts +2 -2
- package/dist/apps/www/settings/privacy/index.js +3 -1
- package/dist/apps/www/settings/read-receipts/index.d.ts +2 -2
- package/dist/apps/www/settings/read-receipts/index.js +3 -1
- package/dist/apps/www/settings/sharing/index.d.ts +2 -2
- package/dist/apps/www/settings/sharing/index.js +3 -1
- package/dist/apps/www/settings/signatures/[uid].d.ts +2 -2
- package/dist/apps/www/settings/signatures/[uid].js +3 -1
- package/dist/apps/www/settings/signatures/index.d.ts +2 -2
- package/dist/apps/www/settings/signatures/index.js +3 -1
- package/dist/apps/www/settings/signatures/new/index.d.ts +2 -2
- package/dist/apps/www/settings/signatures/new/index.js +6 -2
- package/dist/apps/www/tasks/index.d.ts +2 -2
- package/dist/apps/www/tasks/index.js +15 -3
- package/package.json +2 -2
|
@@ -1,185 +1,303 @@
|
|
|
1
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { useEffect, useRef, useState } from "react";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { HiOutlineShieldCheck } from "react-icons/hi2";
|
|
7
|
+
import { formatProfileName, getMyProfile, getMyUsername, Profile, profileInitials } from "@rapidmx/react-shared/auth/profileApi.js";
|
|
8
|
+
import { accountUrlOf } from "../../auth/accountUrl.js";
|
|
9
|
+
import { DEFAULT_TRUSTED_ROLES, lookUpAdminAccess } from "../../auth/adminAccess.js";
|
|
10
|
+
import { ariaKeyShortcuts } from "../../keyboard/format.js";
|
|
11
|
+
import { SHORTCUTS } from "../../keyboard/keymap.js";
|
|
12
|
+
import { useKeyEnvironment } from "../../keyboard/ShortcutProvider.js";
|
|
13
|
+
import { SETTINGS_HREF } from "../../navigation/appHrefs.js";
|
|
14
|
+
import {
|
|
15
|
+
DesktopPermission,
|
|
16
|
+
desktopPermission,
|
|
17
|
+
getNewMailPopupsEnabled,
|
|
18
|
+
requestDesktopPermission,
|
|
19
|
+
setDesktopOfferDismissed,
|
|
20
|
+
setNewMailPopupsEnabled,
|
|
21
|
+
} from "../../mail/newMailNotifications.js";
|
|
22
|
+
|
|
23
|
+
export interface UserMenuProps {
|
|
24
|
+
userUid: string;
|
|
25
|
+
/** auth-server's base URL — where the caller's own profile (name/avatar) and username are fetched from, and what
|
|
26
|
+
* the "Account" item links into, if configured. Without it the menu shows the bare uid and has no "Account" item. */
|
|
27
|
+
authServerUrl?: string;
|
|
28
|
+
onSignOut: () => void;
|
|
29
|
+
/** Shows an "Admin Console" item linking to `/admin`, above "Sign Out" — pass only for a trusted-role caller
|
|
30
|
+
* (the JWT carries the role, i.e. an elevated session). See `detectAdmin` for everyone else. */
|
|
31
|
+
showAdminLink?: boolean;
|
|
32
|
+
/** Asks auth-server whether the caller holds a trusted role (`GET /api/users/me`, once per sitting - see
|
|
33
|
+
* `lookUpAdminAccess()`) and shows the "Admin Console" item if so. Needed because a token that isn't elevated
|
|
34
|
+
* carries no trusted role, so an administrator with an ordinary session is not `showAdminLink`. Does nothing
|
|
35
|
+
* without `authServerUrl`, and a failed lookup leaves the item hidden. Pass `false` while impersonating. */
|
|
36
|
+
detectAdmin?: boolean;
|
|
37
|
+
/** The role names the server treats as trusted (its `trusted_roles` config) - what `detectAdmin` looks for.
|
|
38
|
+
* Defaults to `["admin"]`, the server's own default. */
|
|
39
|
+
trustedRoles?: readonly string[];
|
|
40
|
+
/** Shows a "Settings" item, above "Admin"/"Sign Out" — an account-scoped surface (like "Admin"), not
|
|
41
|
+
* a content-scoped one, so it lives here rather than as a 5th `AppShell` rail icon. Links straight to
|
|
42
|
+
* `/settings/auto-reply`, the only settings section that exists today; repoint this at a real
|
|
43
|
+
* `/settings` landing page once a second section (Mail Filters, Signatures) makes one worth building. */
|
|
44
|
+
showSettingsLink?: boolean;
|
|
45
|
+
/** Shows the new-mail notification controls, above "Admin Console"/"Sign Out": a "New mail pop-ups" on/off switch and, while
|
|
46
|
+
* the browser hasn't been asked, "Turn on desktop notifications". Both are per browser (see `newMailNotifications.ts`).
|
|
47
|
+
* For the shells that announce new mail (Mail); the consoles have nothing to announce. */
|
|
48
|
+
showNotificationSettings?: boolean;
|
|
49
|
+
/** Shows a "Keyboard shortcuts" item that calls this - opening the help dialog (`?` and Ctrl+/ do too). For the shells that have the
|
|
50
|
+
* keyboard layer (`AppChrome`); the consoles don't offer it. */
|
|
51
|
+
onShowShortcuts?: () => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function Avatar({ profile, initials, large }: { profile?: Profile; initials: string; large?: boolean }) {
|
|
55
|
+
const sizeClass = large ? "w-10 h-10 text-base" : "w-8 h-8 text-sm";
|
|
56
|
+
if (profile?.avatar) {
|
|
57
|
+
return (
|
|
58
|
+
<img
|
|
59
|
+
src={profile.avatar}
|
|
60
|
+
alt=""
|
|
61
|
+
className={`${sizeClass} rounded-full object-cover shrink-0`}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return (
|
|
66
|
+
<span
|
|
67
|
+
className={`${sizeClass} rounded-full bg-primary text-white font-semibold flex items-center justify-center shrink-0`}
|
|
68
|
+
>
|
|
69
|
+
{initials}
|
|
70
|
+
</span>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The top-right "who am I" menu shared by every shell (`AppShell`, `AdminShell`, `EscrowShell`): an avatar-button
|
|
76
|
+
* trigger that opens a dropdown showing the caller's avatar/name, an "Account" link to auth-server's account page,
|
|
77
|
+
* an optional "Settings" and "Admin Console" link, and "Sign Out". This service has no local user directory (see
|
|
78
|
+
* `.claude/NOTES.md`), so the name and avatar come from auth-server, and the displayed name (and the initials badge)
|
|
79
|
+
* falls back down a chain: the profile's name (`GET /api/profiles/me`), else the caller's username - their first
|
|
80
|
+
* verified `name` alias (`GET /api/aliases?type=name`, asked for only when the profile gave no name) - else the bare
|
|
81
|
+
* uid. Either lookup can fail (auth-server's CORS list not including this origin, or no profile document at all - a
|
|
82
|
+
* 404 for some accounts) and neither ever surfaces as an error. The avatar image comes from the profile alone.
|
|
83
|
+
*/
|
|
84
|
+
export default function UserMenu({
|
|
85
|
+
userUid,
|
|
86
|
+
authServerUrl,
|
|
87
|
+
onSignOut,
|
|
88
|
+
showAdminLink,
|
|
89
|
+
detectAdmin,
|
|
90
|
+
trustedRoles = DEFAULT_TRUSTED_ROLES,
|
|
91
|
+
showSettingsLink,
|
|
92
|
+
showNotificationSettings,
|
|
93
|
+
onShowShortcuts,
|
|
94
|
+
}: UserMenuProps) {
|
|
95
|
+
const env = useKeyEnvironment();
|
|
96
|
+
const [open, setOpen] = useState(false);
|
|
97
|
+
const [detectedAdmin, setDetectedAdmin] = useState(false);
|
|
98
|
+
const [popups, setPopups] = useState(true);
|
|
99
|
+
const [permission, setPermission] = useState<DesktopPermission>("unsupported");
|
|
100
|
+
const [profile, setProfile] = useState<Profile | undefined>(undefined);
|
|
101
|
+
const [username, setUsername] = useState<string | undefined>(undefined);
|
|
102
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!authServerUrl) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
let cancelled = false;
|
|
109
|
+
void (async () => {
|
|
110
|
+
let loaded: Profile | undefined;
|
|
111
|
+
try {
|
|
112
|
+
loaded = await getMyProfile(authServerUrl);
|
|
113
|
+
} catch {
|
|
114
|
+
// Unreachable, blocked, or no profile document (404) - fall through to the username.
|
|
115
|
+
}
|
|
116
|
+
if (cancelled) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
setProfile(loaded);
|
|
120
|
+
// The username is only the fallback for a missing name - no second request when the profile has one.
|
|
121
|
+
if (!formatProfileName(loaded)) {
|
|
122
|
+
const alias = await getMyUsername(authServerUrl);
|
|
123
|
+
if (!cancelled) {
|
|
124
|
+
setUsername(alias);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
return () => {
|
|
129
|
+
cancelled = true;
|
|
130
|
+
};
|
|
131
|
+
}, [authServerUrl]);
|
|
132
|
+
|
|
133
|
+
// Keyed on the joined names, not the array: a caller's fresh `["admin"]` each render must not re-ask.
|
|
134
|
+
const trustedRolesKey = JSON.stringify(trustedRoles);
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (!detectAdmin || !authServerUrl || showAdminLink) {
|
|
137
|
+
setDetectedAdmin(false);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let cancelled = false;
|
|
141
|
+
void lookUpAdminAccess(authServerUrl, userUid, JSON.parse(trustedRolesKey) as string[]).then((admin) => {
|
|
142
|
+
if (!cancelled) {
|
|
143
|
+
setDetectedAdmin(admin === true);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return () => {
|
|
147
|
+
cancelled = true;
|
|
148
|
+
};
|
|
149
|
+
}, [detectAdmin, authServerUrl, userUid, showAdminLink, trustedRolesKey]);
|
|
150
|
+
|
|
151
|
+
// Read fresh each time the menu opens - another tab may have changed either since - and only on the client.
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (open && showNotificationSettings) {
|
|
154
|
+
setPopups(getNewMailPopupsEnabled());
|
|
155
|
+
setPermission(desktopPermission());
|
|
156
|
+
}
|
|
157
|
+
}, [open, showNotificationSettings]);
|
|
158
|
+
|
|
159
|
+
function togglePopups() {
|
|
160
|
+
setNewMailPopupsEnabled(!popups);
|
|
161
|
+
setPopups(!popups);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function enableDesktopNotifications() {
|
|
165
|
+
// Asked from this click, as browsers require; a "no" (or "yes") answers the first pop-up's offer as well.
|
|
166
|
+
setPermission(await requestDesktopPermission());
|
|
167
|
+
setDesktopOfferDismissed(true);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (!open) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
function handlePointerDown(e: MouseEvent) {
|
|
175
|
+
if (containerRef.current && e.target instanceof Node && !containerRef.current.contains(e.target)) {
|
|
176
|
+
setOpen(false);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
180
|
+
if (e.key === "Escape") {
|
|
181
|
+
setOpen(false);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
document.addEventListener("mousedown", handlePointerDown);
|
|
185
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
186
|
+
return () => {
|
|
187
|
+
document.removeEventListener("mousedown", handlePointerDown);
|
|
188
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
189
|
+
};
|
|
190
|
+
}, [open]);
|
|
191
|
+
|
|
192
|
+
const name = formatProfileName(profile) ?? username ?? userUid;
|
|
193
|
+
const initials = profileInitials(profile, userUid, username);
|
|
194
|
+
const accountUrl = accountUrlOf(authServerUrl);
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<div className="relative" ref={containerRef}>
|
|
198
|
+
<button
|
|
199
|
+
type="button"
|
|
200
|
+
onClick={() => setOpen((o) => !o)}
|
|
201
|
+
aria-haspopup="true"
|
|
202
|
+
aria-expanded={open}
|
|
203
|
+
aria-label="Account menu"
|
|
204
|
+
className="flex items-center gap-1.5 rounded-pill py-1 pl-1 pr-2 hover:bg-surface-alt"
|
|
205
|
+
>
|
|
206
|
+
<Avatar profile={profile} initials={initials} />
|
|
207
|
+
<svg
|
|
208
|
+
width="14"
|
|
209
|
+
height="14"
|
|
210
|
+
viewBox="0 0 20 20"
|
|
211
|
+
fill="none"
|
|
212
|
+
className={`text-text-muted transition-transform ${open ? "rotate-180" : ""}`}
|
|
213
|
+
aria-hidden="true"
|
|
214
|
+
>
|
|
215
|
+
<path d="M5 7.5L10 12.5L15 7.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
|
|
216
|
+
</svg>
|
|
217
|
+
</button>
|
|
218
|
+
{open && (
|
|
219
|
+
<div
|
|
220
|
+
role="menu"
|
|
221
|
+
className="absolute right-0 top-full mt-2 w-60 bg-surface border border-border rounded-md shadow-modal py-1.5 z-10"
|
|
222
|
+
>
|
|
223
|
+
<div className="flex items-center gap-3 px-3.5 py-2.5 border-b border-border">
|
|
224
|
+
<Avatar profile={profile} initials={initials} large />
|
|
225
|
+
<span className="text-sm font-semibold text-text truncate">{name}</span>
|
|
226
|
+
</div>
|
|
227
|
+
{accountUrl && (
|
|
228
|
+
<a
|
|
229
|
+
role="menuitem"
|
|
230
|
+
href={accountUrl}
|
|
231
|
+
className="block px-3.5 py-2 text-sm text-text hover:bg-surface-alt"
|
|
232
|
+
>
|
|
233
|
+
Account
|
|
234
|
+
</a>
|
|
235
|
+
)}
|
|
236
|
+
{showSettingsLink && (
|
|
237
|
+
<a
|
|
238
|
+
role="menuitem"
|
|
239
|
+
href={SETTINGS_HREF}
|
|
240
|
+
className="block px-3.5 py-2 text-sm text-text hover:bg-surface-alt"
|
|
241
|
+
>
|
|
242
|
+
Settings
|
|
243
|
+
</a>
|
|
244
|
+
)}
|
|
245
|
+
{showNotificationSettings && (
|
|
246
|
+
<button
|
|
247
|
+
role="menuitemcheckbox"
|
|
248
|
+
aria-checked={popups}
|
|
249
|
+
type="button"
|
|
250
|
+
onClick={togglePopups}
|
|
251
|
+
className="flex w-full items-center justify-between gap-2 px-3.5 py-2 text-left text-sm text-text hover:bg-surface-alt"
|
|
252
|
+
>
|
|
253
|
+
<span>New mail pop-ups</span>
|
|
254
|
+
<span className="text-xs font-semibold text-text-muted">{popups ? "On" : "Off"}</span>
|
|
255
|
+
</button>
|
|
256
|
+
)}
|
|
257
|
+
{showNotificationSettings && permission === "default" && (
|
|
258
|
+
<button
|
|
259
|
+
role="menuitem"
|
|
260
|
+
type="button"
|
|
261
|
+
onClick={() => void enableDesktopNotifications()}
|
|
262
|
+
className="block w-full px-3.5 py-2 text-left text-sm text-text hover:bg-surface-alt"
|
|
263
|
+
>
|
|
264
|
+
Turn on desktop notifications
|
|
265
|
+
</button>
|
|
266
|
+
)}
|
|
267
|
+
{onShowShortcuts && (
|
|
268
|
+
<button
|
|
269
|
+
role="menuitem"
|
|
270
|
+
type="button"
|
|
271
|
+
aria-keyshortcuts={ariaKeyShortcuts(SHORTCUTS.global.help, env)}
|
|
272
|
+
onClick={() => {
|
|
273
|
+
setOpen(false);
|
|
274
|
+
onShowShortcuts();
|
|
275
|
+
}}
|
|
276
|
+
className="block w-full px-3.5 py-2 text-left text-sm text-text hover:bg-surface-alt"
|
|
277
|
+
>
|
|
278
|
+
Keyboard shortcuts
|
|
279
|
+
</button>
|
|
280
|
+
)}
|
|
281
|
+
{(showAdminLink || detectedAdmin) && (
|
|
282
|
+
<a
|
|
283
|
+
role="menuitem"
|
|
284
|
+
href="/admin"
|
|
285
|
+
className="flex items-center gap-2 px-3.5 py-2 text-sm text-text hover:bg-surface-alt"
|
|
286
|
+
>
|
|
287
|
+
<HiOutlineShieldCheck size={16} aria-hidden="true" className="shrink-0 text-text-muted" />
|
|
288
|
+
Admin Console
|
|
289
|
+
</a>
|
|
290
|
+
)}
|
|
291
|
+
<button
|
|
292
|
+
role="menuitem"
|
|
293
|
+
type="button"
|
|
294
|
+
onClick={onSignOut}
|
|
295
|
+
className="block w-full text-left px-3.5 py-2 text-sm text-text hover:bg-surface-alt"
|
|
296
|
+
>
|
|
297
|
+
Sign Out
|
|
298
|
+
</button>
|
|
299
|
+
</div>
|
|
300
|
+
)}
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|