mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 03:26:07 +00:00
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).
This commit is contained in:
@@ -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 (
|
||||
<div
|
||||
className={`flex items-center gap-3 border-t border-[color:var(--m-rowbr)] py-[11px] ${saving ? 'opacity-60' : ''}`}
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<MHintLabel label={t('admin.googleQuota.title')} hint={t('admin.googleQuota.subtitle')} />
|
||||
{today && (
|
||||
<p
|
||||
className={`mt-[1px] font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] tabular-nums ${
|
||||
status?.exhausted ? 'text-[color:var(--m-st-pending)]' : 'text-m-muted'
|
||||
}`}
|
||||
>
|
||||
{today}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<NumericInput
|
||||
aria-label={t('admin.googleQuota.title')}
|
||||
mode="integer"
|
||||
value={draft}
|
||||
onValueChange={setDraft}
|
||||
onKeyDown={(e) => {
|
||||
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 && (
|
||||
<MAdminButton busy={saving} onClick={() => void save()}>
|
||||
{!saving && <Check size={12} strokeWidth={2.4} />}
|
||||
{t('common.save')}
|
||||
</MAdminButton>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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<ContribStatus, string> = {
|
||||
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 (
|
||||
<div className="rounded-[16px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-[14px] py-1">
|
||||
<MAdminRow
|
||||
first
|
||||
title={
|
||||
<span className="inline-flex max-w-full items-center gap-[6px]">
|
||||
<span className="min-w-0">{t('admin.contribute.title')}</span>
|
||||
<span
|
||||
className={`flex-none font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] font-bold ${STATUS_TONE[status]}`}
|
||||
>
|
||||
{t(`admin.contribute.status.${status}`)}
|
||||
</span>
|
||||
</span>
|
||||
}
|
||||
hint={contribNote(t, state)}
|
||||
trailing={
|
||||
<MToggle
|
||||
checked={on}
|
||||
ariaLabel={t('admin.contribute.title')}
|
||||
disabled={!state.eligible || contrib.busy}
|
||||
onChange={panel.toggleMain}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
{on && (
|
||||
<>
|
||||
<MAdminNote>
|
||||
{[
|
||||
`${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(', ')}
|
||||
</MAdminNote>
|
||||
{state.queue.full && <MAdminNote warn>{t('admin.contribute.figure.queueFull')}</MAdminNote>}
|
||||
{fieldEntries(state.consent.fields).map(([field, fieldOn]) => (
|
||||
<MAdminRow
|
||||
key={field}
|
||||
title={fieldLabel(t, field)}
|
||||
trailing={
|
||||
<MToggle
|
||||
checked={fieldOn}
|
||||
ariaLabel={fieldLabel(t, field)}
|
||||
disabled={contrib.busy}
|
||||
onChange={() => panel.toggleField(field)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
||||
{panel.showLog && (
|
||||
<div className="space-y-2 border-t border-[color:var(--m-rowbr)] py-[11px]">
|
||||
<div className="text-[length:calc(12.5px*var(--fs-scale-body,1))] font-bold text-m-ink">
|
||||
{t('admin.contribute.log.title')}
|
||||
</div>
|
||||
<PlaceContribLog />
|
||||
<MAdminButton variant="ghost" disabled={contrib.busy} onClick={() => setConfirm('withdraw')}>
|
||||
<Undo2 size={12} strokeWidth={2.2} />
|
||||
{t('admin.contribute.withdraw')}
|
||||
</MAdminButton>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{panel.showPrompt && <PlaceContribPrompt state={state} contrib={contrib} onClose={panel.closePrompt} />}
|
||||
<MConfirmSheet
|
||||
open={confirm === 'off'}
|
||||
onClose={() => setConfirm(null)}
|
||||
title={t('admin.contribute.offTitle')}
|
||||
message={t('admin.contribute.offMessage')}
|
||||
confirmLabel={t('admin.contribute.offConfirm')}
|
||||
cancelLabel={t('common.cancel')}
|
||||
onConfirm={panel.switchOff}
|
||||
/>
|
||||
<MConfirmSheet
|
||||
open={confirm === 'withdraw'}
|
||||
onClose={() => 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}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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<ServiceIdentityState, string> = {
|
||||
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<QuotaLevel, string> = {
|
||||
ok: 'bg-m-act',
|
||||
low: 'bg-[color:var(--m-st-pending)]',
|
||||
out: 'bg-[color:var(--m-st-danger)]',
|
||||
};
|
||||
const FIGURE: Record<QuotaLevel, string> = {
|
||||
ok: 'text-m-ink',
|
||||
low: 'text-[color:var(--m-st-pending)]',
|
||||
out: 'text-[color:var(--m-st-danger)]',
|
||||
};
|
||||
const SERVICE_ICON: Record<string, LucideIcon> = { 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 (
|
||||
<li className={`py-[9px] ${allowance.inUse ? '' : 'opacity-60'}`}>
|
||||
<div className="flex items-center gap-2">
|
||||
<Icon size={13} strokeWidth={2} aria-hidden className="flex-none text-m-faint" />
|
||||
<span className="min-w-0 flex-1 truncate text-[length:calc(12px*var(--fs-scale-body,1))] font-bold text-m-ink">
|
||||
{name}
|
||||
</span>
|
||||
{quota && (
|
||||
<span className="flex-none font-geist text-[length:calc(10.5px*var(--fs-scale-caption,1))] tabular-nums text-m-faint">
|
||||
<span className={`font-bold ${FIGURE[quotaLevel(quota)]}`}>{number.format(quota.used)}</span>
|
||||
{' / '}
|
||||
{number.format(quota.limit)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{quota && (
|
||||
<div
|
||||
role="progressbar"
|
||||
aria-label={name}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={quota.limit}
|
||||
aria-valuenow={quota.used}
|
||||
className="mt-[6px] h-[5px] overflow-hidden rounded-full bg-[color:var(--m-rowbr)]"
|
||||
>
|
||||
<div className={`h-full rounded-full ${BAR[quotaLevel(quota)]}`} style={{ width: `${quotaShare(quota)}%` }} />
|
||||
</div>
|
||||
)}
|
||||
{note && (
|
||||
<p className="mt-[3px] font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] leading-snug text-m-muted">
|
||||
{note}
|
||||
</p>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<HTMLDivElement>(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 (
|
||||
<div
|
||||
ref={panel}
|
||||
className="rounded-[16px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-[14px] py-3"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 flex-1 truncate text-[length:calc(13px*var(--fs-scale-body,1))] font-bold text-m-ink">
|
||||
{t('admin.trekApi.quota.title')}
|
||||
</span>
|
||||
<span className="inline-flex flex-none items-center gap-[5px] rounded-full bg-[color:var(--m-sheetop)] px-2 py-[2px] font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] font-bold text-m-ink">
|
||||
<span aria-hidden className={`h-[7px] w-[7px] rounded-full ${STATE_DOT[status?.state ?? 'off']}`} />
|
||||
{status ? t(`admin.trekApi.quota.state.${status.state}`) : '…'}
|
||||
</span>
|
||||
</div>
|
||||
{meta && (
|
||||
<p className="mt-[3px] font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] text-m-muted">{meta}</p>
|
||||
)}
|
||||
{status && status.services.length > 0 && (
|
||||
<ul aria-label={t('admin.trekApi.quota.title')} className="mt-1 divide-y divide-[color:var(--m-rowbr)]">
|
||||
{status.services.map((allowance) => (
|
||||
<MQuotaRow key={allowance.service} allowance={allowance} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{hint && (
|
||||
<p className="mt-1 font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] leading-snug text-m-muted">
|
||||
{hint}
|
||||
</p>
|
||||
)}
|
||||
{canRegenerateKey(status, managed) && (
|
||||
<div className="mt-2 flex justify-end">
|
||||
<MAdminButton variant="ghost" busy={regenerating} onClick={() => setConfirming(true)}>
|
||||
{!regenerating && <RefreshCw size={12} strokeWidth={2.2} />}
|
||||
{t('admin.trekApi.quota.regenerate')}
|
||||
</MAdminButton>
|
||||
</div>
|
||||
)}
|
||||
<MConfirmSheet
|
||||
open={confirming}
|
||||
onClose={() => 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()}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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<MAdminSettingsSectionProps, 'part'>
|
||||
|
||||
// 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 <FeaturesPart admin={admin} t={t} />
|
||||
if (part === 'security') return <SecurityPart admin={admin} t={t} />
|
||||
return <ServicesPart admin={admin} t={t} />
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<div className="space-y-3">
|
||||
{/* Live flight status: open ADS-B data, no key, on by default (desktop parity). */}
|
||||
<FlightLiveCard
|
||||
t={t}
|
||||
managed={!!managed}
|
||||
on={flightLive}
|
||||
locked={flightLiveLocked}
|
||||
onChange={(v) => void handleToggleAuthSetting('flight_live_enabled', v, setFlightLive)}
|
||||
/>
|
||||
{/* Booking mail import: self-hosted only, the operator runs the TREK Cloud relay (desktop parity). */}
|
||||
{!managed && <MMailIngestAdminCard />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<div className="space-y-3">
|
||||
{/* Live flight status: open ADS-B data, no key, on by default (desktop parity). */}
|
||||
<FlightLiveCard
|
||||
t={t}
|
||||
managed={!!managed}
|
||||
on={flightLive}
|
||||
locked={flightLiveLocked}
|
||||
onChange={(v) => void handleToggleAuthSetting('flight_live_enabled', v, setFlightLive)}
|
||||
/>
|
||||
{/* Booking mail import: self-hosted only, the operator runs the TREK Cloud relay (desktop parity). */}
|
||||
{!managed && <MMailIngestAdminCard />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (part === 'security') return (
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{/* Authentication methods, with the passkey switch and the 2FA rule: they are ways in too. */}
|
||||
<MAdminCard>
|
||||
@@ -230,30 +231,117 @@ export default function MAdminSettingsSection({ admin, t, part }: MAdminSettings
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 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 (
|
||||
<div className="space-y-3">
|
||||
{/* 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 && <MAdminPlaceContrib hideWhenSwitchedOff />}
|
||||
|
||||
{!managed && (
|
||||
<MAdminCard>
|
||||
<MAdminCardHead title={t('admin.servicesCard.title')} hint={t('admin.servicesCard.hint')} />
|
||||
<div className="space-y-3">
|
||||
<MTrekApiBlock />
|
||||
<MAdminServiceQuota />
|
||||
<MAdminPlaceContrib />
|
||||
|
||||
{/* Transit backend (#1699): Transitous has no GTFS for much of Asia, so an
|
||||
install can send transit search to Google on the same key. */}
|
||||
<MAdminField label={t('admin.transitProvider.title')} hint={t('admin.transitProvider.subtitle')}>
|
||||
<MAdminSelect
|
||||
title={t('admin.transitProvider.title')}
|
||||
value={transitProvider}
|
||||
onChange={(value) => void changeTransitProvider(value)}
|
||||
options={[
|
||||
{ value: 'transitous', label: t('admin.transitProvider.transitous') },
|
||||
{ value: 'google', label: t('admin.transitProvider.google') },
|
||||
]}
|
||||
/>
|
||||
<MAdminNote>
|
||||
{transitProvider === 'google' ? t('admin.transitProvider.googleHint') : t('admin.transitProvider.transitousHint')}
|
||||
</MAdminNote>
|
||||
{/* 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 && (
|
||||
<MAdminNote warn>{t('admin.transitProvider.noKeyWarning')}</MAdminNote>
|
||||
)}
|
||||
{transitProvider === 'google' && transitGoogleKeySource === 'user-row' && (
|
||||
<MAdminNote warn>{t('admin.transitProvider.personalKeyWarning')}</MAdminNote>
|
||||
)}
|
||||
</MAdminField>
|
||||
|
||||
{/* Which keyed provider answers place search. */}
|
||||
<MAdminField label={t('admin.placesProvider.title')} hint={t('admin.placesProvider.subtitle')}>
|
||||
<MAdminSelect
|
||||
title={t('admin.placesProvider.title')}
|
||||
value={placesProvider}
|
||||
disabled={savingPlacesProvider}
|
||||
onChange={(value) => 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 && <MAdminNote warn>{t('admin.placesProvider.missingKey')}</MAdminNote>}
|
||||
</MAdminField>
|
||||
|
||||
{/* The instance's own search log, which is not Google's to spend. */}
|
||||
<div>
|
||||
<MAdminRow
|
||||
first
|
||||
title={t('admin.placeShadow.title')}
|
||||
hint={t('admin.placeShadow.subtitle')}
|
||||
trailing={
|
||||
<MToggle
|
||||
checked={placeShadowEnabled}
|
||||
ariaLabel={t('admin.placeShadow.title')}
|
||||
onChange={togglePlaceShadow}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</MAdminCard>
|
||||
)}
|
||||
|
||||
{/* The keys of the keyed providers, in the desktop order: Google, Unsplash, Amap. */}
|
||||
{!managed && (
|
||||
<MAdminCard>
|
||||
<MAdminCardHead title={t('admin.apiKeys')} hint={t('admin.apiKeysHint')} />
|
||||
<div className="space-y-3">
|
||||
{/* 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. */}
|
||||
<MTrekApiBlock />
|
||||
|
||||
<MProviderBlock title={t('admin.mapsKey')} badge={t('admin.googleCaveat.badge')} tone="caution">
|
||||
{/* Said before the field, not after it: somebody about to paste a key
|
||||
should read this while deciding, not once they already have. */}
|
||||
<p className="font-geist text-[0.625rem] leading-relaxed text-m-faint">
|
||||
{t('admin.mapsKeyHintShort')}
|
||||
</p>
|
||||
<MAdminNote>{t('admin.mapsKeyHintShort')}</MAdminNote>
|
||||
<div className="flex gap-2">
|
||||
<div className="min-w-0 flex-1">
|
||||
<MAdminSecretInput
|
||||
@@ -274,18 +362,17 @@ export default function MAdminSettingsSection({ admin, t, part }: MAdminSettings
|
||||
</MAdminButton>
|
||||
</div>
|
||||
{validation.maps === true && (
|
||||
<p className="font-geist text-[0.625rem] font-bold text-[color:var(--m-st-confirmed)]">
|
||||
<p className="font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] font-bold text-[color:var(--m-st-confirmed)]">
|
||||
{t('admin.keyValid')}
|
||||
</p>
|
||||
)}
|
||||
{validation.maps === false && (
|
||||
<p className="font-geist text-[0.625rem] font-bold text-[color:var(--m-st-danger)]">
|
||||
<p className="font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] font-bold text-[color:var(--m-st-danger)]">
|
||||
{t('admin.keyInvalid')}
|
||||
</p>
|
||||
)}
|
||||
{/* 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. */}
|
||||
<MBlockDisclosure label={t('admin.placesUsageTitle')}>
|
||||
<MAdminRow
|
||||
title={t('admin.placesPhotos.title')}
|
||||
@@ -342,23 +429,12 @@ export default function MAdminSettingsSection({ admin, t, part }: MAdminSettings
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<MAdminGoogleDailyLimit />
|
||||
</MBlockDisclosure>
|
||||
</MProviderBlock>
|
||||
|
||||
{/* No Test button, same as the desktop tab: /auth/validate-keys only
|
||||
knows how to probe Google Places and OpenWeatherMap. */}
|
||||
<MProviderBlock title={t('admin.amapKey')}>
|
||||
<p className="font-geist text-[0.625rem] leading-relaxed text-m-faint">{t('admin.amapKeyHintShort')}</p>
|
||||
<MAdminSecretInput
|
||||
aria-label={t('admin.amapKey')}
|
||||
value={amapKey}
|
||||
onChange={(e) => setAmapKey(e.target.value)}
|
||||
{...keyInputProps('amap')}
|
||||
/>
|
||||
</MProviderBlock>
|
||||
|
||||
<MProviderBlock title={t('admin.unsplashKey')}>
|
||||
<p className="font-geist text-[0.625rem] leading-relaxed text-m-faint">{t('admin.unsplashKeyHint')}</p>
|
||||
<MAdminNote>{t('admin.unsplashKeyHint')}</MAdminNote>
|
||||
<MAdminSecretInput
|
||||
aria-label={t('admin.unsplashKey')}
|
||||
value={unsplashKey}
|
||||
@@ -367,56 +443,17 @@ export default function MAdminSettingsSection({ admin, t, part }: MAdminSettings
|
||||
/>
|
||||
</MProviderBlock>
|
||||
|
||||
<MAdminField label={t('admin.placesProvider.title')} hint={t('admin.placesProvider.subtitle')}>
|
||||
{/* The app's own picker rather than a bare <select>: a native one is
|
||||
drawn by the operating system and was the one control on this page
|
||||
that did not belong to TREK. Same sheet the settings selects use. */}
|
||||
<button
|
||||
type="button"
|
||||
disabled={savingPlacesProvider}
|
||||
onClick={() => setProviderPickerOpen(true)}
|
||||
className="flex h-[42px] w-full items-center gap-2 rounded-xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-3 text-start text-[0.84375rem] text-m-ink disabled:opacity-50"
|
||||
>
|
||||
<span className="min-w-0 flex-1 truncate">{t(`admin.placesProvider.${placesProvider}`)}</span>
|
||||
<ChevronDown size={15} strokeWidth={2.2} className="flex-none text-m-faint" aria-hidden />
|
||||
</button>
|
||||
<MSetPickerSheet
|
||||
open={providerPickerOpen}
|
||||
onClose={() => setProviderPickerOpen(false)}
|
||||
title={t('admin.placesProvider.title')}
|
||||
value={placesProvider}
|
||||
onSelect={(value) => { if (value !== placesProvider) 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') },
|
||||
]}
|
||||
{/* No Test button, same as the desktop tab: /auth/validate-keys only
|
||||
knows how to probe Google Places and OpenWeatherMap. */}
|
||||
<MProviderBlock title={t('admin.amapKey')}>
|
||||
<MAdminNote>{t('admin.amapKeyHintShort')}</MAdminNote>
|
||||
<MAdminSecretInput
|
||||
aria-label={t('admin.amapKey')}
|
||||
value={amapKey}
|
||||
onChange={(e) => setAmapKey(e.target.value)}
|
||||
{...keyInputProps('amap')}
|
||||
/>
|
||||
{/* From app-config, like the desktop card: the key fields are empty
|
||||
on a managed install and on an operator key set by environment. */}
|
||||
{((placesProvider === 'google' && !hasMapsKey) || (placesProvider === 'amap' && !hasAmapKey)) && (
|
||||
<p className="mt-1 font-geist text-[0.625rem] font-bold text-[color:var(--m-st-pending)]">
|
||||
{t('admin.placesProvider.missingKey')}
|
||||
</p>
|
||||
)}
|
||||
</MAdminField>
|
||||
|
||||
<div>
|
||||
{/* The instance's own search log, which is not Google's to spend. */}
|
||||
<MAdminRow
|
||||
first
|
||||
title={t('admin.placeShadow.title')}
|
||||
hint={t('admin.placeShadow.subtitle')}
|
||||
trailing={
|
||||
<MToggle
|
||||
checked={placeShadowEnabled}
|
||||
ariaLabel={t('admin.placeShadow.title')}
|
||||
onChange={togglePlaceShadow}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</MProviderBlock>
|
||||
|
||||
<MAdminButton busy={savingKeys} onClick={handleSaveApiKeys}>
|
||||
{t('common.save')}
|
||||
|
||||
@@ -80,10 +80,23 @@ export function MAdminClampedText({ children, className = '' }: { children: stri
|
||||
)
|
||||
}
|
||||
|
||||
/** A short line in a card body: a fact under a control, or (warn) what a setting will not do as things stand. */
|
||||
export function MAdminNote({ warn = false, children }: { warn?: boolean; children: ReactNode }) {
|
||||
return (
|
||||
<p
|
||||
className={`mt-[5px] font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] leading-relaxed ${
|
||||
warn ? 'font-bold text-[color:var(--m-st-pending)]' : 'text-m-muted'
|
||||
}`}
|
||||
>
|
||||
{children}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
/** Labelled form field; its hint waits behind the label's info mark. */
|
||||
export function MAdminField({ label, hint, children }: { label: ReactNode; hint?: ReactNode; children: ReactNode }) {
|
||||
return (
|
||||
<div>
|
||||
<div data-m-field="">
|
||||
<div className="mb-[5px]">
|
||||
<MHintLabel
|
||||
label={label}
|
||||
|
||||
Reference in New Issue
Block a user