Files
TREK/client/src/pages/admin/AdminNotificationsPanel.tsx
T
Maurice 31859651d7 feat(help): rewrite the help center for v5 with a Tours section, new pictures in every language, and fix the tour planner bugs it surfaced
Every help screen checked against the v5 redesign. Tours is documented for
the first time, as a screen of its own with twelve screens under it, and
notifications get help of their own. All pictures are taken again on a
realistic demo trip, with short loops where a still cannot show the motion.
The English is plain and every language is written naturally rather than
word for word.

The switcher shows two levels at most, a screen's overview lists its
sub-screens as cards above its guides, each wiki page is linked once, and
the help sidebar is wider.

Fixes found along the way: Save to Collection keeps a tour's route, a track
dropped on the places column opens the Tours import, tour Share on desktop,
the unsaved tour draft lives on the account, a route click no longer adds
an end point, Trip places leaves the trip's tours out, Escape closes a
stage's day menu, confirms before destructive deletes, DWD warnings sharing
one id kept apart, a booking's date moves with it, and smaller fixes across
notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and
the admin screens.
2026-10-22 22:29:35 +02:00

78 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React from 'react'
import { BellRing, Loader2 } from 'lucide-react'
import { useAdminNotificationMatrix } from '../../components/Admin/useAdminNotificationMatrix'
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'
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.
export default function AdminNotificationsPanel({ t, toast }: { t: (k: string) => string; toast: ReturnType<typeof useToast> }) {
const { matrix, saving, visibleChannels, toggle } = useAdminNotificationMatrix(t, toast)
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>{t('common.loading')}</span>
</div>,
)
}
if (matrix.event_types.length === 0) {
return card(<SettingsHint>{t('settings.notificationPreferences.noChannels')}</SettingsHint>)
}
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 ? t('common.saving') : null}
</span>
{visibleChannels.map(ch => (
<span key={ch} className={EYEBROW} style={fs(9.5)}>{channelName(ch)}</span>
))}
</div>
{/* 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="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-center text-content-faint" style={fs(13, 'body')}>—</span>
}
const isOn = matrix.preferences[eventType]?.[ch] ?? true
return (
<div key={ch} className="flex justify-center">
<ToggleSwitch on={isOn} label={`${eventName(eventType)}, ${channelName(ch)}`} onToggle={() => { void toggle(eventType, ch) }} />
</div>
)
})}
</div>
)
})}
</div>
</div>
</div>,
)
}