Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

feat(mobile): notification defaults, SSO unlink, wanderer and place names on the phone

Maurice5caa8905233d
diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json
index c17d67368..ce7770fc5 100644
--- a/client/scripts/feature-pairs.json
+++ b/client/scripts/feature-pairs.json
@@ -57,6 +57,21 @@
"desktop": ["src/pages/admin/AdminSettingsTab.tsx"],
"mobile": ["src/mobile/screens/admin/MAdminSettingsSection.tsx"]
},
+ {
+ "feature": "Wanderer connection",
+ "hooks": ["src/components/Settings/useWandererConnection.ts"],
+ "desktop": ["src/components/Settings/WandererConnectionSection.tsx"],
+ "mobile": ["src/mobile/screens/settings/MWandererConnectionSection.tsx"]
+ },
+ {
+ "feature": "Admin notification defaults",
+ "hooks": [
+ "src/pages/admin/useNotificationDefaults.ts",
+ "src/pages/admin/notificationDefaultsModel.ts"
+ ],
+ "desktop": ["src/pages/admin/AdminNotificationDefaultsPanel.tsx"],
+ "mobile": ["src/mobile/screens/admin/MAdminNotificationDefaults.tsx"]
+ },
{
"feature": "Admin Google daily limit",
"hooks": ["src/components/Admin/useGoogleQuota.ts"],
diff --git a/client/src/mobile/screens/admin/MAdminNotificationDefaults.tsx b/client/src/mobile/screens/admin/MAdminNotificationDefaults.tsx
new file mode 100644
index 000000000..95b15cc61
--- /dev/null
+++ b/client/src/mobile/screens/admin/MAdminNotificationDefaults.tsx
@@ -0,0 +1,86 @@
+import type { NotificationDefault } from '@trek/shared';
+import { EVENT_LABEL_KEYS, channelLabel } from '../../../components/Settings/notificationLabels';
+import { useTranslation } from '../../../i18n';
+import {
+ DEFAULT_ICON,
+ DEFAULT_LABEL_KEYS,
+ NEXT_DEFAULT,
+ defaultChannels,
+ defaultOf,
+} from '../../../pages/admin/notificationDefaultsModel';
+import { useNotificationDefaults } from '../../../pages/admin/useNotificationDefaults';
+import { MAdminCard, MAdminCardHead } from './MAdminUi';
+
+const TONE: Record<NotificationDefault, string> = {
+ on: 'border-transparent bg-m-act text-m-actfg',
+ off: 'border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] text-m-muted',
+ blocked:
+ 'border-transparent bg-[color:color-mix(in_srgb,var(--m-st-danger)_14%,transparent)] text-[color:var(--m-st-danger)]',
+};
+
+/**
+ * What every user's notification cells start as (#1536), the phone's form of the
+ * desktop grid: one row per event with a pill per channel, each tap cycling
+ * On → Off → Blocked. Off is a default a user may still turn on, Blocked is off
+ * for everyone and locked in their settings.
+ */
+export default function MAdminNotificationDefaults() {
+ const { t } = useTranslation();
+ const { matrix, saving, cycle } = useNotificationDefaults();
+ if (!matrix) return null;
+ const channels = defaultChannels(matrix);
+
+ return (
+ <MAdminCard>
+ <MAdminCardHead title={t('admin.notificationDefaults.title')} hint={t('admin.notificationDefaults.hint')} />
+ {/* The key to the pills below, in the same three looks. */}
+ <div className="mt-2 flex flex-wrap gap-[6px]" aria-hidden>
+ {(['on', 'off', 'blocked'] as const).map((state) => {
+ const Icon = DEFAULT_ICON[state];
+ return (
+ <span
+ key={state}
+ className={`inline-flex items-center gap-1 rounded-full border px-2 py-[2px] font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] font-bold ${TONE[state]}`}
+ >
+ <Icon size={10} strokeWidth={2.6} />
+ {t(DEFAULT_LABEL_KEYS[state])}
+ </span>
+ );
+ })}
+ </div>
+ <div className={`mt-1 transition-opacity ${saving ? 'opacity-60' : ''}`}>
+ {matrix.event_types.map((eventType) => {
+ const implemented = matrix.implemented_combos[eventType] ?? [];
+ const eventLabel = t(EVENT_LABEL_KEYS[eventType]) || eventType;
+ return (
+ <div key={eventType} className="border-t border-[color:var(--m-rowbr)] py-[10px] first:border-t-0">
+ <div className="text-[length:calc(12.5px*var(--fs-scale-body,1))] font-bold text-m-ink">{eventLabel}</div>
+ <div className="mt-[6px] flex flex-wrap gap-[6px]">
+ {channels
+ .filter((ch) => implemented.includes(ch.id))
+ .map((ch) => {
+ const state = defaultOf(matrix, eventType, ch.id);
+ const Icon = DEFAULT_ICON[state];
+ return (
+ <button
+ key={ch.id}
+ type="button"
+ data-state={state}
+ disabled={saving}
+ aria-label={`${eventLabel}, ${channelLabel(ch, t)}: ${t(DEFAULT_LABEL_KEYS[state])}`}
+ onClick={() => void cycle(eventType, ch.id, NEXT_DEFAULT[state])}
+ className={`inline-flex h-[28px] items-center gap-[5px] whitespace-nowrap rounded-full border px-[10px] text-[length:calc(11px*var(--fs-scale-body,1))] font-bold ${TONE[state]}`}
+ >
+ <Icon size={11} strokeWidth={2.6} aria-hidden />
+ {channelLabel(ch, t)}
+ </button>
+ );
+ })}
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ </MAdminCard>
+ );
+}
diff --git a/client/src/mobile/screens/admin/MAdminNotificationsSection.tsx b/client/src/mobile/screens/admin/MAdminNotificationsSection.tsx
index 003b54b53..bfa99c61b 100644
--- a/client/src/mobile/screens/admin/MAdminNotificationsSection.tsx
+++ b/client/src/mobile/screens/admin/MAdminNotificationsSection.tsx
@@ -4,6 +4,7 @@ import { SWITCH_ONLY_CHANNELS, useNotificationChannels } from '../../../componen
import { useAdminNotificationSettings } from '../../../components/Admin/useAdminNotificationSettings'
import MToggle from '../../components/MToggle'
import MAdminNotifyMatrix from './MAdminNotifyMatrix'
+import MAdminNotificationDefaults from './MAdminNotificationDefaults'
import { MAdminButton, MAdminCard, MAdminCardHead, MAdminField, MAdminInput, MAdminRow } from './MAdminUi'
interface MAdminNotificationsSectionProps {
@@ -204,6 +205,8 @@ export default function MAdminNotificationsSection({ admin, t }: MAdminNotificat
</MAdminCard>
<MAdminNotifyMatrix t={t} toast={toast} />
+ {/* What each user's cells start as, below the admin's own channels as on the desktop tab. */}
+ <MAdminNotificationDefaults />
</div>
)
}
diff --git a/client/src/mobile/screens/admin/MAdminSheets.tsx b/client/src/mobile/screens/admin/MAdminSheets.tsx
index 4d4f1ca13..2ebdf00f0 100644
--- a/client/src/mobile/screens/admin/MAdminSheets.tsx
+++ b/client/src/mobile/screens/admin/MAdminSheets.tsx
@@ -1,11 +1,12 @@
import { useState } from 'react'
-import { AlertTriangle, CheckCircle, ExternalLink, Fingerprint, ShieldOff, Trash2, UserPlus, UserCog, Download, KeyRound, RotateCcw } from 'lucide-react'
+import { AlertTriangle, CheckCircle, ExternalLink, Fingerprint, ShieldOff, Trash2, Unlink, UserPlus, UserCog, Download, KeyRound, RotateCcw } from 'lucide-react'
import { useAdminUserActions } from '../../../components/Admin/useAdminUserActions'
import type { TranslationFn } from '../../../types'
import type { useAdmin } from '../../../pages/admin/useAdmin'
import MSheet from '../../components/MSheet'
import MSegmented from '../../components/MSegmented'
import MAdminResetMfaSheet from './MAdminResetMfaSheet'
+import MConfirmSheet from '../settings/MConfirmSheet'
import { MAdminButton, MAdminField, MAdminInput, MAdminSecretInput, MAdminSheetFrame } from './MAdminUi'
import { NO_AUTOFILL } from '../../../utils/noAutofill'
@@ -33,6 +34,7 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) {
updateInfo, showUpdateModal, setShowUpdateModal,
showRotateJwtModal, setShowRotateJwtModal, rotatingJwt,
handleCreateUser, handleSaveUser, handleDeleteUser,
+ oidcConfigured,
} = admin
const roleOptions = [
@@ -43,6 +45,7 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) {
const [showResetPasskeys, setShowResetPasskeys] = useState(false)
const [resettingPk, setResettingPk] = useState(false)
const [showResetMfa, setShowResetMfa] = useState(false)
+ const [showUnlinkSso, setShowUnlinkSso] = useState(false)
const userActions = useAdminUserActions(admin, t)
const { rotateJwt } = userActions
@@ -176,6 +179,13 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) {
{t('admin.mfa.reset')}
</MAdminButton>
)}
+ {/* Unlinking single sign-on, as on the desktop: only once SSO is set up, and never for yourself. */}
+ {oidcConfigured && editingUser.id !== currentUser?.id && (
+ <MAdminButton variant="ghost" className="text-[color:var(--m-st-danger)]" onClick={() => setShowUnlinkSso(true)}>
+ <Unlink size={12} strokeWidth={2.2} />
+ {t('admin.sso.unlink')}
+ </MAdminButton>
+ )}
<MAdminButton
variant="danger"
disabled={editingUser.id === currentUser?.id}
@@ -195,6 +205,21 @@ export default function MAdminSheets({ admin, t }: MAdminSheetsProps) {
</MAdminSheetFrame>
</MSheet>
+ {/* Unlink single sign-on confirm */}
+ <MConfirmSheet
+ open={showUnlinkSso && !!editingUser}
+ onClose={() => setShowUnlinkSso(false)}
+ title={t('admin.sso.unlink')}
+ message={`${t('admin.sso.unlinkHint')} ${t('admin.sso.unlinkConfirm', { name: editingUser?.username ?? '' })}`}
+ confirmLabel={t('admin.sso.unlink')}
+ cancelLabel={t('common.cancel')}
+ danger
+ onConfirm={() => {
+ setShowUnlinkSso(false)
+ if (editingUser) void userActions.unlinkSso(editingUser)
+ }}
+ />
+
{/* Reset two-factor confirm */}
<MAdminResetMfaSheet
open={showResetMfa}
diff --git a/client/src/mobile/screens/settings/MSettingsGeneral.tsx b/client/src/mobile/screens/settings/MSettingsGeneral.tsx
index 730abaaa8..e5fd44ef6 100644
--- a/client/src/mobile/screens/settings/MSettingsGeneral.tsx
+++ b/client/src/mobile/screens/settings/MSettingsGeneral.tsx
@@ -12,6 +12,7 @@ import { dateFormatOptions } from '../../../utils/dateFormat'
import { MSetCard, MSetEyebrow, MSetHint, MSetSelectRow, MSetSegments, MSetRow } from './MSettingsUi'
import MToggle from '../../components/MToggle'
import MSetPickerSheet from './MSetPickerSheet'
+import MHintLabel from '../../components/MHintLabel'
import { preferredNavAppOptions } from '../../../components/Planner/placeNavigation'
import DemoLock from '../../../components/Demo/DemoLock'
import { useDemoAccountLock } from '../../../components/Demo/useDemoLock'
@@ -26,6 +27,7 @@ export default function MSettingsGeneral() {
const demoLocked = useDemoAccountLock()
const [currencyOpen, setCurrencyOpen] = useState(false)
const [langOpen, setLangOpen] = useState(false)
+ const [placeLangOpen, setPlaceLangOpen] = useState(false)
const [startTabOpen, setStartTabOpen] = useState(false)
const [navAppOpen, setNavAppOpen] = useState(false)
const [dateFormatOpen, setDateFormatOpen] = useState(false)
@@ -133,6 +135,20 @@ export default function MSettingsGeneral() {
<MSetSelectRow label={language.label} trailing={chevron} onClick={() => setLangOpen(true)} />
</DemoLock>
+ {/* Place names (#1799): searches can answer in another language than the app. */}
+ <div className="mb-[5px] mt-[14px]">
+ <MHintLabel
+ label={t('settings.placeLanguage')}
+ hint={t('settings.placeLanguageHint')}
+ labelClassName="font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] font-bold uppercase tracking-[.09em] text-m-faint"
+ />
+ </div>
+ <MSetSelectRow
+ label={SUPPORTED_LANGUAGES.find((l) => l.value === settings.place_language)?.label ?? t('settings.placeLanguageApp')}
+ trailing={chevron}
+ onClick={() => setPlaceLangOpen(true)}
+ />
+
<MSetEyebrow className="mb-[6px] mt-[14px]">{t('settings.temperature')}</MSetEyebrow>
<MSetSegments
value={settings.temperature_unit || 'celsius'}
@@ -230,6 +246,17 @@ export default function MSettingsGeneral() {
options={dateFormats}
/>
+ <MSetPickerSheet
+ open={placeLangOpen}
+ onClose={() => setPlaceLangOpen(false)}
+ title={t('settings.placeLanguage')}
+ value={settings.place_language || ''}
+ onSelect={(v) => save('place_language', v)}
+ options={[
+ { value: '', label: t('settings.placeLanguageApp') },
+ ...SUPPORTED_LANGUAGES.map((l) => ({ value: l.value, label: l.label })),
+ ]}
+ />
<MSetPickerSheet
open={langOpen}
onClose={() => setLangOpen(false)}
diff --git a/client/src/mobile/screens/settings/MSettingsIntegrations.tsx b/client/src/mobile/screens/settings/MSettingsIntegrations.tsx
index c933d6a28..5923948f3 100644
--- a/client/src/mobile/screens/settings/MSettingsIntegrations.tsx
+++ b/client/src/mobile/screens/settings/MSettingsIntegrations.tsx
@@ -2,6 +2,7 @@ import MPhotoProvidersSection from './MPhotoProvidersSection'
import MAirTrailConnectionSection from './MAirTrailConnectionSection'
import MMailImportSection from './MMailImportSection'
import MDawarichConnectionSection from './MDawarichConnectionSection'
+import MWandererConnectionSection from './MWandererConnectionSection'
import MLlmConnectionSection from './MLlmConnectionSection'
import MAiConnectionSection from './MAiConnectionSection'
import MSettingsMcp from './MSettingsMcp'
@@ -14,7 +15,7 @@ import { useIntegrationGates } from '../../../components/Settings/useIntegration
* function audit is rebuilt natively in the mobile design language.
*/
export default function MSettingsIntegrations() {
- const { mcpEnabled, airtrailEnabled, llmEnabled, aiAssistantEnabled, aiConnectionEnabled, ownParsing, dawarichEnabled, managed } = useIntegrationGates({ reloadAddons: true })
+ const { mcpEnabled, airtrailEnabled, llmEnabled, aiAssistantEnabled, aiConnectionEnabled, ownParsing, dawarichEnabled, wandererEnabled, managed } = useIntegrationGates({ reloadAddons: true })
return (
<>
@@ -26,6 +27,7 @@ export default function MSettingsIntegrations() {
{!managed && <MPhotoProvidersSection />}
{airtrailEnabled && !managed && <MAirTrailConnectionSection />}
{dawarichEnabled && !managed && <MDawarichConnectionSection />}
+ {wandererEnabled && !managed && <MWandererConnectionSection />}
{aiConnectionEnabled && !managed && <MAiConnectionSection assistant={aiAssistantEnabled} parsing={llmEnabled} />}
{/* Which model reads a booking, and what that costs, comes with the instance on
a managed install. The per-user fallback exists for people who supply their
diff --git a/client/src/mobile/screens/settings/MSettingsUi.tsx b/client/src/mobile/screens/settings/MSettingsUi.tsx
index b8b2c8798..4dbdd2d61 100644
--- a/client/src/mobile/screens/settings/MSettingsUi.tsx
+++ b/client/src/mobile/screens/settings/MSettingsUi.tsx
@@ -1,5 +1,4 @@
-import React, { ReactNode } from 'react'
-import type { LucideIcon } from 'lucide-react'
+import React, { ComponentType, ReactNode } from 'react'
import MHintLabel from '../../components/MHintLabel'
/**
@@ -10,7 +9,8 @@ import MHintLabel from '../../components/MHintLabel'
interface MSetCardProps {
title: string
- icon: LucideIcon
+ /** A lucide icon or a brand mark drawn the same way (WandererMark). */
+ icon: ComponentType<{ size?: number; strokeWidth?: number; className?: string }>
badge?: ReactNode
className?: string
children: ReactNode
diff --git a/client/src/mobile/screens/settings/MWandererConnectionSection.tsx b/client/src/mobile/screens/settings/MWandererConnectionSection.tsx
new file mode 100644
index 000000000..22ef39ef5
--- /dev/null
+++ b/client/src/mobile/screens/settings/MWandererConnectionSection.tsx
@@ -0,0 +1,112 @@
+import { Loader2, Plug, Save, Unplug } from 'lucide-react';
+import { useWandererConnection } from '../../../components/Settings/useWandererConnection';
+import WandererWatchRow from '../../../components/Settings/WandererWatchRow';
+import WandererMark from '../../../components/Tours/wanderer/WandererMark';
+import { useTranslation } from '../../../i18n';
+import MToggle from '../../components/MToggle';
+import { MSetButton, MSetCard, MSetHint, MSetInput, MSetRow } from './MSettingsUi';
+
+/**
+ * Phone twin of components/Settings/WandererConnectionSection: the reader's own
+ * wanderer trail database, from which Tours imports trails. Presentation only;
+ * saving, testing and disconnecting live in `useWandererConnection`, and the
+ * background check of the imported trails is the shared WandererWatchRow.
+ */
+export default function MWandererConnectionSection() {
+ const { t } = useTranslation();
+ const S = useWandererConnection();
+ const probe = S.probe ?? (S.lastCheck ? { ok: false, message: S.lastCheck } : null);
+
+ return (
+ <MSetCard
+ title={t('wanderer.title')}
+ icon={WandererMark}
+ className="mt-3"
+ badge={
+ <span
+ className={`flex-none font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] font-bold ${
+ S.connected ? 'text-[color:var(--m-st-confirmed)]' : 'text-m-muted'
+ }`}
+ >
+ {S.connected ? t('wanderer.connected') : t('wanderer.notConnected')}
+ </span>
+ }
+ >
+ <MSetHint className="mt-0">{t('wanderer.intro')}</MSetHint>
+
+ <div className="mt-3 space-y-3">
+ <MSetInput
+ type="url"
+ inputMode="url"
+ aria-label={t('wanderer.url')}
+ placeholder="https://wanderer.example.com"
+ value={S.url}
+ onChange={(event) => S.setUrl(event.target.value)}
+ />
+ <div>
+ <MSetInput
+ type="password"
+ autoComplete="off"
+ aria-label={t('wanderer.token')}
+ aria-invalid={S.tokenInvalid || undefined}
+ placeholder={S.connected && !S.token ? '••••••••' : 'wanderer_key_…'}
+ value={S.token}
+ onChange={(event) => S.setToken(event.target.value)}
+ />
+ {S.tokenInvalid ? (
+ <MSetHint className="font-bold text-[color:var(--m-st-danger)]">{t('wanderer.tokenInvalid')}</MSetHint>
+ ) : (
+ <MSetHint>{t('wanderer.tokenHint')}</MSetHint>
+ )}
+ </div>
+ </div>
+
+ <MSetRow
+ first
+ label={t('wanderer.allowInsecureTls')}
+ hint={t('wanderer.allowInsecureTlsHint')}
+ trailing={
+ <MToggle
+ checked={S.allowInsecureTls}
+ ariaLabel={t('wanderer.allowInsecureTls')}
+ onChange={S.toggleInsecureTls}
+ />
+ }
+ />
+
+ <div className="mt-3 flex flex-wrap items-center gap-2">
+ <MSetButton disabled={S.saving || S.loading || !S.canSave} onClick={() => void S.save()}>
+ <Save size={14} /> {t('common.save')}
+ </MSetButton>
+ <MSetButton
+ variant="ghost"
+ disabled={S.testing || S.loading || !S.url.trim() || S.tokenInvalid}
+ onClick={() => void S.test()}
+ >
+ {S.testing ? <Loader2 size={14} className="animate-spin" /> : <Plug size={14} />}
+ {t('wanderer.test.button')}
+ </MSetButton>
+ {S.connected && (
+ <MSetButton variant="danger" disabled={S.saving} onClick={() => void S.disconnect()}>
+ <Unplug size={14} /> {t('wanderer.disconnect')}
+ </MSetButton>
+ )}
+ </div>
+
+ {probe && (
+ <p
+ role="status"
+ className={`mt-3 font-geist text-[length:calc(11px*var(--fs-scale-caption,1))] font-bold ${
+ probe.ok ? 'text-[color:var(--m-st-confirmed)]' : 'text-[color:var(--m-st-danger)]'
+ }`}
+ >
+ {probe.message}
+ </p>
+ )}
+
+ <div className="mt-2">
+ <WandererWatchRow refreshKey={S.checkKey} />
+ </div>
+ </MSetCard>
+ );
+}
diff --git a/client/src/pages/admin/AdminNotificationDefaultsPanel.tsx b/client/src/pages/admin/AdminNotificationDefaultsPanel.tsx
index 274318106..55599dff3 100644
--- a/client/src/pages/admin/AdminNotificationDefaultsPanel.tsx
+++ b/client/src/pages/admin/AdminNotificationDefaultsPanel.tsx
@@ -1,4 +1,4 @@
-import { Check, Lock, Minus, UsersRound } from 'lucide-react'
+import { UsersRound } from 'lucide-react'
import type { NotificationDefault } from '@trek/shared'
import { useTranslation } from '../../i18n'
import { Tooltip } from '../../components/shared/Tooltip'
@@ -6,19 +6,13 @@ import { SettingsCard } from '../../components/Settings/settingsKit'
import { fs } from '../../components/shared/DialogShell'
import { EVENT_LABEL_KEYS, channelLabel } from '../../components/Settings/notificationLabels'
import { useNotificationDefaults } from './useNotificationDefaults'
+import { DEFAULT_ICON as ICON, DEFAULT_LABEL_KEYS as LABEL_KEYS, NEXT_DEFAULT as NEXT, defaultChannels, defaultOf } from './notificationDefaultsModel'
-const NEXT: Record<NotificationDefault, NotificationDefault> = { on: 'off', off: 'blocked', blocked: 'on' }
-const ICON = { on: Check, off: Minus, blocked: Lock } as const
const TONE: Record<NotificationDefault, string> = {
on: 'bg-accent text-accent-text border-transparent',
off: 'bg-surface-card text-content-muted border-edge',
blocked: 'bg-danger-soft text-danger border-transparent',
}
-const LABEL_KEYS: Record<NotificationDefault, string> = {
- on: 'admin.notificationDefaults.on',
- off: 'admin.notificationDefaults.off',
- blocked: 'admin.notificationDefaults.blocked',
-}
/**
* What every user's notification cells start as (#1536). One cell per event and
@@ -30,7 +24,7 @@ export default function AdminNotificationDefaultsPanel() {
const { matrix, saving, cycle } = useNotificationDefaults()
if (!matrix) return null
- const channels = matrix.channels.filter(ch => matrix.event_types.some(evt => matrix.implemented_combos[evt]?.includes(ch.id)))
+ const channels = defaultChannels(matrix)
const columns = `minmax(0, 1fr) ${channels.map(() => '76px').join(' ')}`
return (
@@ -63,7 +57,7 @@ export default function AdminNotificationDefaultsPanel() {
<span className="min-w-0 truncate font-medium text-content" style={fs(13, 'body')}>{t(EVENT_LABEL_KEYS[eventType]) || eventType}</span>
{channels.map(ch => {
if (!implemented.includes(ch.id)) return <span key={ch.id} className="text-center text-content-faint" style={fs(13, 'body')}>—</span>
- const state = matrix.defaults[eventType]?.[ch.id] ?? 'on'
+ const state = defaultOf(matrix, eventType, ch.id)
const Icon = ICON[state]
const label = `${t(EVENT_LABEL_KEYS[eventType]) || eventType}, ${channelLabel(ch, t)}: ${t(LABEL_KEYS[state])}`
return (
diff --git a/client/src/pages/admin/notificationDefaultsModel.ts b/client/src/pages/admin/notificationDefaultsModel.ts
new file mode 100644
index 000000000..6b3894e29
--- /dev/null
+++ b/client/src/pages/admin/notificationDefaultsModel.ts
@@ -0,0 +1,33 @@
+import type { NotificationDefault } from '@trek/shared';
+import { Check, Lock, Minus } from 'lucide-react';
+import type { NotificationDefaultsMatrix } from './useNotificationDefaults';
+
+/**
+ * The notification defaults grid (#1536) as both views draw it, the desktop
+ * AdminNotificationDefaultsPanel and the phone MAdminNotificationDefaults: each
+ * cell cycles On → Off → Blocked, Off a default a user may still turn on,
+ * Blocked off for everyone.
+ */
+export const NEXT_DEFAULT: Record<NotificationDefault, NotificationDefault> = {
+ on: 'off',
+ off: 'blocked',
+ blocked: 'on',
+};
+export const DEFAULT_ICON = { on: Check, off: Minus, blocked: Lock } as const;
+export const DEFAULT_LABEL_KEYS: Record<NotificationDefault, string> = {
+ on: 'admin.notificationDefaults.on',
+ off: 'admin.notificationDefaults.off',
+ blocked: 'admin.notificationDefaults.blocked',
+};
+
+/** The channels at least one event can be sent on; a channel nothing uses gets no column. */
+export function defaultChannels(matrix: NotificationDefaultsMatrix): NotificationDefaultsMatrix['channels'] {
+ return matrix.channels.filter((ch) =>
+ matrix.event_types.some((evt) => matrix.implemented_combos[evt]?.includes(ch.id))
+ );
+}
+
+/** A cell's current default; a cell the server does not list starts on. */
+export function defaultOf(matrix: NotificationDefaultsMatrix, eventType: string, channel: string): NotificationDefault {
+ return matrix.defaults[eventType]?.[channel] ?? 'on';
+}
diff --git a/client/tests/unit/mobile/admin/MAdminNotificationDefaults.test.tsx b/client/tests/unit/mobile/admin/MAdminNotificationDefaults.test.tsx
new file mode 100644
index 000000000..7ef13e3a7
--- /dev/null
+++ b/client/tests/unit/mobile/admin/MAdminNotificationDefaults.test.tsx
@@ -0,0 +1,57 @@
+// FE-MOB-ANOTIFDEF-001 to FE-MOB-ANOTIFDEF-003
+import { http, HttpResponse } from 'msw';
+import { describe, expect, it } from 'vitest';
+import MAdminNotificationDefaults from '../../../../src/mobile/screens/admin/MAdminNotificationDefaults';
+import { server } from '../../../helpers/msw/server';
+import { fireEvent, render, waitFor } from '../../../helpers/render';
+
+const matrix = (defaults: Record<string, Record<string, string>>) => ({
+ defaults,
+ channels: [
+ { id: 'inapp', labelKey: 'settings.notificationPreferences.inapp', active: true, configured: true },
+ { id: 'email', labelKey: 'settings.notificationPreferences.email', active: true, configured: true },
+ ],
+ event_types: ['trip_invite', 'booking_change'],
+ implemented_combos: { trip_invite: ['inapp', 'email'], booking_change: ['inapp'] },
+});
+
+const cells = () => Array.from(document.querySelectorAll('button[data-state]')) as HTMLElement[];
+
+describe('MAdminNotificationDefaults (#1536)', () => {
+ it('FE-MOB-ANOTIFDEF-001: one pill per channel an event is sent on, each in its state', async () => {
+ server.use(
+ http.get('/api/admin/notification-preferences/defaults', () =>
+ HttpResponse.json(matrix({ trip_invite: { inapp: 'on', email: 'blocked' }, booking_change: { inapp: 'off' } }))
+ )
+ );
+ render(<MAdminNotificationDefaults />);
+ await waitFor(() => expect(cells()).toHaveLength(3));
+ expect(cells().map((b) => b.getAttribute('data-state'))).toEqual(['on', 'blocked', 'off']);
+ });
+
+ it('FE-MOB-ANOTIFDEF-002: a tap cycles the cell to its next state and saves it', async () => {
+ const sent: unknown[] = [];
+ server.use(
+ http.get('/api/admin/notification-preferences/defaults', () =>
+ HttpResponse.json(matrix({ trip_invite: { inapp: 'on', email: 'on' }, booking_change: { inapp: 'on' } }))
+ ),
+ http.put('/api/admin/notification-preferences/defaults', async ({ request }) => {
+ sent.push(await request.json());
+ return HttpResponse.json(
+ matrix({ trip_invite: { inapp: 'on', email: 'off' }, booking_change: { inapp: 'on' } })
+ );
+ })
+ );
+ render(<MAdminNotificationDefaults />);
+ await waitFor(() => expect(cells()).toHaveLength(3));
+ fireEvent.click(cells()[1]);
+ await waitFor(() => expect(sent).toHaveLength(1));
+ await waitFor(() => expect(cells()[1].getAttribute('data-state')).toBe('off'));
+ });
+
+ it('FE-MOB-ANOTIFDEF-003: nothing is drawn until the defaults are loaded', () => {
+ server.use(http.get('/api/admin/notification-preferences/defaults', () => new Promise(() => {})));
+ render(<MAdminNotificationDefaults />);
+ expect(cells()).toHaveLength(0);
+ });
+});
diff --git a/client/tests/unit/mobile/admin/MAdminNotificationsSection.test.tsx b/client/tests/unit/mobile/admin/MAdminNotificationsSection.test.tsx
index da79a125c..6b696a886 100644
--- a/client/tests/unit/mobile/admin/MAdminNotificationsSection.test.tsx
+++ b/client/tests/unit/mobile/admin/MAdminNotificationsSection.test.tsx
@@ -10,6 +10,9 @@ import { useTranslation } from '../../../../src/i18n';
import type { useAdmin } from '../../../../src/pages/admin/useAdmin';
import MAdminNotificationsSection from '../../../../src/mobile/screens/admin/MAdminNotificationsSection';
+// The defaults grid loads its own data and has its own suite (MAdminNotificationDefaults.test.tsx).
+vi.mock('../../../../src/mobile/screens/admin/MAdminNotificationDefaults', () => ({ default: () => <div data-testid="notification-defaults" /> }));
+
// The per-event matrix loads its own data and has its own spec — stub it so the
// assertions here only see the section's own cards.
vi.mock('../../../../src/mobile/screens/admin/MAdminNotifyMatrix', () => ({
diff --git a/client/tests/unit/mobile/admin/MAdminSheets.test.tsx b/client/tests/unit/mobile/admin/MAdminSheets.test.tsx
index 3cdfe716e..4d52385ad 100644
--- a/client/tests/unit/mobile/admin/MAdminSheets.test.tsx
+++ b/client/tests/unit/mobile/admin/MAdminSheets.test.tsx
@@ -1,4 +1,4 @@
-// FE-MOB-ASHEET-001 to FE-MOB-ASHEET-026
+// FE-MOB-ASHEET-001 to FE-MOB-ASHEET-028
import React from 'react';
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import userEvent from '@testing-library/user-event';
@@ -217,6 +217,30 @@ describe('MAdminSheets', () => {
expect(hitId).toBe('2');
});
+ it('FE-MOB-ASHEET-027: unlinking single sign-on confirms first, then forgets that user's SSO identity', async () => {
+ const user = userEvent.setup();
+ let hitId = '';
+ server.use(
+ http.delete('/api/admin/users/:id/sso', ({ params }) => {
+ hitId = String(params.id);
+ return HttpResponse.json({ ok: true });
+ }),
+ );
+ const admin = renderSheets({ editingUser: ALICE, oidcConfigured: true });
+
+ await user.click(screen.getByRole('button', { name: 'Remove SSO link' }));
+ expect(screen.getByRole('dialog', { name: 'Remove SSO link' })).toBeInTheDocument();
+ await user.click(screen.getAllByRole('button', { name: 'Remove SSO link' })[1]);
+
+ await waitFor(() => expect(admin.toast.success).toHaveBeenCalled());
+ expect(hitId).toBe('2');
+ });
+
+ it('FE-MOB-ASHEET-028: without single sign-on set up there is nothing to unlink', () => {
+ renderSheets({ editingUser: ALICE, oidcConfigured: false });
+ expect(screen.queryByRole('button', { name: 'Remove SSO link' })).not.toBeInTheDocument();
+ });
+
it('FE-MOB-ASHEET-012: a failing passkey reset toasts the error and keeps the sheet open', async () => {
const user = userEvent.setup();
server.use(
diff --git a/client/tests/unit/mobile/settings/MSettingsGeneral.test.tsx b/client/tests/unit/mobile/settings/MSettingsGeneral.test.tsx
index 881ac5f6e..caa29db41 100644
--- a/client/tests/unit/mobile/settings/MSettingsGeneral.test.tsx
+++ b/client/tests/unit/mobile/settings/MSettingsGeneral.test.tsx
@@ -1,7 +1,7 @@
// FE-MOB-SET-001 onwards
import { describe, it, expect, vi, beforeEach } from 'vitest';
import userEvent from '@testing-library/user-event';
-import { render, screen } from '../../../helpers/render';
+import { render, screen, within } from '../../../helpers/render';
import { resetAllStores, seedStore } from '../../../helpers/store';
import { buildSettings } from '../../../helpers/factories';
import { useSettingsStore } from '../../../../src/store/settingsStore';
@@ -53,6 +53,21 @@ describe('MSettingsGeneral', () => {
expect(updateSetting).toHaveBeenCalledWith('language', 'de');
});
+ it('FE-MOB-SET-003b: place names follow the app until another language is picked for them', async () => {
+ const user = userEvent.setup();
+ const updateSetting = vi.fn().mockResolvedValue(undefined);
+ seedStore(useSettingsStore, {
+ settings: buildSettings({ language: 'en' }),
+ updateSetting,
+ });
+ render(<MSettingsGeneral />);
+
+ await user.click(screen.getByRole('button', { name: 'Same as the app' }));
+ const sheet = await screen.findByRole('dialog', { name: 'Place names' });
+ await user.click(within(sheet).getByRole('button', { name: 'Deutsch' }));
+ expect(updateSetting).toHaveBeenCalledWith('place_language', 'de');
+ });
+
it('FE-MOB-SET-004: a chosen display currency is shown with its symbol', () => {
seedStore(useSettingsStore, { settings: buildSettings({ language: 'en', default_currency: 'EUR' }) });
render(<MSettingsGeneral />);
diff --git a/client/tests/unit/mobile/settings/MWandererConnectionSection.test.tsx b/client/tests/unit/mobile/settings/MWandererConnectionSection.test.tsx
new file mode 100644
index 000000000..7a91d83aa
--- /dev/null
+++ b/client/tests/unit/mobile/settings/MWandererConnectionSection.test.tsx
@@ -0,0 +1,102 @@
+// FE-MOB-WAND-001 to FE-MOB-WAND-004
+import userEvent from '@testing-library/user-event';
+import type { WandererConnection } from '@trek/shared';
+import { http, HttpResponse } from 'msw';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import MWandererConnectionSection from '../../../../src/mobile/screens/settings/MWandererConnectionSection';
+import { server } from '../../../helpers/msw/server';
+import { render, screen, waitFor } from '../../../helpers/render';
+import { resetAllStores } from '../../../helpers/store';
+
+const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() }));
+vi.mock('../../../../src/components/shared/Toast', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('../../../../src/components/shared/Toast')>()),
+ useToast: () => toast,
+}));
+
+const disconnected: WandererConnection = {
+ url: '',
+ tokenMasked: '',
+ allowInsecureTls: false,
+ connected: false,
+ lastCheckedAt: null,
+ lastCheckOk: null,
+ lastCheckError: null,
+};
+const connected: WandererConnection = {
+ ...disconnected,
+ url: 'https://wanderer.test',
+ tokenMasked: '••••••••',
+ connected: true,
+};
+
+function settingsRoute(state: { current: WandererConnection }) {
+ return http.get('/api/integrations/wanderer/settings', () => HttpResponse.json(state.current));
+}
+
+beforeEach(() => {
+ resetAllStores();
+ vi.clearAllMocks();
+});
+
+describe('MWandererConnectionSection', () => {
+ it('FE-MOB-WAND-001: saves an address and a token and shows the connection', async () => {
+ const state = { current: disconnected };
+ const saved: unknown[] = [];
+ server.use(
+ settingsRoute(state),
+ http.put('/api/integrations/wanderer/settings', async ({ request }) => {
+ saved.push(await request.json());
+ state.current = connected;
+ return HttpResponse.json({ success: true });
+ })
+ );
+ render(<MWandererConnectionSection />);
+
+ expect(await screen.findByText('Not connected')).toBeInTheDocument();
+ await userEvent.type(screen.getByLabelText('Instance URL'), 'https://wanderer.test');
+ await userEvent.type(screen.getByLabelText('API token'), 'wanderer_key_abc');
+ await userEvent.click(screen.getByRole('button', { name: 'Save' }));
+
+ await waitFor(() =>
+ expect(saved).toEqual([{ url: 'https://wanderer.test', token: 'wanderer_key_abc', allowInsecureTls: false }])
+ );
+ expect(await screen.findByText('Connected')).toBeInTheDocument();
+ });
+
+ it('FE-MOB-WAND-002: a token that is no wanderer API token is called out and not sent', async () => {
+ server.use(settingsRoute({ current: disconnected }));
+ render(<MWandererConnectionSection />);
+ await userEvent.type(await screen.findByLabelText('Instance URL'), 'https://wanderer.test');
+ await userEvent.type(screen.getByLabelText('API token'), 'my-password');
+
+ expect(screen.getByLabelText('API token')).toHaveAttribute('aria-invalid', 'true');
+ expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
+ });
+
+ it('FE-MOB-WAND-003: a test reports its result in the card', async () => {
+ server.use(
+ settingsRoute({ current: connected }),
+ http.post('/api/integrations/wanderer/test', () => HttpResponse.json({ ok: true, trailCount: 5 }))
+ );
+ render(<MWandererConnectionSection />);
+ await screen.findByText('Connected');
+ await userEvent.click(screen.getByRole('button', { name: /Test connection|Test/ }));
+ expect(await screen.findByRole('status')).toBeInTheDocument();
+ });
+
+ it('FE-MOB-WAND-004: a connected install can be disconnected', async () => {
+ let deleted = false;
+ server.use(
+ settingsRoute({ current: connected }),
+ http.delete('/api/integrations/wanderer/settings', () => {
+ deleted = true;
+ return HttpResponse.json({ success: true });
+ })
+ );
+ render(<MWandererConnectionSection />);
+ await screen.findByText('Connected');
+ await userEvent.click(screen.getByRole('button', { name: /Disconnect/ }));
+ await waitFor(() => expect(deleted).toBe(true));
+ });
+});