feat: add admin dialog and move user management out of settings/profile modals
- Sync shared web-ui AdminDialog and header/profile/settings dialog updates - Add a dedicated admin entry to the header profile dropdown, admin-only - Move user-management settings from SettingsDialog/ProfileDialog into AdminDialog Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f1b52a4fa6
commit
395b7d0e79
8 files changed
+180
-185
No files matched your search
@@ -1,6 +1,6 @@
|
||||
<script>
|
||||
import { page } from '$app/state';
|
||||
import { AppShell as SharedAppShell, ProfileDialog } from '@gabriel20xx/web-ui';
|
||||
import { AdminDialog, AppShell as SharedAppShell, ProfileDialog } from '@gabriel20xx/web-ui';
|
||||
import { Tooltip } from 'bits-ui';
|
||||
import AuthPage from '$lib/features/auth/AuthPage.svelte';
|
||||
import { createAuthStore } from '$lib/features/auth/auth.svelte.js';
|
||||
@@ -9,11 +9,23 @@
|
||||
let { children } = $props();
|
||||
const auth = createAuthStore();
|
||||
const navItems = [
|
||||
{ href: '/', label: 'Overview', icon: 'layout-dashboard', description: 'Browse shared tables and collaborate on structured data.' },
|
||||
{ href: '/about', label: 'About', icon: 'info', description: 'Learn about CollabTable and its collaboration features.' },
|
||||
{
|
||||
href: '/',
|
||||
label: 'Overview',
|
||||
icon: 'layout-dashboard',
|
||||
description: 'Browse shared tables and collaborate on structured data.',
|
||||
},
|
||||
{
|
||||
href: '/about',
|
||||
label: 'About',
|
||||
icon: 'info',
|
||||
description: 'Learn about CollabTable and its collaboration features.',
|
||||
},
|
||||
];
|
||||
let settingsOpen = $state(false);
|
||||
let credentialsOpen = $state(false);
|
||||
let adminOpen = $state(false);
|
||||
const isAdmin = $derived(auth.status?.role === 'admin' || auth.status?.role === 'superadmin');
|
||||
|
||||
async function saveProfile(input) {
|
||||
await auth.updateCredentials({
|
||||
@@ -44,6 +56,7 @@
|
||||
username={auth.status.username ?? ''}
|
||||
onLogout={() => auth.logout()}
|
||||
onProfile={() => (credentialsOpen = true)}
|
||||
onAdmin={isAdmin ? () => (adminOpen = true) : undefined}
|
||||
onSettings={() => (settingsOpen = true)}
|
||||
>
|
||||
{@render children?.()}
|
||||
@@ -51,8 +64,9 @@
|
||||
{/if}
|
||||
</Tooltip.Provider>
|
||||
|
||||
<SettingsDialog
|
||||
bind:open={settingsOpen}
|
||||
<SettingsDialog bind:open={settingsOpen} />
|
||||
<AdminDialog
|
||||
bind:open={adminOpen}
|
||||
currentRole={auth.status?.role ?? 'user'}
|
||||
currentUserId={auth.status?.id}
|
||||
onCreateUser={(input) => auth.createUser(input)}
|
||||
@@ -64,13 +78,7 @@
|
||||
bind:open={credentialsOpen}
|
||||
currentUsername={auth.status?.username ?? ''}
|
||||
currentEmail={auth.status?.email ?? ''}
|
||||
currentRole={auth.status?.role ?? 'user'}
|
||||
currentUserId={auth.status?.id}
|
||||
onCreateUser={(input) => auth.createUser(input)}
|
||||
onDeleteUser={(id) => auth.deleteUser(id)}
|
||||
onListUsers={() => auth.listUsers()}
|
||||
onSave={saveProfile}
|
||||
onUpdateUser={(id, input) => auth.updateUser(id, input)}
|
||||
onTotpStatus={() => auth.totpStatus()}
|
||||
onTotpSetup={() => auth.setupTotp()}
|
||||
onTotpEnable={(token) => auth.enableTotp(token)}
|
||||
|
||||
@@ -6,82 +6,60 @@
|
||||
import { currentLanguage, languages, setLanguage } from '$lib/language.svelte.js';
|
||||
import { themeState } from '$lib/theme.svelte.js';
|
||||
|
||||
let {
|
||||
currentRole = 'user',
|
||||
currentUserId,
|
||||
onCreateUser,
|
||||
onDeleteUser,
|
||||
onListUsers,
|
||||
onUpdateUser,
|
||||
open = $bindable(false)
|
||||
} = $props();
|
||||
let { open = $bindable(false) } = $props();
|
||||
|
||||
const languageItems = languages.map((language) => ({ value: language.id, label: language.label }));
|
||||
</script>
|
||||
|
||||
<SharedSettingsDialog
|
||||
bind:open
|
||||
currentRole={currentRole}
|
||||
currentUserId={currentUserId}
|
||||
onCreateUser={onCreateUser}
|
||||
onDeleteUser={onDeleteUser}
|
||||
onListUsers={onListUsers}
|
||||
onUpdateUser={onUpdateUser}
|
||||
title="Settings"
|
||||
>
|
||||
<div>
|
||||
<span class="mb-2 block text-sm font-medium">Theme</span>
|
||||
<div class="flex w-full rounded-md border border-border p-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'light' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('light')}
|
||||
>
|
||||
<Sun class="size-4" />
|
||||
Light
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'dark' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('dark')}
|
||||
>
|
||||
<Moon class="size-4" />
|
||||
Dark
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'system' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('system')}
|
||||
>
|
||||
<SunMoon class="size-4" />
|
||||
System
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<label for="settings-language" class="mb-2 block text-sm font-medium">Language</label>
|
||||
<Select
|
||||
type="single"
|
||||
value={currentLanguage()}
|
||||
items={languageItems}
|
||||
onValueChange={(value) => setLanguage(value)}
|
||||
<SharedSettingsDialog bind:open title="Settings">
|
||||
<div>
|
||||
<span class="mb-2 block text-sm font-medium">Theme</span>
|
||||
<div class="flex w-full rounded-md border border-border p-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'light' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('light')}
|
||||
>
|
||||
<SelectTrigger id="settings-language" class="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{#each languageItems as item (item.value)}
|
||||
<SelectItem value={item.value} label={item.label}>{item.label}</SelectItem>
|
||||
{/each}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Sun class="size-4" />
|
||||
Light
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'dark' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('dark')}
|
||||
>
|
||||
<Moon class="size-4" />
|
||||
Dark
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'system' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('system')}
|
||||
>
|
||||
<SunMoon class="size-4" />
|
||||
System
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<label for="settings-language" class="mb-2 block text-sm font-medium">Language</label>
|
||||
<Select type="single" value={currentLanguage()} items={languageItems} onValueChange={(value) => setLanguage(value)}>
|
||||
<SelectTrigger id="settings-language" class="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{#each languageItems as item (item.value)}
|
||||
<SelectItem value={item.value} label={item.label}>{item.label}</SelectItem>
|
||||
{/each}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div class="sc-form-actions">
|
||||
<Button type="button" variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<script lang="ts">
|
||||
import type {
|
||||
UserCreateRequest,
|
||||
UserDeleteRequest,
|
||||
UserId,
|
||||
UserListRequest,
|
||||
UserRole,
|
||||
UserUpdateRequest
|
||||
} from '../types';
|
||||
import Dialog from './Dialog.svelte';
|
||||
import UserManagement from './UserManagement.svelte';
|
||||
|
||||
let {
|
||||
currentRole = 'user',
|
||||
currentUserId,
|
||||
description = 'Manage accounts and access for this application.',
|
||||
loginRequired = true,
|
||||
onCreateUser,
|
||||
onDeleteUser,
|
||||
onLoginRequiredChange,
|
||||
onListUsers,
|
||||
onUpdateUser,
|
||||
open = $bindable(false),
|
||||
title = 'Admin'
|
||||
}: {
|
||||
currentRole?: UserRole;
|
||||
currentUserId?: UserId;
|
||||
description?: string;
|
||||
loginRequired?: boolean;
|
||||
onCreateUser?: UserCreateRequest;
|
||||
onDeleteUser?: UserDeleteRequest;
|
||||
onLoginRequiredChange?: (required: boolean) => void | Promise<void>;
|
||||
onListUsers?: UserListRequest;
|
||||
onUpdateUser?: UserUpdateRequest;
|
||||
open?: boolean;
|
||||
title?: string;
|
||||
} = $props();
|
||||
|
||||
let loginRequiredValue = $state<boolean>(true);
|
||||
let loginSettingError = $state('');
|
||||
|
||||
$effect(() => {
|
||||
loginRequiredValue = loginRequired;
|
||||
});
|
||||
|
||||
async function updateLoginRequired(required: boolean) {
|
||||
const previous = loginRequiredValue;
|
||||
loginRequiredValue = required;
|
||||
loginSettingError = '';
|
||||
try {
|
||||
await onLoginRequiredChange?.(required);
|
||||
} catch (error) {
|
||||
loginRequiredValue = previous;
|
||||
loginSettingError = error instanceof Error ? error.message : 'The setting could not be saved.';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog bind:open {description} {title}>
|
||||
{#if onLoginRequiredChange}
|
||||
<div class="sc-field">
|
||||
<label class="flex items-center gap-3">
|
||||
<input
|
||||
class="size-4 accent-primary"
|
||||
type="checkbox"
|
||||
checked={loginRequiredValue}
|
||||
onchange={(event) => updateLoginRequired((event.currentTarget as HTMLInputElement).checked)}
|
||||
/>
|
||||
<span>
|
||||
<span class="block font-medium">Require login to access app</span>
|
||||
<span class="sc-muted">Admins and superadmins can change this setting.</span>
|
||||
</span>
|
||||
</label>
|
||||
{#if loginSettingError}<p class="sc-error" role="alert">{loginSettingError}</p>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<UserManagement
|
||||
currentRole={currentRole}
|
||||
currentUserId={currentUserId}
|
||||
onCreate={onCreateUser}
|
||||
onDelete={onDeleteUser}
|
||||
onList={onListUsers}
|
||||
onUpdate={onUpdateUser}
|
||||
/>
|
||||
</Dialog>
|
||||
@@ -15,6 +15,7 @@
|
||||
headerActions,
|
||||
navItems = [],
|
||||
onAbout,
|
||||
onAdmin,
|
||||
onLogout,
|
||||
onNavigate,
|
||||
onProfile,
|
||||
@@ -34,6 +35,7 @@
|
||||
headerActions?: Snippet;
|
||||
navItems?: NavItem[];
|
||||
onAbout?: () => void | Promise<void>;
|
||||
onAdmin?: () => void | Promise<void>;
|
||||
onLogout?: () => void | Promise<void>;
|
||||
onNavigate?: (item: NavItem) => void;
|
||||
onProfile?: () => void;
|
||||
@@ -61,6 +63,7 @@
|
||||
actions={headerActions}
|
||||
{navItems}
|
||||
{onAbout}
|
||||
{onAdmin}
|
||||
{onLogout}
|
||||
{onNavigate}
|
||||
{onProfile}
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
navItems = [],
|
||||
actions,
|
||||
onAbout,
|
||||
onAdmin,
|
||||
onLogout,
|
||||
onNavigate,
|
||||
onProfile,
|
||||
@@ -115,6 +116,7 @@
|
||||
navItems?: NavItem[];
|
||||
actions?: Snippet;
|
||||
onAbout?: () => void | Promise<void>;
|
||||
onAdmin?: () => void | Promise<void>;
|
||||
onLogout?: () => void | Promise<void>;
|
||||
onNavigate?: (item: NavItem) => void;
|
||||
onProfile?: () => void | Promise<void>;
|
||||
@@ -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 @@
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#if onAdmin}
|
||||
<button
|
||||
class="sc-profile-menu-item"
|
||||
role="menuitem"
|
||||
type="button"
|
||||
onclick={() => {
|
||||
profileOpen = false;
|
||||
void onAdmin?.();
|
||||
}}
|
||||
>
|
||||
<ShieldCheck aria-hidden="true" size={15} strokeWidth={2} />
|
||||
Admin
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#if showSettings && onSettings}
|
||||
<button
|
||||
class="sc-profile-menu-item"
|
||||
|
||||
@@ -1,51 +1,27 @@
|
||||
<script lang="ts">
|
||||
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<void>;
|
||||
onTotpDisable?: TotpTokenAction;
|
||||
onTotpEnable?: TotpTokenAction;
|
||||
onTotpSetup?: TotpSetupRequest;
|
||||
onTotpStatus?: TotpStatusRequest;
|
||||
onUpdateUser?: UserUpdateRequest;
|
||||
totpEnabled?: boolean;
|
||||
open?: boolean;
|
||||
} = $props();
|
||||
@@ -158,13 +134,4 @@
|
||||
enabled={totpEnabled}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<UserManagement
|
||||
currentRole={currentRole}
|
||||
currentUserId={currentUserId}
|
||||
onCreate={onCreateUser}
|
||||
onDelete={onDeleteUser}
|
||||
onList={onListUsers}
|
||||
onUpdate={onUpdateUser}
|
||||
/>
|
||||
</Dialog>
|
||||
@@ -1,93 +1,24 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
import type {
|
||||
UserCreateRequest,
|
||||
UserDeleteRequest,
|
||||
UserId,
|
||||
UserListRequest,
|
||||
UserRole,
|
||||
UserUpdateRequest
|
||||
} from '../types';
|
||||
import Dialog from './Dialog.svelte';
|
||||
import UserManagement from './UserManagement.svelte';
|
||||
|
||||
let {
|
||||
children,
|
||||
description = '',
|
||||
currentRole = 'user',
|
||||
currentUserId,
|
||||
loginRequired = true,
|
||||
onCreateUser,
|
||||
onDeleteUser,
|
||||
onLoginRequiredChange,
|
||||
onListUsers,
|
||||
onUpdateUser,
|
||||
open = $bindable(false),
|
||||
title = 'Settings'
|
||||
}: {
|
||||
children?: Snippet;
|
||||
description?: string;
|
||||
currentRole?: UserRole;
|
||||
currentUserId?: UserId;
|
||||
loginRequired?: boolean;
|
||||
onCreateUser?: UserCreateRequest;
|
||||
onDeleteUser?: UserDeleteRequest;
|
||||
onLoginRequiredChange?: (required: boolean) => void | Promise<void>;
|
||||
onListUsers?: UserListRequest;
|
||||
onUpdateUser?: UserUpdateRequest;
|
||||
open?: boolean;
|
||||
title?: string;
|
||||
} = $props();
|
||||
|
||||
let loginRequiredValue = $state<boolean>(true);
|
||||
let loginSettingError = $state('');
|
||||
|
||||
$effect(() => {
|
||||
loginRequiredValue = loginRequired;
|
||||
});
|
||||
|
||||
async function updateLoginRequired(required: boolean) {
|
||||
const previous = loginRequiredValue;
|
||||
loginRequiredValue = required;
|
||||
loginSettingError = '';
|
||||
try {
|
||||
await onLoginRequiredChange?.(required);
|
||||
} catch (error) {
|
||||
loginRequiredValue = previous;
|
||||
loginSettingError = error instanceof Error ? error.message : 'The setting could not be saved.';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog bind:open {description} {title}>
|
||||
{#if currentRole === 'admin' || currentRole === 'superadmin'}
|
||||
<div class="sc-field">
|
||||
<label class="flex items-center gap-3">
|
||||
<input
|
||||
class="size-4 accent-primary"
|
||||
type="checkbox"
|
||||
checked={loginRequiredValue}
|
||||
onchange={(event) => updateLoginRequired((event.currentTarget as HTMLInputElement).checked)}
|
||||
/>
|
||||
<span>
|
||||
<span class="block font-medium">Require login to access app</span>
|
||||
<span class="sc-muted">Admins and superadmins can change this setting.</span>
|
||||
</span>
|
||||
</label>
|
||||
{#if loginSettingError}<p class="sc-error" role="alert">{loginSettingError}</p>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if children}
|
||||
{@render children()}
|
||||
{:else}
|
||||
<p class="sc-muted">No settings have been configured for this application yet.</p>
|
||||
{/if}
|
||||
<UserManagement
|
||||
currentRole={currentRole}
|
||||
currentUserId={currentUserId}
|
||||
onCreate={onCreateUser}
|
||||
onDelete={onDeleteUser}
|
||||
onList={onListUsers}
|
||||
onUpdate={onUpdateUser}
|
||||
/>
|
||||
</Dialog>
|
||||
@@ -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';
|
||||
|
||||
Reference in new issue
Block a user