import { useNavigate } from 'react-router' import { Bell, Link2, Lock, Send } from 'lucide-react' import { WEB_PUSH_CHANNEL_ID } from '@trek/shared' import { useTranslation } from '../../../i18n' import { MSetCard, MSetEyebrow, MSetInput, MSetButton, MSetHint } from './MSettingsUi' import MChip from '../../components/MChip' import MWebPushCard from './MWebPushCard' import { EVENT_LABEL_KEYS, channelLabel, isLockedCell } from '../../../components/Settings/notificationLabels' import { MASKED, useNotificationSettings } from '../../../components/Settings/useNotificationSettings' /** * "Notifications" section — NotificationsTab parity: webhook + ntfy channel * credentials, push on this device, plugin channels and the event/channel * preference matrix, rendered as chip rows instead of the desktop grid. */ export default function MSettingsNotifications() { const { t } = useTranslation() const navigate = useNavigate() const { matrix, loadFailed, saving, visibleChannels, hasChannel, pluginChannels, toggle, testChannel, channelTesting, webhookUrl, setWebhookUrl, webhookIsSet, webhookSaving, webhookTesting, saveWebhookUrl, testWebhookUrl, ntfyTopic, setNtfyTopic, ntfyServer, setNtfyServer, ntfyToken, setNtfyToken, ntfyTokenIsSet, ntfySaving, ntfyTesting, saveNtfySettings, clearNtfyToken, testNtfySettings, } = useNotificationSettings({ skipMaskedToken: true }) return ( {!matrix && (

{loadFailed ? t('common.error') : t('common.loading')}

)} {matrix && visibleChannels.length === 0 && (

{t('settings.notificationPreferences.noChannels')}

)} {matrix && visibleChannels.length > 0 && ( <> {hasChannel('webhook') && (
{t('settings.webhookUrl.label')} {t('settings.webhookUrl.hint')} setWebhookUrl(e.target.value)} placeholder={webhookIsSet ? MASKED : t('settings.webhookUrl.placeholder')} />
{t('common.save')} {t('settings.webhookUrl.test')}
)} {hasChannel('ntfy') && (
{t('settings.ntfyUrl.topicLabel')} {t('settings.ntfyUrl.hint')} setNtfyTopic(e.target.value)} placeholder={t('settings.ntfyUrl.topicPlaceholder')} /> {t('settings.ntfyUrl.serverLabel')} setNtfyServer(e.target.value)} placeholder={matrix.defaults?.ntfyServer || t('settings.ntfyUrl.serverPlaceholder')} /> {t('settings.ntfyUrl.tokenLabel')} {t('settings.ntfyUrl.tokenHint')} setNtfyToken(e.target.value)} placeholder={ntfyTokenIsSet ? MASKED : ''} />
{t('common.save')} {t('settings.ntfyUrl.test')} {ntfyTokenIsSet && ( {t('common.clear')} )}
)} {hasChannel(WEB_PUSH_CHANNEL_ID) && } {pluginChannels.map((ch) => (
{channelLabel(ch, t)} {ch.configured ? t('settings.notificationPreferences.pluginConfigured') : t('settings.notificationPreferences.notConfigured')}
{!ch.configured && ch.settingsPath && ( navigate(ch.settingsPath!)}> {t('settings.notificationPreferences.configure')} )} testChannel(ch)} disabled={!ch.configured || channelTesting === ch.id}> {t('settings.notificationPreferences.sendTest')}
))} {saving &&

{t('common.saving')}

} {/* Event → channel matrix as chip rows: tap a channel chip to toggle it. */} {matrix.event_types.map((eventType, i) => { const implementedForEvent = matrix.implemented_combos[eventType] ?? [] const relevantChannels = visibleChannels.filter((ch) => implementedForEvent.includes(ch.id)) if (relevantChannels.length === 0) return null return (
0 ? 'border-t border-[color:var(--m-rowbr)]' : ''}`}>
{t(EVENT_LABEL_KEYS[eventType]) || eventType}
{relevantChannels.map((ch) => { const isOn = matrix.preferences[eventType]?.[ch.id] ?? true // Switched off for everyone by the admin (#1536): shown, but locked. if (isLockedCell(matrix.locked, eventType, ch.id)) { return ( ) } return ( toggle(eventType, ch.id)}> {channelLabel(ch, t)} ) })}
) })} )}
) }