Sync shared snapshot from 07cf330
This commit is contained in:
1 parent
cd0db77208
commit
557a61b4ee
5 files changed
+4
-167
No files matched your search
@@ -1,86 +0,0 @@
|
||||
<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>
|
||||
@@ -16,7 +16,6 @@
|
||||
headerActions,
|
||||
navItems = [],
|
||||
onAbout,
|
||||
onAdmin,
|
||||
onLogout,
|
||||
onNavigate,
|
||||
onProfile,
|
||||
@@ -37,7 +36,6 @@
|
||||
headerActions?: Snippet;
|
||||
navItems?: NavItem[];
|
||||
onAbout?: () => void | Promise<void>;
|
||||
onAdmin?: () => void | Promise<void>;
|
||||
onLogout?: () => void | Promise<void>;
|
||||
onNavigate?: (item: NavItem) => void;
|
||||
onProfile?: () => void;
|
||||
@@ -68,7 +66,6 @@
|
||||
actions={headerActions}
|
||||
{navItems}
|
||||
{onAbout}
|
||||
{onAdmin}
|
||||
{onLogout}
|
||||
{onNavigate}
|
||||
{onProfile}
|
||||
|
||||
@@ -100,7 +100,6 @@
|
||||
navItems = [],
|
||||
actions,
|
||||
onAbout,
|
||||
onAdmin,
|
||||
onLogout,
|
||||
onNavigate,
|
||||
onProfile,
|
||||
@@ -116,7 +115,6 @@
|
||||
navItems?: NavItem[];
|
||||
actions?: Snippet;
|
||||
onAbout?: () => void | Promise<void>;
|
||||
onAdmin?: () => void | Promise<void>;
|
||||
onLogout?: () => void | Promise<void>;
|
||||
onNavigate?: (item: NavItem) => void;
|
||||
onProfile?: () => void | Promise<void>;
|
||||
@@ -128,12 +126,8 @@
|
||||
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 || onAdmin || (showSettings && onSettings) || onAbout || aboutHref || onLogout),
|
||||
),
|
||||
Boolean(username && (onProfile || (showSettings && onSettings) || onAbout || aboutHref || onLogout)),
|
||||
);
|
||||
|
||||
function closeMenus(): void {
|
||||
@@ -225,21 +219,6 @@
|
||||
</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"
|
||||
|
||||
Reference in new issue
Block a user