Apply shared UI and workflow fixes
Docker / Docker Build & Push (push) Successful in 8m26s
Lint / Lint (push) Failing after 20s
Tests / Go backend (push) Successful in 16s
Tests / Dashboard checks (push) Successful in 23s

This commit is contained in:
Gabriel20xx committed 2026-08-07 15:22:26 +02:00
1 parent fb22af5272
commit f208697859
15 files changed
+287 -62

No files matched your search

@@ -7,22 +7,37 @@
brand = 'Application',
children,
description = '',
icon,
links = [],
onClose,
open = $bindable(false),
version = ''
}: {
brand?: string;
children?: Snippet;
description?: string;
icon?: Snippet;
links?: AboutLink[];
onClose?: () => void | Promise<void>;
open?: boolean;
version?: string;
} = $props();
let wasOpen = false;
$effect(() => {
if (wasOpen && !open) void onClose?.();
wasOpen = open;
});
</script>
<Dialog bind:open title={`About ${brand}`}>
<div class="sc-auth-brand">
<span aria-hidden="true" class="sc-brand-mark">{brand.slice(0, 1).toUpperCase()}</span>
{#if icon}
{@render icon()}
{:else}
<span aria-hidden="true" class="sc-brand-mark">{brand.slice(0, 1).toUpperCase()}</span>
{/if}
<strong>{brand}</strong>
</div>
@@ -2,6 +2,7 @@
import type { Snippet } from 'svelte';
import type { NavItem } from '../types';
import Header from './Header.svelte';
import PageHeader from './PageHeader.svelte';
let {
brand = 'Application',
@@ -15,9 +16,10 @@
onNavigate,
onProfile,
onSettings,
showPageHeader = true,
showSettings = true,
theme = 'dark',
username = ''
username = '',
}: {
brand?: string;
brandHref?: string;
@@ -30,10 +32,17 @@
onNavigate?: (item: NavItem) => void;
onProfile?: () => void;
onSettings?: () => void;
showPageHeader?: boolean;
showSettings?: boolean;
theme?: 'dark' | 'light' | 'system';
username?: string;
} = $props();
const activeNavItem = $derived(
navItems.find((item) =>
item.href === '/' ? currentPath === '/' : currentPath === item.href || currentPath.startsWith(`${item.href}/`),
),
);
</script>
<div class={`sc-root sc-app-shell ${className}`} data-theme={theme === 'system' ? undefined : theme}>
@@ -52,6 +61,13 @@
/>
<main class="sc-main">
{#if showPageHeader && activeNavItem?.href !== '/about'}
<PageHeader
title={activeNavItem?.label ?? brand}
description={activeNavItem?.description ??
`Explore the ${activeNavItem?.label?.toLowerCase() ?? 'application'} section.`}
/>
{/if}
{@render children?.()}
</main>
</div>
@@ -39,6 +39,7 @@
let identifier = $state('');
let password = $state('');
let totpToken = $state('');
let totpRequired = $state(false);
let confirmPassword = $state('');
let submitError = $state('');
let submitting = $state(false);
@@ -47,6 +48,17 @@
let resetOpen = $state(false);
let resetting = $state(false);
function isTotpChallenge(caught: unknown): boolean {
if (!(caught instanceof Error)) return false;
const message = caught.message.toLowerCase();
return (
message.includes('two-factor authentication code required') ||
message.includes('multi-factor authentication code required') ||
(message.includes('totp') && message.includes('required')) ||
(message.includes('mfa') && message.includes('required'))
);
}
async function submit(event: SubmitEvent): Promise<void> {
event.preventDefault();
submitError = '';
@@ -64,10 +76,23 @@
await onSetup({ username, email, password });
} else {
if (!onLogin) throw new Error('The application has not configured its login handler.');
if (totpRequired && !totpToken.trim()) {
submitError = 'Enter the six-digit authenticator code to continue.';
return;
}
await onLogin({ identifier, password, totpToken: totpToken.trim() });
}
} catch (caught) {
submitError = caught instanceof Error ? caught.message : 'Authentication failed.';
if (!setupRequired && showTotp && isTotpChallenge(caught)) {
totpRequired = true;
submitError = 'Enter the six-digit authenticator code to continue.';
} else {
if (!setupRequired) {
totpRequired = false;
totpToken = '';
}
submitError = caught instanceof Error ? caught.message : 'Authentication failed.';
}
} finally {
submitting = false;
}
@@ -170,9 +195,9 @@
/>
</label>
{#if showTotp && !setupRequired}
{#if showTotp && !setupRequired && totpRequired}
<label class="sc-field">
<span class="sc-label">Authenticator code <span class="sc-label-optional">(if enabled)</span></span>
<span class="sc-label">Authenticator code</span>
<input
autocomplete="one-time-code"
class="sc-input"
@@ -1,7 +1,95 @@
<script lang="ts">
import {
Activity,
Archive,
BarChart3,
Bot,
Box,
CircleAlert,
CircleHelp,
CircleUserRound,
CloudDownload,
Database,
FileCog,
FolderOpen,
Gamepad2,
GalleryHorizontalEnd,
HardDrive,
Image,
Info,
LayoutDashboard,
ListVideo,
Logs,
Magnet,
Map,
MapPinned,
MessageCircle,
MonitorPlay,
Play,
Plug,
RefreshCw,
ScanSearch,
ScrollText,
Send,
Server,
Settings2,
ShieldCheck,
SlidersHorizontal,
Sparkles,
Tags,
Upload,
Users,
WandSparkles,
Workflow,
Wrench,
} from '@lucide/svelte';
import type { Snippet } from 'svelte';
import type { NavItem } from '../types';
const icons: Record<string, typeof LayoutDashboard> = {
activity: Activity,
archive: Archive,
'bar-chart-3': BarChart3,
bot: Bot,
box: Box,
'circle-alert': CircleAlert,
'circle-help': CircleHelp,
'cloud-download': CloudDownload,
database: Database,
'file-cog': FileCog,
'folder-open': FolderOpen,
gamepad: Gamepad2,
'gallery-horizontal-end': GalleryHorizontalEnd,
'hard-drive': HardDrive,
image: Image,
info: Info,
'layout-dashboard': LayoutDashboard,
'list-video': ListVideo,
logs: Logs,
magnet: Magnet,
map: Map,
'map-pinned': MapPinned,
'message-circle': MessageCircle,
'monitor-play': MonitorPlay,
play: Play,
plug: Plug,
'refresh-cw': RefreshCw,
'scan-search': ScanSearch,
'scroll-text': ScrollText,
send: Send,
server: Server,
'settings-2': Settings2,
'shield-check': ShieldCheck,
'sliders-horizontal': SlidersHorizontal,
sparkles: Sparkles,
tags: Tags,
upload: Upload,
users: Users,
'wand-sparkles': WandSparkles,
workflow: Workflow,
wrench: Wrench,
};
let {
brand = 'Application',
brandHref = '/',
@@ -30,6 +118,10 @@
let navOpen = $state(false);
function iconFor(item: NavItem) {
return icons[item.icon ?? 'layout-dashboard'] ?? LayoutDashboard;
}
function isActive(item: NavItem): boolean {
return item.href === '/'
? currentPath === '/'
@@ -45,6 +137,7 @@
<nav aria-label="Primary navigation" class="sc-nav" data-open={navOpen}>
{#each navItems as item}
{@const Icon = iconFor(item)}
<a
aria-current={isActive(item) ? 'page' : undefined}
class="sc-nav-link"
@@ -58,6 +151,7 @@
navOpen = false;
}}
>
<Icon aria-hidden="true" class="sc-nav-icon" size={16} strokeWidth={2} />
{item.label}
</a>
{/each}
@@ -71,7 +165,10 @@
{/if}
{#if username && onProfile}
<button class="sc-profile-button" type="button" onclick={onProfile}>{username}</button>
<button class="sc-profile-button" type="button" onclick={onProfile}>
<CircleUserRound aria-hidden="true" class="sc-profile-icon" size={16} strokeWidth={2} />
<span>{username}</span>
</button>
{/if}
{#if onLogout}
@@ -16,8 +16,10 @@
description = '',
currentRole = 'user',
currentUserId,
loginRequired = true,
onCreateUser,
onDeleteUser,
onLoginRequiredChange,
onListUsers,
onUpdateUser,
open = $bindable(false),
@@ -27,16 +29,54 @@
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}
+35 -10
View File
@@ -1,4 +1,4 @@
@import '../../../design-tokens/theme.css';
@import "../../../design-tokens/theme.css";
:where(.sc-root, .sc-root *) {
box-sizing: border-box;
@@ -85,7 +85,17 @@
.sc-icon-button {
border: 1px solid transparent;
border-radius: var(--sc-radius-md);
transition: color 140ms ease, background 140ms ease, border-color 140ms ease;
transition:
color 140ms ease,
background 140ms ease,
border-color 140ms ease;
}
.sc-nav-link,
.sc-profile-button {
display: inline-flex;
align-items: center;
gap: 0.4rem;
}
.sc-nav-link {
@@ -96,7 +106,7 @@
}
.sc-nav-link:hover,
.sc-nav-link[data-active='true'] {
.sc-nav-link[data-active="true"] {
color: var(--sc-fg);
background: var(--sc-surface-hover);
border-color: var(--sc-border);
@@ -146,6 +156,11 @@
justify-content: space-between;
gap: 1rem;
margin-bottom: 1.5rem;
padding: 1rem 1.25rem;
background: var(--sc-surface);
border: 1px solid var(--sc-border);
border-radius: var(--sc-radius-lg);
box-shadow: var(--sc-shadow-sm);
}
.sc-page-header h1,
@@ -209,19 +224,19 @@
font-weight: 650;
}
.sc-badge[data-variant='success'] {
.sc-badge[data-variant="success"] {
color: var(--sc-success-fg);
background: var(--sc-success);
border-color: transparent;
}
.sc-badge[data-variant='warning'] {
.sc-badge[data-variant="warning"] {
color: var(--sc-warning-fg);
background: var(--sc-warning);
border-color: transparent;
}
.sc-badge[data-variant='danger'] {
.sc-badge[data-variant="danger"] {
color: var(--sc-danger-fg);
background: var(--sc-danger);
border-color: transparent;
@@ -240,7 +255,11 @@
font-weight: 650;
line-height: 1;
cursor: pointer;
transition: color 140ms ease, background 140ms ease, border-color 140ms ease, opacity 140ms ease;
transition:
color 140ms ease,
background 140ms ease,
border-color 140ms ease,
opacity 140ms ease;
}
.sc-button:hover:not(:disabled) {
@@ -406,7 +425,9 @@
border: 1px solid var(--sc-border);
border-radius: var(--sc-radius-md);
outline: none;
transition: border-color 140ms ease, box-shadow 140ms ease;
transition:
border-color 140ms ease,
box-shadow 140ms ease;
}
.sc-textarea {
@@ -558,7 +579,11 @@
padding: 1.5rem;
color: var(--sc-fg);
background:
radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--sc-primary) 18%, transparent), transparent 35%),
radial-gradient(
circle at 15% 10%,
color-mix(in srgb, var(--sc-primary) 18%, transparent),
transparent 35%
),
var(--sc-bg);
}
@@ -744,7 +769,7 @@
padding-bottom: 0.25rem;
}
.sc-nav[data-open='true'] {
.sc-nav[data-open="true"] {
display: flex;
}
+13 -5
View File
@@ -1,10 +1,12 @@
import type { Snippet } from 'svelte';
import type { Snippet } from "svelte";
export type AsyncAction<T = void> = (value: T) => void | Promise<void>;
export interface NavItem {
href: string;
label: string;
icon?: string;
description?: string;
}
export interface AuthSetupInput {
@@ -27,7 +29,8 @@ export interface TotpSetupResponse {
export type TotpStatusRequest = () => boolean | Promise<boolean>;
export type TotpSetupRequest = () => TotpSetupResponse | Promise<TotpSetupResponse>;
export type TotpSetupRequest = () =>
TotpSetupResponse | Promise<TotpSetupResponse>;
export type TotpTokenAction = (token: string) => void | Promise<void>;
@@ -41,7 +44,7 @@ export interface ProfileUpdateInput {
password?: string;
}
export type UserRole = 'superadmin' | 'admin' | 'user';
export type UserRole = "superadmin" | "admin" | "user";
export type UserId = string | number;
@@ -71,9 +74,14 @@ export interface UserUpdateInput {
export type UserListRequest = () => ManagedUser[] | Promise<ManagedUser[]>;
export type UserCreateRequest = (input: UserCreateInput) => void | Promise<void | ManagedUser>;
export type UserCreateRequest = (
input: UserCreateInput,
) => void | Promise<void | ManagedUser>;
export type UserUpdateRequest = (id: UserId, input: UserUpdateInput) => void | Promise<void | ManagedUser>;
export type UserUpdateRequest = (
id: UserId,
input: UserUpdateInput,
) => void | Promise<void | ManagedUser>;
export type UserDeleteRequest = (id: UserId) => void | Promise<void>;