diff --git a/packages/web-ui/src/lib/components/AdminDialog.svelte b/packages/web-ui/src/lib/components/AdminDialog.svelte new file mode 100644 index 0000000..be27a10 --- /dev/null +++ b/packages/web-ui/src/lib/components/AdminDialog.svelte @@ -0,0 +1,86 @@ + + + + {#if onLoginRequiredChange} + + + updateLoginRequired((event.currentTarget as HTMLInputElement).checked)} + /> + + Require login to access app + Admins and superadmins can change this setting. + + + {#if loginSettingError}{loginSettingError}{/if} + + {/if} + + + diff --git a/packages/web-ui/src/lib/components/AppShell.svelte b/packages/web-ui/src/lib/components/AppShell.svelte index 204b5be..64ae198 100644 --- a/packages/web-ui/src/lib/components/AppShell.svelte +++ b/packages/web-ui/src/lib/components/AppShell.svelte @@ -15,6 +15,7 @@ headerActions, navItems = [], onAbout, + onAdmin, onLogout, onNavigate, onProfile, @@ -34,6 +35,7 @@ headerActions?: Snippet; navItems?: NavItem[]; onAbout?: () => void | Promise; + onAdmin?: () => void | Promise; onLogout?: () => void | Promise; onNavigate?: (item: NavItem) => void; onProfile?: () => void; @@ -61,6 +63,7 @@ actions={headerActions} {navItems} {onAbout} + {onAdmin} {onLogout} {onNavigate} {onProfile} diff --git a/packages/web-ui/src/lib/components/Header.svelte b/packages/web-ui/src/lib/components/Header.svelte index 03c3f6c..d97db48 100644 --- a/packages/web-ui/src/lib/components/Header.svelte +++ b/packages/web-ui/src/lib/components/Header.svelte @@ -100,6 +100,7 @@ navItems = [], actions, onAbout, + onAdmin, onLogout, onNavigate, onProfile, @@ -115,6 +116,7 @@ navItems?: NavItem[]; actions?: Snippet; onAbout?: () => void | Promise; + onAdmin?: () => void | Promise; onLogout?: () => void | Promise; onNavigate?: (item: NavItem) => void; onProfile?: () => void | Promise; @@ -126,8 +128,12 @@ let navOpen = $state(false); let profileOpen = $state(false); + // onAdmin is only ever passed by the caller when the signed-in user's role qualifies, so its + // presence alone is enough to decide visibility here - same as onProfile/onLogout below. const hasProfileMenu = $derived( - Boolean(username && (onProfile || (showSettings && onSettings) || onAbout || aboutHref || onLogout)), + Boolean( + username && (onProfile || onAdmin || (showSettings && onSettings) || onAbout || aboutHref || onLogout), + ), ); function closeMenus(): void { @@ -219,6 +225,21 @@ {/if} + {#if onAdmin} + { + profileOpen = false; + void onAdmin?.(); + }} + > + + Admin + + {/if} + {#if showSettings && onSettings} - import type { - ProfileUpdateInput, - TotpSetupRequest, - TotpStatusRequest, - TotpTokenAction, - UserCreateRequest, - UserDeleteRequest, - UserId, - UserListRequest, - UserRole, - UserUpdateRequest - } from '../types'; + import type { ProfileUpdateInput, TotpSetupRequest, TotpStatusRequest, TotpTokenAction } from '../types'; import Button from './Button.svelte'; import Dialog from './Dialog.svelte'; import TotpSettings from './TotpSettings.svelte'; - import UserManagement from './UserManagement.svelte'; let { currentEmail = '', - currentRole = 'user', - currentUserId, - onCreateUser, - onDeleteUser, - onListUsers, currentUsername = '', onSave, onTotpDisable, onTotpEnable, onTotpSetup, onTotpStatus, - onUpdateUser, totpEnabled = false, open = $bindable(false) }: { currentEmail?: string; - currentRole?: UserRole; - currentUserId?: UserId; - onCreateUser?: UserCreateRequest; - onDeleteUser?: UserDeleteRequest; - onListUsers?: UserListRequest; currentUsername?: string; onSave?: (input: ProfileUpdateInput) => void | Promise; onTotpDisable?: TotpTokenAction; onTotpEnable?: TotpTokenAction; onTotpSetup?: TotpSetupRequest; onTotpStatus?: TotpStatusRequest; - onUpdateUser?: UserUpdateRequest; totpEnabled?: boolean; open?: boolean; } = $props(); @@ -158,13 +134,4 @@ enabled={totpEnabled} /> {/if} - - diff --git a/packages/web-ui/src/lib/components/SettingsDialog.svelte b/packages/web-ui/src/lib/components/SettingsDialog.svelte index 8e23ea8..23c348f 100644 --- a/packages/web-ui/src/lib/components/SettingsDialog.svelte +++ b/packages/web-ui/src/lib/components/SettingsDialog.svelte @@ -1,93 +1,24 @@ - {#if currentRole === 'admin' || currentRole === 'superadmin'} - - - updateLoginRequired((event.currentTarget as HTMLInputElement).checked)} - /> - - Require login to access app - Admins and superadmins can change this setting. - - - {#if loginSettingError}{loginSettingError}{/if} - - {/if} {#if children} {@render children()} {:else} No settings have been configured for this application yet. {/if} - diff --git a/packages/web-ui/src/lib/index.ts b/packages/web-ui/src/lib/index.ts index 2af9c49..f7358cc 100644 --- a/packages/web-ui/src/lib/index.ts +++ b/packages/web-ui/src/lib/index.ts @@ -1,4 +1,5 @@ export { default as AboutDialog } from './components/AboutDialog.svelte'; +export { default as AdminDialog } from './components/AdminDialog.svelte'; export { default as AppShell } from './components/AppShell.svelte'; export { default as AuthPage } from './components/AuthPage.svelte'; export { default as Badge } from './components/Badge.svelte';
{loginSettingError}
No settings have been configured for this application yet.