From a3620f9e051ecbbe339e5b7fb6b95cd278cffebd Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 14 Nov 2026 11:09:22 +0100 Subject: [PATCH] feat(mobile): the admin services section gets what the desktop tab has - Place search and routing as one card, as on the desktop: TREK's own services, today's allowance with a new identity behind a confirm sheet (MAdminServiceQuota), sharing place details (MAdminPlaceContrib), the transit backend and the place search provider as TREK selects, and the search log. - The key card holds Google (with its options and the daily request cap, MAdminGoogleDailyLimit), Unsplash and Amap, in the desktop order. - The logic both views need moves into one place: the transit switch into useAdminSettingsActions, the allowance figures into serviceIdentityModel, and the share-place-details panel into usePlaceContribPanel. - MAdminSettingsSection renders each section in a function of its own. - Tests follow the split admin sections (Save order, 2FA label, field marker). --- client/scripts/feature-pairs.json | 24 ++ client/scripts/theme-baseline.json | 2 +- .../components/Admin/PlaceContribPanel.tsx | 81 +----- .../components/Admin/ServiceIdentityPanel.tsx | 61 ++-- .../Admin/serviceIdentityModel.test.ts | 71 +++++ .../components/Admin/serviceIdentityModel.ts | 49 ++++ .../Admin/useAdminSettingsActions.test.ts | 31 ++ .../Admin/useAdminSettingsActions.ts | 24 ++ .../components/Admin/usePlaceContribPanel.ts | 79 +++++ .../screens/admin/MAdminGoogleDailyLimit.tsx | 63 ++++ .../screens/admin/MAdminPlaceContrib.tsx | 124 ++++++++ .../screens/admin/MAdminServiceQuota.tsx | 170 +++++++++++ .../screens/admin/MAdminSettingsSection.tsx | 273 ++++++++++-------- client/src/mobile/screens/admin/MAdminUi.tsx | 15 +- .../src/pages/admin/AdminSettingsTab.test.tsx | 2 +- client/src/pages/admin/AdminSettingsTab.tsx | 28 +- .../admin/MAdminDefaultUserSettings.test.tsx | 2 +- .../unit/mobile/admin/MAdminServices.test.tsx | 174 +++++++++++ .../admin/MAdminSettingsSection.test.tsx | 14 +- 19 files changed, 1027 insertions(+), 260 deletions(-) create mode 100644 client/src/components/Admin/serviceIdentityModel.test.ts create mode 100644 client/src/components/Admin/serviceIdentityModel.ts create mode 100644 client/src/components/Admin/usePlaceContribPanel.ts create mode 100644 client/src/mobile/screens/admin/MAdminGoogleDailyLimit.tsx create mode 100644 client/src/mobile/screens/admin/MAdminPlaceContrib.tsx create mode 100644 client/src/mobile/screens/admin/MAdminServiceQuota.tsx create mode 100644 client/tests/unit/mobile/admin/MAdminServices.test.tsx diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json index 25d1e3c21..c17d67368 100644 --- a/client/scripts/feature-pairs.json +++ b/client/scripts/feature-pairs.json @@ -57,6 +57,30 @@ "desktop": ["src/pages/admin/AdminSettingsTab.tsx"], "mobile": ["src/mobile/screens/admin/MAdminSettingsSection.tsx"] }, + { + "feature": "Admin Google daily limit", + "hooks": ["src/components/Admin/useGoogleQuota.ts"], + "desktop": ["src/components/Admin/GoogleDailyLimitRow.tsx"], + "mobile": ["src/mobile/screens/admin/MAdminGoogleDailyLimit.tsx"] + }, + { + "feature": "Admin share place details", + "hooks": [ + "src/components/Admin/usePlaceContribPanel.ts", + "src/components/Admin/placeContribModel.ts" + ], + "desktop": ["src/components/Admin/PlaceContribPanel.tsx"], + "mobile": ["src/mobile/screens/admin/MAdminPlaceContrib.tsx"] + }, + { + "feature": "Admin TREK services allowance", + "hooks": [ + "src/components/Admin/useServiceIdentity.ts", + "src/components/Admin/serviceIdentityModel.ts" + ], + "desktop": ["src/components/Admin/ServiceIdentityPanel.tsx"], + "mobile": ["src/mobile/screens/admin/MAdminServiceQuota.tsx"] + }, { "feature": "Admin users invite status", "hooks": ["src/pages/admin/adminModel.ts"], diff --git a/client/scripts/theme-baseline.json b/client/scripts/theme-baseline.json index 456d3fc64..5d2a44be9 100644 --- a/client/scripts/theme-baseline.json +++ b/client/scripts/theme-baseline.json @@ -160,7 +160,7 @@ "mobile/screens/admin/MAdminPackingTemplateManager.tsx": 8, "mobile/screens/admin/MAdminPermissionsPanel.tsx": 1, "mobile/screens/admin/MAdminPluginsPanel.tsx": 128, - "mobile/screens/admin/MAdminSettingsSection.tsx": 9, + "mobile/screens/admin/MAdminSettingsSection.tsx": 2, "mobile/screens/admin/MAdminSheets.tsx": 11, "mobile/screens/admin/MAdminStoragePanel.tsx": 42, "mobile/screens/admin/MAdminUi.tsx": 7, diff --git a/client/src/components/Admin/PlaceContribPanel.tsx b/client/src/components/Admin/PlaceContribPanel.tsx index e8ddf91f6..975325335 100644 --- a/client/src/components/Admin/PlaceContribPanel.tsx +++ b/client/src/components/Admin/PlaceContribPanel.tsx @@ -1,26 +1,16 @@ -import type { PlaceContribField, PlaceContribState } from '@trek/shared'; +import type { PlaceContribState } from '@trek/shared'; import { HeartHandshake, Undo2 } from 'lucide-react'; -import { useState } from 'react'; import { useTranslation } from '../../i18n'; import type { TranslationFn } from '../../types'; -import { getApiErrorMessage } from '../../utils/apiError'; import { SettingsCard, StatusPill } from '../Settings/settingsKit'; import ToggleSwitch from '../Settings/ToggleSwitch'; import ConfirmDialog from '../shared/ConfirmDialog'; import { fs } from '../shared/DialogShell'; -import { useToast } from '../shared/Toast'; import { FigureBadge } from '../Tours/paddle/FigureBadge'; import PlaceContribLog from './PlaceContribLog'; -import { - contribNote, - contribStatus, - fieldEntries, - fieldLabel, - refusalReason, - type ContribStatus, -} from './placeContribModel'; +import { contribNote, fieldEntries, fieldLabel, type ContribStatus } from './placeContribModel'; import PlaceContribPrompt from './PlaceContribPrompt'; -import { usePlaceContrib } from './usePlaceContrib'; +import { usePlaceContribPanel } from './usePlaceContribPanel'; const PILL_TONE: Record = { active: 'success', @@ -61,54 +51,12 @@ function Figures({ state, t }: { state: PlaceContribState; t: TranslationFn }) { * way to take everything back. Turning it on for the first time opens the same * prompt an admin gets on the first visit, so an agreement always comes from it. */ -/** - * Standing alone (managed settings), a card that can only say "not available" - * because the operator switched sharing off is a dead end. - */ -function hiddenAlone(state: PlaceContribState, alone: boolean): boolean { - return alone && state.ineligibleReason === 'env_off'; -} - export default function PlaceContribPanel({ hideWhenSwitchedOff = false }: { hideWhenSwitchedOff?: boolean } = {}) { const { t } = useTranslation(); - const toast = useToast(); - const contrib = usePlaceContrib(); - const { state } = contrib; - const [prompting, setPrompting] = useState(null); - const [confirm, setConfirm] = useState<'off' | 'withdraw' | null>(null); + const panel = usePlaceContribPanel({ hideWhenSwitchedOff }); + const { contrib, state, status, on, confirm, setConfirm, toggleField, withdraw } = panel; - if (!state) return null; - if (hiddenAlone(state, hideWhenSwitchedOff)) return null; - const status = contribStatus(state); - const agreed = state.consent.decision === 'agreed' && state.consent.termsVersion === state.termsVersion; - // The prompt opens by itself once per visit while the server asks for it. - const showPrompt = prompting ?? state.showPrompt; - - const fail = (err: unknown) => { - const reason = refusalReason(err); - toast.error( - reason === 'terms_outdated' || reason === 'no_field' - ? t(`admin.contribute.refused.${reason}`) - : getApiErrorMessage(err, t('common.error')) - ); - }; - - const toggleField = (field: PlaceContribField) => { - const fields = { ...state.consent.fields, [field]: !state.consent.fields[field] }; - if (!Object.values(fields).some(Boolean)) { - setConfirm('off'); - return; - } - contrib.decide({ action: 'fields', fields }).catch(fail); - }; - - const withdraw = () => { - setConfirm(null); - contrib.withdraw().then((r) => { - const total = Object.values(r.withdrawn).reduce((a, b) => a + b, 0); - toast.success(t('admin.contribute.withdrawn', { total })); - }, fail); - }; + if (panel.hidden || !state || !status) return null; return ( (agreed && state.consent.enabled ? setConfirm('off') : setPrompting(true))} + onToggle={panel.toggleMain} /> } bodyClassName="flex flex-col gap-3 p-4" > - {agreed && state.consent.enabled && ( + {on && ( <>
    @@ -151,7 +99,7 @@ export default function PlaceContribPanel({ hideWhenSwitchedOff = false }: { hid )} - {(agreed || state.consent.decision === 'off') && ( + {panel.showLog && (
    {/* A plain section head: the settings fold nothing away. */}
    @@ -175,16 +123,11 @@ export default function PlaceContribPanel({ hideWhenSwitchedOff = false }: { hid
    )} - {showPrompt && state.eligible && ( - setPrompting(false)} /> - )} + {panel.showPrompt && } setConfirm(null)} - onConfirm={() => { - setConfirm(null); - contrib.decide({ action: 'off' }).catch(fail); - }} + onConfirm={panel.switchOff} title={t('admin.contribute.offTitle')} message={t('admin.contribute.offMessage')} confirmLabel={t('admin.contribute.offConfirm')} diff --git a/client/src/components/Admin/ServiceIdentityPanel.tsx b/client/src/components/Admin/ServiceIdentityPanel.tsx index ce448f2d5..39989a37b 100644 --- a/client/src/components/Admin/ServiceIdentityPanel.tsx +++ b/client/src/components/Admin/ServiceIdentityPanel.tsx @@ -1,15 +1,22 @@ -import type { ServiceAllowance, ServiceIdentityState, ServiceIdentityStatus, ServiceQuotaView } from '@trek/shared'; +import type { ServiceAllowance, ServiceIdentityState } from '@trek/shared'; import { MapPin, RefreshCw, Route, Search, Signal, type LucideIcon } from 'lucide-react'; import { useRef, useState } from 'react'; import { useTranslation } from '../../i18n'; import { useSettingsStore } from '../../store/settingsStore'; -import type { TranslationFn } from '../../types'; import { getApiErrorMessage } from '../../utils/apiError'; -import { formatClockTime } from '../../utils/formatters'; import { SettingsCard } from '../Settings/settingsKit'; import ConfirmDialog from '../shared/ConfirmDialog'; import { useToast } from '../shared/Toast'; import { FigureBadge } from '../Tours/paddle/FigureBadge'; +import { + allowanceNote, + canRegenerateKey, + identityHint, + quotaLevel, + quotaResetClock, + quotaShare, + type QuotaLevel, +} from './serviceIdentityModel'; import { useServiceIdentity } from './useServiceIdentity'; const STATE_DOT: Record = { @@ -23,32 +30,8 @@ const STATE_DOT: Record = { const SERVICE_ICON: Record = { places: MapPin, photon: Search, valhalla: Route }; /** Below a tenth of the day left the bar turns amber, at nothing left red. */ -function barTone(quota: ServiceQuotaView): string { - if (quota.remaining === 0) return 'bg-danger'; - return quota.remaining < quota.limit / 10 ? 'bg-warning' : 'bg-accent'; -} - -function figureTone(quota: ServiceQuotaView): string { - if (quota.remaining === 0) return 'text-danger'; - return quota.remaining < quota.limit / 10 ? 'text-warning' : 'text-content'; -} - -/** The clock time the counts start again, in the user's format; one for all services, which share the day. */ -function useResetTime(status: ServiceIdentityStatus | null): string | null { - const is12h = useSettingsStore((s) => s.settings.time_format === '12h'); - const at = status?.services.find((s) => s.quota)?.quota?.resetAt; - if (!at) return null; - const reset = new Date(at); - return formatClockTime( - `${String(reset.getHours()).padStart(2, '0')}:${String(reset.getMinutes()).padStart(2, '0')}`, - is12h - ); -} - -function tileNote(t: TranslationFn, allowance: ServiceAllowance): string | null { - if (!allowance.inUse) return t('admin.trekApi.quota.notInUse'); - return allowance.quota ? null : t('admin.trekApi.quota.unavailable'); -} +const BAR_TONE: Record = { ok: 'bg-accent', low: 'bg-warning', out: 'bg-danger' }; +const FIGURE_TONE: Record = { ok: 'text-content', low: 'text-warning', out: 'text-danger' }; /** * One service under the key, as a tile: what is left today as the figure that @@ -59,10 +42,10 @@ function ServiceTile({ allowance }: { allowance: ServiceAllowance }) { const { t, locale } = useTranslation(); const number = new Intl.NumberFormat(locale); const name = t(`admin.trekApi.quota.service.${allowance.service}`); - const note = tileNote(t, allowance); + const note = allowanceNote(t, allowance); const quota = allowance.quota; const Icon = SERVICE_ICON[allowance.service] ?? MapPin; - const share = quota && quota.limit > 0 ? Math.min(100, (quota.used / quota.limit) * 100) : 100; + const share = quota ? quotaShare(quota) : 100; // One row per service: its name, the day's use as a bar, used of the limit. return ( @@ -83,7 +66,7 @@ function ServiceTile({ allowance }: { allowance: ServiceAllowance }) { className="h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-surface-tertiary" >
    @@ -91,7 +74,7 @@ function ServiceTile({ allowance }: { allowance: ServiceAllowance }) { className="flex-none text-caption tabular-nums text-content-faint" title={`${t('admin.trekApi.quota.remaining')}: ${number.format(quota.remaining)}`} > - {number.format(quota.used)} + {number.format(quota.used)} {' / '} {number.format(quota.limit)} @@ -103,11 +86,6 @@ function ServiceTile({ allowance }: { allowance: ServiceAllowance }) { ); } -function stateHint(t: TranslationFn, status: ServiceIdentityStatus | null, failed: boolean): string | null { - if (!status) return failed ? t('admin.trekApi.quota.unavailable') : null; - return status.state === 'connected' ? null : t(`admin.trekApi.quota.hint.${status.state}`); -} - /** * How this installation stands with the TREK services: whether it has its key, * and for place search, address search and routing today's allowance against @@ -121,7 +99,8 @@ export default function ServiceIdentityPanel({ managed = false }: { managed?: bo const panel = useRef(null); const { status, failed, regenerating, regenerate } = useServiceIdentity(panel); const [confirming, setConfirming] = useState(false); - const resetAt = useResetTime(status); + const is12h = useSettingsStore((s) => s.settings.time_format === '12h'); + const resetAt = quotaResetClock(status, is12h); const confirmRegenerate = async () => { setConfirming(false); @@ -133,8 +112,8 @@ export default function ServiceIdentityPanel({ managed = false }: { managed?: bo } }; - const hint = stateHint(t, status, failed); - const canRegenerate = !managed && status !== null && status.keySource !== 'env' && status.state !== 'off'; + const hint = identityHint(t, status, failed); + const canRegenerate = canRegenerateKey(status, managed); return (
    diff --git a/client/src/components/Admin/serviceIdentityModel.test.ts b/client/src/components/Admin/serviceIdentityModel.test.ts new file mode 100644 index 000000000..b2045908e --- /dev/null +++ b/client/src/components/Admin/serviceIdentityModel.test.ts @@ -0,0 +1,71 @@ +// FE-ADMIN-SVCMODEL-001 to FE-ADMIN-SVCMODEL-006 +import type { ServiceIdentityStatus } from '@trek/shared'; +import { describe, expect, it } from 'vitest'; +import { + allowanceNote, + canRegenerateKey, + identityHint, + quotaLevel, + quotaResetClock, + quotaShare, +} from './serviceIdentityModel'; + +const t = (key: string) => key; +const quota = (used: number, limit: number) => ({ + used, + limit, + remaining: limit - used, + resetAt: '2026-11-15T01:30:00', +}); +const STATUS: ServiceIdentityStatus = { + state: 'connected', + tier: 'std', + keySource: 'registered', + services: [ + { service: 'places', inUse: true, quota: quota(10, 100) }, + { service: 'photon', inUse: false, quota: null }, + ], + lastSeenAt: null, +} as ServiceIdentityStatus; + +describe('serviceIdentityModel', () => { + it('FE-ADMIN-SVCMODEL-001: a day is ok, low below a tenth left, out at nothing left', () => { + expect(quotaLevel(quota(10, 100))).toBe('ok'); + expect(quotaLevel(quota(95, 100))).toBe('low'); + expect(quotaLevel(quota(100, 100))).toBe('out'); + }); + + it('FE-ADMIN-SVCMODEL-002: the bar share is capped at the whole and full without a limit', () => { + expect(quotaShare(quota(25, 100))).toBe(25); + expect(quotaShare({ used: 150, limit: 100, remaining: 0, resetAt: '' })).toBe(100); + expect(quotaShare({ used: 0, limit: 0, remaining: 0, resetAt: '' })).toBe(100); + }); + + it('FE-ADMIN-SVCMODEL-003: the reset reads from the first counted service, in the user format', () => { + expect(quotaResetClock(STATUS, false)).toBe('01:30'); + expect(quotaResetClock(STATUS, true)).toMatch(/1:30/); + expect(quotaResetClock(null, false)).toBeNull(); + expect(quotaResetClock({ ...STATUS, services: [] }, false)).toBeNull(); + }); + + it('FE-ADMIN-SVCMODEL-004: a service out of use, or without a count, says so', () => { + expect(allowanceNote(t, STATUS.services[1])).toBe('admin.trekApi.quota.notInUse'); + expect(allowanceNote(t, { service: 'places', inUse: true, quota: null })).toBe('admin.trekApi.quota.unavailable'); + expect(allowanceNote(t, STATUS.services[0])).toBeNull(); + }); + + it('FE-ADMIN-SVCMODEL-005: the identity line is quiet when connected', () => { + expect(identityHint(t, STATUS, false)).toBeNull(); + expect(identityHint(t, { ...STATUS, state: 'revoked' }, false)).toBe('admin.trekApi.quota.hint.revoked'); + expect(identityHint(t, null, true)).toBe('admin.trekApi.quota.unavailable'); + expect(identityHint(t, null, false)).toBeNull(); + }); + + it('FE-ADMIN-SVCMODEL-006: a new key only where the admin holds the key', () => { + expect(canRegenerateKey(STATUS, false)).toBe(true); + expect(canRegenerateKey(STATUS, true)).toBe(false); + expect(canRegenerateKey({ ...STATUS, keySource: 'env' }, false)).toBe(false); + expect(canRegenerateKey({ ...STATUS, state: 'off' }, false)).toBe(false); + expect(canRegenerateKey(null, false)).toBe(false); + }); +}); diff --git a/client/src/components/Admin/serviceIdentityModel.ts b/client/src/components/Admin/serviceIdentityModel.ts new file mode 100644 index 000000000..9acc30b2e --- /dev/null +++ b/client/src/components/Admin/serviceIdentityModel.ts @@ -0,0 +1,49 @@ +import type { ServiceAllowance, ServiceIdentityStatus, ServiceQuotaView } from '@trek/shared'; +import type { TranslationFn } from '../../types'; +import { formatClockTime } from '../../utils/formatters'; + +/** + * What the allowance panels (desktop ServiceIdentityPanel, phone MAdminServiceQuota) + * read from the service identity status. Pure, so both views show the same thing. + */ + +/** How much of a service's day is left: plenty, below a tenth, or nothing. */ +export type QuotaLevel = 'ok' | 'low' | 'out'; + +export function quotaLevel(quota: ServiceQuotaView): QuotaLevel { + if (quota.remaining === 0) return 'out'; + return quota.remaining < quota.limit / 10 ? 'low' : 'ok'; +} + +/** The share of the day used, for the bar; a quota without a limit reads as full. */ +export function quotaShare(quota: ServiceQuotaView): number { + return quota.limit > 0 ? Math.min(100, (quota.used / quota.limit) * 100) : 100; +} + +/** The clock time the counts start again, in the user's format; one for all services, which share the day. */ +export function quotaResetClock(status: ServiceIdentityStatus | null, is12h: boolean): string | null { + const at = status?.services.find((s) => s.quota)?.quota?.resetAt; + if (!at) return null; + const reset = new Date(at); + return formatClockTime( + `${String(reset.getHours()).padStart(2, '0')}:${String(reset.getMinutes()).padStart(2, '0')}`, + is12h + ); +} + +/** A service that is not in use, or whose count the service did not report, says so under its row. */ +export function allowanceNote(t: TranslationFn, allowance: ServiceAllowance): string | null { + if (!allowance.inUse) return t('admin.trekApi.quota.notInUse'); + return allowance.quota ? null : t('admin.trekApi.quota.unavailable'); +} + +/** A line about the identity itself, when it is not simply connected (or could not be read). */ +export function identityHint(t: TranslationFn, status: ServiceIdentityStatus | null, failed: boolean): string | null { + if (!status) return failed ? t('admin.trekApi.quota.unavailable') : null; + return status.state === 'connected' ? null : t(`admin.trekApi.quota.hint.${status.state}`); +} + +/** A new key can be asked for unless the operator holds it (managed, environment) or the services are off. */ +export function canRegenerateKey(status: ServiceIdentityStatus | null, managed: boolean): boolean { + return !managed && status !== null && status.keySource !== 'env' && status.state !== 'off'; +} diff --git a/client/src/components/Admin/useAdminSettingsActions.test.ts b/client/src/components/Admin/useAdminSettingsActions.test.ts index acc2a74f2..b582ad764 100644 --- a/client/src/components/Admin/useAdminSettingsActions.test.ts +++ b/client/src/components/Admin/useAdminSettingsActions.test.ts @@ -13,6 +13,7 @@ const api = vi.hoisted(() => ({ updatePlacesDetails: vi.fn(), updatePlacesEnrich: vi.fn(), updatePlaceShadow: vi.fn(), + updateTransitProvider: vi.fn(), })); vi.mock('../../api/client', () => ({ adminApi: { @@ -22,6 +23,7 @@ vi.mock('../../api/client', () => ({ updatePlacesDetails: api.updatePlacesDetails, updatePlacesEnrich: api.updatePlacesEnrich, updatePlaceShadow: api.updatePlaceShadow, + updateTransitProvider: api.updateTransitProvider, }, authApi: { updateAppSettings: api.updateAppSettings }, })); @@ -51,6 +53,9 @@ function host(over: Record = {}) { setPlacesEnrichEnabled: vi.fn(), setPlaceShadowEnabledState: vi.fn(), setPlaceShadowEnabled: vi.fn(), + transitProvider: 'transitous' as const, + setTransitProviderState: vi.fn(), + setTransitGoogleKeySource: vi.fn(), ...over, }; } @@ -140,4 +145,30 @@ describe('useAdminSettingsActions', () => { expect(admin.setPlacesDetailsEnabledState).toHaveBeenCalledWith(false); expect(admin.setPlacesEnrichEnabled).toHaveBeenCalledWith(false); }); + + it('FE-HOOK-ADMSETACT-T01: switching the transit backend shows it at once and keeps the key source the server reports', async () => { + api.updateTransitProvider.mockResolvedValueOnce({ provider: 'google', googleKeySource: 'instance' }); + const { admin, actions } = mount(); + await act(() => actions.changeTransitProvider('google')); + expect(admin.setTransitProviderState).toHaveBeenCalledWith('google'); + expect(api.updateTransitProvider).toHaveBeenCalledWith('google'); + expect(admin.setTransitGoogleKeySource).toHaveBeenCalledWith('instance'); + }); + + it('FE-HOOK-ADMSETACT-T02: picking the backend already set writes nothing', async () => { + api.updateTransitProvider.mockClear(); + const { admin, actions } = mount(); + await act(() => actions.changeTransitProvider('transitous')); + expect(api.updateTransitProvider).not.toHaveBeenCalled(); + expect(admin.setTransitProviderState).not.toHaveBeenCalled(); + }); + + it('FE-HOOK-ADMSETACT-T03: a failed save puts the previous backend back and says why', async () => { + api.updateTransitProvider.mockRejectedValueOnce(new Error('down')); + const { admin, actions } = mount(); + await act(() => actions.changeTransitProvider('google')); + expect(admin.setTransitProviderState).toHaveBeenNthCalledWith(1, 'google'); + expect(admin.setTransitProviderState).toHaveBeenNthCalledWith(2, 'transitous'); + expect(admin.toast.error).toHaveBeenCalled(); + }); }); diff --git a/client/src/components/Admin/useAdminSettingsActions.ts b/client/src/components/Admin/useAdminSettingsActions.ts index 15259b474..b7fa7cfc3 100644 --- a/client/src/components/Admin/useAdminSettingsActions.ts +++ b/client/src/components/Admin/useAdminSettingsActions.ts @@ -1,3 +1,4 @@ +import type { TransitKeySource, TransitProvider } from '@trek/shared'; import { adminApi, authApi } from '../../api/client'; import type { TranslationFn } from '../../types'; import { getApiErrorMessage } from '../../types'; @@ -28,6 +29,9 @@ interface SettingsActionsHost { setPlacesEnrichEnabled: Flag; setPlaceShadowEnabledState: Flag; setPlaceShadowEnabled: Flag; + transitProvider: TransitProvider; + setTransitProviderState: (provider: TransitProvider) => void; + setTransitGoogleKeySource: (source: TransitKeySource) => void; } /** @@ -86,9 +90,29 @@ export function useAdminSettingsActions(admin: SettingsActionsHost, t: Translati }; }; + /** + * The transit backend (#1699): shown at once, and back to the previous one with a + * word when the save fails, so a select that springs back does not read as broken. + * A pick of the provider already selected writes nothing: the route is audited. + */ + const changeTransitProvider = async (value: string) => { + if (value === admin.transitProvider) return; + const next: TransitProvider = value === 'google' ? 'google' : 'transitous'; + const previous = admin.transitProvider; + admin.setTransitProviderState(next); + try { + const saved = await adminApi.updateTransitProvider(next); + admin.setTransitGoogleKeySource(saved.googleKeySource); + } catch (err: unknown) { + admin.setTransitProviderState(previous); + toast.error(getApiErrorMessage(err, t('common.error'))); + } + }; + return { saveOidc, saveFileTypes, + changeTransitProvider, togglePlacesPhotos: placeSwitch(admin.setPlacesPhotosEnabledState, admin.setPlacesPhotosEnabled, (enabled) => adminApi.updatePlacesPhotos(enabled) ), diff --git a/client/src/components/Admin/usePlaceContribPanel.ts b/client/src/components/Admin/usePlaceContribPanel.ts new file mode 100644 index 000000000..3b98a8eec --- /dev/null +++ b/client/src/components/Admin/usePlaceContribPanel.ts @@ -0,0 +1,79 @@ +import type { PlaceContribField } from '@trek/shared'; +import { useState } from 'react'; +import { useTranslation } from '../../i18n'; +import { getApiErrorMessage } from '../../utils/apiError'; +import { useToast } from '../shared/Toast'; +import { contribStatus, refusalReason } from './placeContribModel'; +import { usePlaceContrib } from './usePlaceContrib'; + +/** + * What the share-place-details panels (desktop PlaceContribPanel, phone + * MAdminPlaceContrib) do: the main switch (on asks for consent first, off asks + * to confirm), one switch per field (switching the last one off is switching the + * whole thing off), withdrawing what was shared, and the words for a refusal. + */ +export function usePlaceContribPanel({ hideWhenSwitchedOff = false }: { hideWhenSwitchedOff?: boolean } = {}) { + const { t } = useTranslation(); + const toast = useToast(); + const contrib = usePlaceContrib(); + const { state } = contrib; + const [prompting, setPrompting] = useState(null); + const [confirm, setConfirm] = useState<'off' | 'withdraw' | null>(null); + + const fail = (err: unknown) => { + const reason = refusalReason(err); + toast.error( + reason === 'terms_outdated' || reason === 'no_field' + ? t(`admin.contribute.refused.${reason}`) + : getApiErrorMessage(err, t('common.error')) + ); + }; + + // Shown on its own (a managed install), a switch the environment turned off is + // no decision of the admin's, so the panel stays away. + const hidden = !state || (hideWhenSwitchedOff && state.ineligibleReason === 'env_off'); + const agreed = !!state && state.consent.decision === 'agreed' && state.consent.termsVersion === state.termsVersion; + const on = agreed && !!state?.consent.enabled; + + const toggleField = (field: PlaceContribField) => { + if (!state) return; + const fields = { ...state.consent.fields, [field]: !state.consent.fields[field] }; + if (!Object.values(fields).some(Boolean)) { + setConfirm('off'); + return; + } + contrib.decide({ action: 'fields', fields }).catch(fail); + }; + + const switchOff = () => { + setConfirm(null); + contrib.decide({ action: 'off' }).catch(fail); + }; + + const withdraw = () => { + setConfirm(null); + contrib.withdraw().then((r) => { + const total = Object.values(r.withdrawn).reduce((a, b) => a + b, 0); + toast.success(t('admin.contribute.withdrawn', { total })); + }, fail); + }; + + return { + contrib, + state, + hidden, + status: state ? contribStatus(state) : null, + agreed, + on, + /** The log and the withdraw action: once agreed, and still after switching off. */ + showLog: agreed || state?.consent.decision === 'off', + showPrompt: !!state && (prompting ?? state.showPrompt) && state.eligible, + toggleMain: () => (on ? setConfirm('off') : setPrompting(true)), + closePrompt: () => setPrompting(false), + confirm, + setConfirm, + toggleField, + switchOff, + withdraw, + }; +} diff --git a/client/src/mobile/screens/admin/MAdminGoogleDailyLimit.tsx b/client/src/mobile/screens/admin/MAdminGoogleDailyLimit.tsx new file mode 100644 index 000000000..3ab18550e --- /dev/null +++ b/client/src/mobile/screens/admin/MAdminGoogleDailyLimit.tsx @@ -0,0 +1,63 @@ +import { Check } from 'lucide-react'; +import { useGoogleQuota } from '../../../components/Admin/useGoogleQuota'; +import { NumericInput } from '../../../components/shared/NumericInput'; +import { useTranslation } from '../../../i18n'; +import MHintLabel from '../../components/MHintLabel'; +import { MAdminButton } from './MAdminUi'; + +/** + * The daily cap on Google requests, the phone's form of the desktop + * GoogleDailyLimitRow: today's count under the name (in the warning colour once + * the day is used up), the cap in a small field, and a save while it differs. + */ +export default function MAdminGoogleDailyLimit() { + const { t } = useTranslation(); + const { status, draft, setDraft, dirty, saving, save } = useGoogleQuota(); + + let today: string | null = null; + if (status) { + if (status.exhausted) today = t('admin.googleQuota.reached', { used: status.used_today }); + else if (status.daily_limit == null) today = t('admin.googleQuota.usedToday', { used: status.used_today }); + else today = t('admin.googleQuota.usedOfLimit', { used: status.used_today, limit: status.daily_limit }); + } + + return ( +
    +
    + + {today && ( +

    + {today} +

    + )} +
    + { + if (e.key === 'Enter') { + e.preventDefault(); + void save(); + } + }} + placeholder={t('admin.googleQuota.placeholder')} + disabled={status === null || saving} + className="h-[34px] w-[88px] flex-none rounded-full border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-3 text-end font-geist text-[length:calc(12.5px*var(--fs-scale-body,1))] tabular-nums text-m-ink outline-none placeholder:text-m-faint" + /> + {dirty && ( + void save()}> + {!saving && } + {t('common.save')} + + )} +
    + ); +} diff --git a/client/src/mobile/screens/admin/MAdminPlaceContrib.tsx b/client/src/mobile/screens/admin/MAdminPlaceContrib.tsx new file mode 100644 index 000000000..ae5ee2ad2 --- /dev/null +++ b/client/src/mobile/screens/admin/MAdminPlaceContrib.tsx @@ -0,0 +1,124 @@ +import { Undo2 } from 'lucide-react'; +import PlaceContribLog from '../../../components/Admin/PlaceContribLog'; +import PlaceContribPrompt from '../../../components/Admin/PlaceContribPrompt'; +import { contribNote, fieldEntries, fieldLabel, type ContribStatus } from '../../../components/Admin/placeContribModel'; +import { usePlaceContribPanel } from '../../../components/Admin/usePlaceContribPanel'; +import { useTranslation } from '../../../i18n'; +import MToggle from '../../components/MToggle'; +import MConfirmSheet from '../settings/MConfirmSheet'; +import { MAdminButton, MAdminNote, MAdminRow } from './MAdminUi'; + +const STATUS_TONE: Record = { + active: 'text-[color:var(--m-st-confirmed)]', + paused: 'text-[color:var(--m-st-pending)]', + off: 'text-m-muted', + unavailable: 'text-m-muted', +}; + +/** + * Sharing place details with the TREK Places API, the phone's form of the + * desktop PlaceContribPanel: one switch for the installation (on asks for + * consent first), one per field, the figures, the transmission log and the way + * to take everything back. The logic is usePlaceContribPanel, shared with it. + */ +export default function MAdminPlaceContrib({ hideWhenSwitchedOff = false }: { hideWhenSwitchedOff?: boolean }) { + const { t, locale } = useTranslation(); + const panel = usePlaceContribPanel({ hideWhenSwitchedOff }); + const { contrib, state, status, on, confirm, setConfirm } = panel; + if (panel.hidden || !state || !status) return null; + + const number = new Intl.NumberFormat(locale); + const last = state.lastSuccessDay + ? new Intl.DateTimeFormat(locale, { day: 'numeric', month: 'short' }).format( + new Date(`${state.lastSuccessDay}T12:00:00`) + ) + : t('admin.contribute.never'); + + return ( +
    + + {t('admin.contribute.title')} + + {t(`admin.contribute.status.${status}`)} + + + } + hint={contribNote(t, state)} + trailing={ + + } + /> + + {on && ( + <> + + {[ + `${t('admin.contribute.figure.accepted')} ${number.format(state.counts.accepted)}`, + `${t('admin.contribute.figure.queue')} ${number.format(state.queue.size)}`, + `${t('admin.contribute.figure.last')} ${last}`, + ].join(', ')} + + {state.queue.full && {t('admin.contribute.figure.queueFull')}} + {fieldEntries(state.consent.fields).map(([field, fieldOn]) => ( + panel.toggleField(field)} + /> + } + /> + ))} + + )} + + {panel.showLog && ( +
    +
    + {t('admin.contribute.log.title')} +
    + + setConfirm('withdraw')}> + + {t('admin.contribute.withdraw')} + +
    + )} + + {panel.showPrompt && } + setConfirm(null)} + title={t('admin.contribute.offTitle')} + message={t('admin.contribute.offMessage')} + confirmLabel={t('admin.contribute.offConfirm')} + cancelLabel={t('common.cancel')} + onConfirm={panel.switchOff} + /> + setConfirm(null)} + title={t('admin.contribute.withdrawTitle')} + message={t('admin.contribute.withdrawMessage')} + confirmLabel={t('admin.contribute.withdraw')} + cancelLabel={t('common.cancel')} + danger + onConfirm={panel.withdraw} + /> +
    + ); +} diff --git a/client/src/mobile/screens/admin/MAdminServiceQuota.tsx b/client/src/mobile/screens/admin/MAdminServiceQuota.tsx new file mode 100644 index 000000000..58098362c --- /dev/null +++ b/client/src/mobile/screens/admin/MAdminServiceQuota.tsx @@ -0,0 +1,170 @@ +import type { ServiceAllowance, ServiceIdentityState, ServiceIdentityStatus } from '@trek/shared'; +import { MapPin, RefreshCw, Route, Search, type LucideIcon } from 'lucide-react'; +import { useRef, useState } from 'react'; +import { + allowanceNote, + canRegenerateKey, + identityHint, + quotaLevel, + quotaResetClock, + quotaShare, + type QuotaLevel, +} from '../../../components/Admin/serviceIdentityModel'; +import { useServiceIdentity } from '../../../components/Admin/useServiceIdentity'; +import { useToast } from '../../../components/shared/Toast'; +import { useTranslation } from '../../../i18n'; +import { useSettingsStore } from '../../../store/settingsStore'; +import type { TranslationFn } from '../../../types'; +import { getApiErrorMessage } from '../../../utils/apiError'; +import MConfirmSheet from '../settings/MConfirmSheet'; +import { MAdminButton } from './MAdminUi'; + +const STATE_DOT: Record = { + connected: 'bg-[color:var(--m-st-confirmed)]', + registering: 'bg-[color:var(--m-st-pending)] motion-safe:animate-pulse', + legacy: 'bg-[color:var(--m-faint)]', + off: 'bg-[color:var(--m-faint)]', + revoked: 'bg-[color:var(--m-st-danger)]', +}; +const BAR: Record = { + ok: 'bg-m-act', + low: 'bg-[color:var(--m-st-pending)]', + out: 'bg-[color:var(--m-st-danger)]', +}; +const FIGURE: Record = { + ok: 'text-m-ink', + low: 'text-[color:var(--m-st-pending)]', + out: 'text-[color:var(--m-st-danger)]', +}; +const SERVICE_ICON: Record = { places: MapPin, photon: Search, valhalla: Route }; + +/** The tier, an operator key from the environment and the reset, as one quiet line (the desktop's badges). */ +function quotaMeta(t: TranslationFn, status: ServiceIdentityStatus | null, resetAt: string | null): string { + if (!status) return ''; + const parts = [ + status.tier ? t(`admin.trekApi.quota.tier.${status.tier}`) : null, + status.keySource === 'env' ? `${t('admin.trekApi.quota.key')}: TREK_SERVICES_KEY` : null, + resetAt ? `${t('admin.trekApi.quota.resets')} ${resetAt}` : null, + ]; + return parts.filter(Boolean).join(', '); +} + +function MQuotaRow({ allowance }: { allowance: ServiceAllowance }) { + const { t, locale } = useTranslation(); + const number = new Intl.NumberFormat(locale); + const name = t(`admin.trekApi.quota.service.${allowance.service}`); + const note = allowanceNote(t, allowance); + const quota = allowance.quota; + const Icon = SERVICE_ICON[allowance.service] ?? MapPin; + return ( +
  • +
    + + + {name} + + {quota && ( + + {number.format(quota.used)} + {' / '} + {number.format(quota.limit)} + + )} +
    + {quota && ( +
    +
    +
    + )} + {note && ( +

    + {note} +

    + )} +
  • + ); +} + +/** + * How this installation stands with the TREK services, the phone's form of the + * desktop ServiceIdentityPanel: its state, today's use per service against the + * allowance, when the count starts again, and a new key when the old one leaked. + * Read while in view and refreshed every 30 seconds (useServiceIdentity). + */ +export default function MAdminServiceQuota({ managed = false }: { managed?: boolean }) { + const { t } = useTranslation(); + const toast = useToast(); + const panel = useRef(null); + const { status, failed, regenerating, regenerate } = useServiceIdentity(panel); + const [confirming, setConfirming] = useState(false); + const is12h = useSettingsStore((s) => s.settings.time_format === '12h'); + const resetAt = quotaResetClock(status, is12h); + const hint = identityHint(t, status, failed); + const meta = quotaMeta(t, status, resetAt); + + const confirmRegenerate = async () => { + setConfirming(false); + try { + await regenerate(); + toast.success(t('admin.trekApi.quota.regenerated')); + } catch (err) { + toast.error(getApiErrorMessage(err, t('common.error'))); + } + }; + + return ( +
    +
    + + {t('admin.trekApi.quota.title')} + + + + {status ? t(`admin.trekApi.quota.state.${status.state}`) : '…'} + +
    + {meta && ( +

    {meta}

    + )} + {status && status.services.length > 0 && ( +
      + {status.services.map((allowance) => ( + + ))} +
    + )} + {hint && ( +

    + {hint} +

    + )} + {canRegenerateKey(status, managed) && ( +
    + setConfirming(true)}> + {!regenerating && } + {t('admin.trekApi.quota.regenerate')} + +
    + )} + setConfirming(false)} + title={t('admin.trekApi.quota.regenerateTitle')} + message={t('admin.trekApi.quota.regenerateBody')} + confirmLabel={t('admin.trekApi.quota.regenerate')} + cancelLabel={t('common.cancel')} + onConfirm={() => void confirmRegenerate()} + /> +
    + ); +} diff --git a/client/src/mobile/screens/admin/MAdminSettingsSection.tsx b/client/src/mobile/screens/admin/MAdminSettingsSection.tsx index 01abc962c..ecec506d7 100644 --- a/client/src/mobile/screens/admin/MAdminSettingsSection.tsx +++ b/client/src/mobile/screens/admin/MAdminSettingsSection.tsx @@ -1,5 +1,4 @@ -import { useState } from 'react' -import { AlertTriangle, ChevronDown, RefreshCw } from 'lucide-react' +import { AlertTriangle, RefreshCw } from 'lucide-react' import { useAdminSettingsActions } from '../../../components/Admin/useAdminSettingsActions' import { placesGoogleOnlyHint } from '../../../utils/placeSource' import type { TranslationFn } from '../../../types' @@ -8,15 +7,19 @@ import MToggle from '../../components/MToggle' import { MBlockDisclosure, MProviderBlock, MTrekApiBlock } from './MApiProviderBlocks' import MAdminOidcCard from './MAdminOidcCard' import MMailIngestAdminCard from './MMailIngestAdminCard' -import MSetPickerSheet from '../settings/MSetPickerSheet' +import MAdminGoogleDailyLimit from './MAdminGoogleDailyLimit' +import MAdminPlaceContrib from './MAdminPlaceContrib' +import MAdminServiceQuota from './MAdminServiceQuota' import { MAdminButton, MAdminCard, MAdminCardHead, MAdminField, MAdminInput, + MAdminNote, MAdminRow, MAdminSecretInput, + MAdminSelect, } from './MAdminUi' interface MAdminSettingsSectionProps { @@ -30,52 +33,50 @@ interface MAdminSettingsSectionProps { part: 'security' | 'services' | 'features' } -// The admin's security, services and feature setup sections as phone cards. -// All state and mutations come from useAdmin. +type PartProps = Omit + +// The admin's security, services and feature setup sections as phone cards, +// one function each. All state and mutations come from useAdmin. export default function MAdminSettingsSection({ admin, t, part }: MAdminSettingsSectionProps) { - const [providerPickerOpen, setProviderPickerOpen] = useState(false) + if (part === 'features') return + if (part === 'security') return + return +} + +/** Live flights and booking mails: how the integrations of the addons tab reach the world. */ +function FeaturesPart({ admin, t }: PartProps) { + const { managed, flightLive, setFlightLive, flightLiveLocked, handleToggleAuthSetting } = admin + return ( +
    + {/* Live flight status: open ADS-B data, no key, on by default (desktop parity). */} + void handleToggleAuthSetting('flight_live_enabled', v, setFlightLive)} + /> + {/* Booking mail import: self-hosted only, the operator runs the TREK Cloud relay (desktop parity). */} + {!managed && } +
    + ) +} + +/** Who may sign in and what it takes, with the one destructive action last. */ +function SecurityPart({ admin, t }: PartProps) { const { - placesPhotosEnabled, placesAutocompleteEnabled, placesDetailsEnabled, placesEnrichEnabled, - placesGoogleOnly, handleTogglePlacesGoogleOnly, - placeShadowEnabled, passwordLogin, setPasswordLogin, passwordRegistration, setPasswordRegistration, oidcLogin, setOidcLogin, oidcRegistration, setOidcRegistration, oidcAutoRedirect, setOidcAutoRedirect, - flightLive, setFlightLive, flightLiveLocked, envOverrideOidcOnly, oidcConfigured, requireMfa, passkeyLogin, setPasskeyLogin, passkeyConfigured, webauthnRpId, setWebauthnRpId, webauthnOrigins, setWebauthnOrigins, savingWebauthn, handleSaveWebauthn, - allowedFileTypes, setAllowedFileTypes, savingFileTypes, - mapsKey, setMapsKey, unsplashKey, setUnsplashKey, amapKey, setAmapKey, hasMapsKey, hasAmapKey, keyInputProps, mapsKeyTestable, savingKeys, validating, validation, - placesProvider, savingPlacesProvider, handleSavePlacesProvider, managed, setShowRotateJwtModal, handleToggleAuthSetting, handleToggleRequireMfa, - handleSaveApiKeys, handleValidateKey, } = admin + const { saveOidc } = useAdminSettingsActions(admin, t) - const { - saveOidc, saveFileTypes, togglePlacesPhotos, togglePlacesAutocomplete, togglePlacesDetails, togglePlacesEnrich, - togglePlaceShadow, - } = useAdminSettingsActions(admin, t) - - if (part === 'features') { - return ( -
    - {/* Live flight status: open ADS-B data, no key, on by default (desktop parity). */} - void handleToggleAuthSetting('flight_live_enabled', v, setFlightLive)} - /> - {/* Booking mail import: self-hosted only, the operator runs the TREK Cloud relay (desktop parity). */} - {!managed && } -
    - ) - } - - if (part === 'security') return ( + return (
    {/* Authentication methods, with the passkey switch and the 2FA rule: they are ways in too. */} @@ -230,30 +231,117 @@ export default function MAdminSettingsSection({ admin, t, part }: MAdminSettings )}
    ) +} - // Services: what the install talks to outside, and the file types it takes. +/** What the install talks to outside: place search and routing, the keys, the file types. */ +function ServicesPart({ admin, t }: PartProps) { + const { + placesPhotosEnabled, placesAutocompleteEnabled, placesDetailsEnabled, placesEnrichEnabled, + placesGoogleOnly, handleTogglePlacesGoogleOnly, + placeShadowEnabled, + transitProvider, transitGoogleKeySource, + allowedFileTypes, setAllowedFileTypes, savingFileTypes, + mapsKey, setMapsKey, unsplashKey, setUnsplashKey, amapKey, setAmapKey, hasMapsKey, hasAmapKey, keyInputProps, mapsKeyTestable, savingKeys, validating, validation, + placesProvider, savingPlacesProvider, handleSavePlacesProvider, + managed, + handleSaveApiKeys, handleValidateKey, + } = admin + const { + saveFileTypes, togglePlacesPhotos, togglePlacesAutocomplete, togglePlacesDetails, togglePlacesEnrich, + togglePlaceShadow, changeTransitProvider, + } = useAdminSettingsActions(admin, t) + + // Services, cut like the desktop tab: place search and routing (TREK's own + // services, which provider answers what, the search log), then the keys for + // the keyed providers, then the file types. + const providerMissingKey = (placesProvider === 'google' && !hasMapsKey) || (placesProvider === 'amap' && !hasAmapKey) return (
    - {/* API keys, place search and routing: the operator's on a managed install, - same as the desktop tab, so the whole card is left out. Unlike the desktop - tab, the phone has no share place details section for a managed install. */} + {/* On a managed install place search and routing are the operator's, but + sharing place details stays the admin's decision, as on the desktop. */} + {managed && } + + {!managed && ( + + +
    + + + + + {/* Transit backend (#1699): Transitous has no GTFS for much of Asia, so an + install can send transit search to Google on the same key. */} + + void changeTransitProvider(value)} + options={[ + { value: 'transitous', label: t('admin.transitProvider.transitous') }, + { value: 'google', label: t('admin.transitProvider.google') }, + ]} + /> + + {transitProvider === 'google' ? t('admin.transitProvider.googleHint') : t('admin.transitProvider.transitousHint')} + + {/* Google without a key that resolves changes nothing, and a personal key + serves this admin alone: the request-time fallback is silent, so here + is the only place to say it. */} + {transitProvider === 'google' && transitGoogleKeySource === null && ( + {t('admin.transitProvider.noKeyWarning')} + )} + {transitProvider === 'google' && transitGoogleKeySource === 'user-row' && ( + {t('admin.transitProvider.personalKeyWarning')} + )} + + + {/* Which keyed provider answers place search. */} + + void handleSavePlacesProvider(value)} + options={[ + { value: 'auto', label: t('admin.placesProvider.auto') }, + { value: 'google', label: t('admin.placesProvider.google') }, + { value: 'amap', label: t('admin.placesProvider.amap') }, + { value: 'openstreetmap', label: t('admin.placesProvider.openstreetmap') }, + ]} + /> + {/* From app-config, like the desktop card: the key fields are empty + on a managed install and on an operator key set by environment. */} + {providerMissingKey && {t('admin.placesProvider.missingKey')}} + + + {/* The instance's own search log, which is not Google's to spend. */} +
    + + } + /> +
    +
    +
    + )} + + {/* The keys of the keyed providers, in the desktop order: Google, Unsplash, Amap. */} {!managed && (
    - {/* Comparable blocks in the order we would have somebody choose them, - matching the desktop tab: the free source first, the keys after it. - The recommendation used to sit on the Google field here, which told - a phone admin the opposite of what the same setting says on a - laptop. */} - - {/* Said before the field, not after it: somebody about to paste a key should read this while deciding, not once they already have. */} -

    - {t('admin.mapsKeyHintShort')} -

    + {t('admin.mapsKeyHintShort')}
    {validation.maps === true && ( -

    +

    {t('admin.keyValid')}

    )} {validation.maps === false && ( -

    +

    {t('admin.keyInvalid')}

    )} - {/* What the key is allowed to be spent on. Under the key rather than - loose at the foot of the card: every one of them is a Google - request, and none of them mean anything without it. */} + {/* What the key may be spent on, and how much of it a day. Under the key: + every one of them is a Google request. */} } /> + - {/* No Test button, same as the desktop tab: /auth/validate-keys only - knows how to probe Google Places and OpenWeatherMap. */} - -

    {t('admin.amapKeyHintShort')}

    - setAmapKey(e.target.value)} - {...keyInputProps('amap')} - /> -
    - -

    {t('admin.unsplashKeyHint')}

    + {t('admin.unsplashKeyHint')}
    - - {/* The app's own picker rather than a bare