feat(settings,admin): every tab and popup in the planner's design

This commit is contained in:
Maurice
2026-10-01 16:00:37 +02:00
parent 4bc7c5cf68
commit 788a58679e
75 changed files with 8134 additions and 8023 deletions
@@ -1,37 +1,65 @@
import React, { useEffect, useRef, useState } from 'react'
import { BellRing, Loader2 } from 'lucide-react'
import { adminApi } from '../../api/client'
import { useToast } from '../../components/shared/Toast'
import ToggleSwitch from '../../components/Settings/ToggleSwitch'
import { SettingsCard, SettingsHint } from '../../components/Settings/settingsKit'
import { fs } from '../../components/shared/DialogShell'
import { ADMIN_EVENT_LABEL_KEYS, ADMIN_CHANNEL_LABEL_KEYS } from './AdminPage.constants'
type Preferences = Record<string, Record<string, boolean>>
interface AdminPreferenceMatrix {
event_types: string[]
channels?: { id: string; active: boolean }[]
implemented_combos: Record<string, string[] | undefined>
preferences: Preferences
}
const EYEBROW = 'text-center font-geist font-bold uppercase tracking-[.08em] text-content-faint'
// Per-event × per-channel admin notification preference matrix.
// Loads its own data and auto-saves each toggle. Markup identical to AdminPage.
// Loads its own data and auto-saves each toggle.
export default function AdminNotificationsPanel({ t, toast }: { t: (k: string) => string; toast: ReturnType<typeof useToast> }) {
const [matrix, setMatrix] = useState<any>(null)
const [matrix, setMatrix] = useState<AdminPreferenceMatrix | null>(null)
const [saving, setSaving] = useState(false)
// Toggles fire faster than React re-renders, so the live preferences are mirrored in a
// ref. Reading state out of the render closure would let a second toggle undo the first.
const prefsRef = useRef<any>(null)
const prefsRef = useRef<Preferences | null>(null)
const writePrefs = (prefs: any) => {
const writePrefs = (prefs: Preferences) => {
prefsRef.current = prefs
setMatrix((m: any) => m ? { ...m, preferences: prefs } : m)
setMatrix(m => m ? { ...m, preferences: prefs } : m)
}
useEffect(() => {
adminApi.getNotificationPreferences().then((data: any) => {
adminApi.getNotificationPreferences().then((data: AdminPreferenceMatrix) => {
prefsRef.current = data.preferences
setMatrix(data)
}).catch(() => {})
}, [])
if (!matrix) return <p className="text-content-faint" style={{ fontSize: 'calc(12px * var(--fs-scale-body, 1))', fontStyle: 'italic', padding: 16 }}>Loading…</p>
const card = (children: React.ReactNode) => (
<SettingsCard icon={BellRing} title={t('admin.tabs.notifications')} hint={t('admin.notifications.adminNotificationsHint')}>
{children}
</SettingsCard>
)
if (!matrix) {
return card(
<div className="flex items-center gap-2 text-content-faint" style={fs(12, 'body')}>
<Loader2 size={14} className="animate-spin" />
<span>Loading…</span>
</div>,
)
}
// Admin-scoped events only ever go out over the built-in channels (plugin channels
// are user-scoped), so this list stays explicit rather than server-driven.
const isActive = (id: string) => matrix.channels?.some((c: { id: string; active: boolean }) => c.id === id && c.active) ?? false
const isActive = (id: string) => matrix.channels?.some(c => c.id === id && c.active) ?? false
const visibleChannels = (['inapp', 'email', 'webhook', 'ntfy'] as const).filter(ch => {
if (!isActive(ch)) return false
return matrix.event_types.some((evt: string) => matrix.implemented_combos[evt]?.includes(ch))
return matrix.event_types.some(evt => matrix.implemented_combos[evt]?.includes(ch))
})
const toggle = async (eventType: string, channel: string) => {
@@ -53,53 +81,40 @@ export default function AdminNotificationsPanel({ t, toast }: { t: (k: string) =
}
if (matrix.event_types.length === 0) {
return (
<div className="bg-white rounded-xl border border-slate-200 p-6">
<p className="text-content-faint" style={{ fontSize: 'calc(13px * var(--fs-scale-body, 1))' }}>{t('settings.notificationPreferences.noChannels')}</p>
</div>
)
return card(<SettingsHint>{t('settings.notificationPreferences.noChannels')}</SettingsHint>)
}
return (
<div className="space-y-4">
<div className="bg-white rounded-xl border border-slate-200 overflow-hidden">
<div className="px-6 py-4 border-b border-slate-100">
<h2 className="font-semibold text-slate-900">{t('admin.tabs.notifications')}</h2>
<p className="text-xs text-slate-400 mt-1">{t('admin.notifications.adminNotificationsHint')}</p>
const columns = `minmax(0, 1fr) ${visibleChannels.map(() => '76px').join(' ')}`
const channelName = (ch: string) => t(ADMIN_CHANNEL_LABEL_KEYS[ch]) || ch
const eventName = (evt: string) => t(ADMIN_EVENT_LABEL_KEYS[evt]) || evt
return card(
<div className={`overflow-x-auto rounded-[12px] border border-edge-faint bg-surface-card transition-opacity ${saving ? 'opacity-60' : ''}`}>
<div className="min-w-max">
{/* The channel names over their columns */}
<div className="grid items-end gap-1 border-b border-edge-faint px-3.5 pb-2 pt-2.5" style={{ gridTemplateColumns: columns }}>
<span className="font-geist font-bold uppercase tracking-[.08em] text-content-faint" style={fs(9.5)}>
{saving ? 'Saving…' : null}
</span>
{visibleChannels.map(ch => (
<span key={ch} className={EYEBROW} style={fs(9.5)}>{channelName(ch)}</span>
))}
</div>
<div className="p-6">
{saving && <p className="text-content-faint" style={{ fontSize: 'calc(11px * var(--fs-scale-caption, 1))', marginBottom: 8 }}>Saving…</p>}
{/* Header row */}
<div className="border-b border-edge" style={{ display: 'grid', gridTemplateColumns: `minmax(0, 1fr) ${visibleChannels.map(() => '80px').join(' ')}`, gap: 4, paddingBottom: 6, marginBottom: 4 }}>
<span />
{visibleChannels.map(ch => (
<span key={ch} className="text-content-faint" style={{ fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 600, textAlign: 'center', textTransform: 'uppercase', letterSpacing: '0.04em' }}>
{t(ADMIN_CHANNEL_LABEL_KEYS[ch]) || ch}
</span>
))}
</div>
{/* Event rows */}
{matrix.event_types.map((eventType: string) => {
{/* One row per event, a switch per channel that implements it */}
<div className="divide-y divide-edge-faint">
{matrix.event_types.map(eventType => {
const implementedForEvent = matrix.implemented_combos[eventType] ?? []
return (
<div key={eventType} className="border-b border-edge" style={{ display: 'grid', gridTemplateColumns: `minmax(0, 1fr) ${visibleChannels.map(() => '80px').join(' ')}`, gap: 4, alignItems: 'center', padding: '8px 0' }}>
<span className="text-content" style={{ fontSize: 'calc(13px * var(--fs-scale-body, 1))' }}>
{t(ADMIN_EVENT_LABEL_KEYS[eventType]) || eventType}
</span>
<div key={eventType} className="grid items-center gap-1 px-3.5 py-2.5" style={{ gridTemplateColumns: columns }}>
<span className="min-w-0 truncate font-medium text-content" style={fs(13, 'body')}>{eventName(eventType)}</span>
{visibleChannels.map(ch => {
if (!implementedForEvent.includes(ch)) {
return <span key={ch} className="text-content-faint" style={{ textAlign: 'center', fontSize: 'calc(14px * var(--fs-scale-body, 1))' }}>—</span>
return <span key={ch} className="text-center text-content-faint" style={fs(13, 'body')}>—</span>
}
const isOn = matrix.preferences[eventType]?.[ch] ?? true
return (
<div key={ch} style={{ display: 'flex', justifyContent: 'center' }}>
<button type="button"
onClick={() => toggle(eventType, ch)}
className={`relative inline-flex h-5 w-9 items-center rounded-full transition-colors flex-shrink-0 ${isOn ? 'bg-content' : 'bg-edge'}`}
>
<span className="absolute left-0.5 h-4 w-4 rounded-full bg-white transition-transform duration-200"
style={{ transform: isOn ? 'translateX(16px)' : 'translateX(0)' }} />
</button>
<div key={ch} className="flex justify-center">
<ToggleSwitch on={isOn} label={`${eventName(eventType)}, ${channelName(ch)}`} onToggle={() => { void toggle(eventType, ch) }} />
</div>
)
})}
@@ -108,6 +123,6 @@ export default function AdminNotificationsPanel({ t, toast }: { t: (k: string) =
})}
</div>
</div>
</div>
</div>,
)
}