mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
feat(admin): live flight status, booking mail import and paddle water data as rows of the addon cards
The addons page listed the trip, global and integration addons and then three loose cards under them: live flight status, the booking mail import and the paddle water data. They now sit where they belong, as rows of the cards: - Live flight status is a row of the trip card, with its switch, locked when FLIGHT_LIVE_ENABLED holds it. - The booking mail import is a row of the integration card with its switch; while it is on, "Set up mail import" opens the transport, address, AI allowance, test and status in a dialog, the way AI is set up. - The paddle water data are a row under the Tours addon that opens the regions in a dialog, counting the open requests, else the regions. The phone follows with the same rows and bottom sheets. The setup row and the setup dialog are shared components (AddonSetupRow, AddonSetupDialog on the desktop, MAdminOptionRow and MAdminSetupRow on the phone), the card counts stay the addons' own, and the settings tab loses its features part.
This commit is contained in:
@@ -7,6 +7,7 @@ import { useAuthStore } from '../../store/authStore';
|
||||
import { useSettingsStore } from '../../store/settingsStore';
|
||||
import { useAddonStore } from '../../store/addonStore';
|
||||
import { ToastContainer } from '../shared/Toast';
|
||||
import { mailIngestRepo } from '../../repo/mailIngestRepo';
|
||||
import AddonManager from './AddonManager';
|
||||
|
||||
function buildAddon(overrides = {}) {
|
||||
@@ -691,4 +692,40 @@ describe('AddonManager', () => {
|
||||
expect(roadtrip.querySelector('svg.lucide-car-front')).toBeInTheDocument();
|
||||
expect(tours.querySelector('svg.lucide-puzzle')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-ADMIN-ADDON-045: live flight status is a row of the trip card, switched there and locked by the environment', async () => {
|
||||
server.use(addonsRoute([buildAddon({ id: 'packing', name: 'Lists', icon: 'ListChecks', type: 'trip', enabled: true })]));
|
||||
const onToggle = vi.fn();
|
||||
const { unmount } = render(<AddonManager flightLive={{ on: false, locked: false, managed: false, onToggle }} />);
|
||||
const trip = (await screen.findByRole('heading', { name: 'Trip' })).closest('section')!;
|
||||
await userEvent.click(within(trip).getByRole('button', { name: 'Follow booked flights live' }));
|
||||
expect(onToggle).toHaveBeenCalledTimes(1);
|
||||
// The count stays the addons': the flight row is an instance option beside them.
|
||||
expect(within(trip).getByText('1/1')).toBeInTheDocument();
|
||||
unmount();
|
||||
|
||||
render(<AddonManager flightLive={{ on: true, locked: true, managed: false, onToggle }} />);
|
||||
expect(await screen.findByRole('button', { name: 'Follow booked flights live' })).toBeDisabled();
|
||||
});
|
||||
|
||||
it('FE-ADMIN-ADDON-046: the booking mail import is a row of the integration card whose setup opens in a dialog', async () => {
|
||||
server.use(addonsRoute([buildAddon({ id: 'mcp', name: 'MCP', icon: 'Terminal', type: 'integration', enabled: false })]));
|
||||
vi.spyOn(mailIngestRepo, 'adminSettings').mockResolvedValue({ mail_ingest_enabled: 'true' });
|
||||
vi.spyOn(mailIngestRepo, 'adminStatus').mockRejectedValue(new Error('no status'));
|
||||
render(<AddonManager mailImport />);
|
||||
const integration = (await screen.findByRole('heading', { name: 'Integration' })).closest('section')!;
|
||||
expect(within(integration).getByText('Booking mail import')).toBeInTheDocument();
|
||||
await userEvent.click(await within(integration).findByRole('button', { name: 'Set up mail import' }));
|
||||
const dialog = await screen.findByRole('dialog');
|
||||
expect(within(dialog).getByText('How mail arrives')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('FE-ADMIN-ADDON-047: without the mail option the integration card has no mail row and nothing is loaded', async () => {
|
||||
server.use(addonsRoute([buildAddon({ id: 'mcp', name: 'MCP', icon: 'Terminal', type: 'integration', enabled: false })]));
|
||||
const load = vi.spyOn(mailIngestRepo, 'adminSettings');
|
||||
render(<AddonManager />);
|
||||
await screen.findByRole('heading', { name: 'Integration' });
|
||||
expect(screen.queryByText('Booking mail import')).not.toBeInTheDocument();
|
||||
expect(load).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ComponentType, ReactNode } from 'react'
|
||||
import type { ComponentType } from 'react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
import { Puzzle, ListChecks, Wallet, FileText, CalendarDays, Globe, Briefcase, Image, Terminal, Link2, Compass, BookOpen, Sparkles, Luggage, Plane, Bookmark, Users, Loader2, Mountain, CarFront } from 'lucide-react'
|
||||
import { Puzzle, ListChecks, Wallet, FileText, CalendarDays, Globe, Briefcase, Image, Terminal, Link2, Compass, BookOpen, Sparkles, Luggage, Plane, Bookmark, Users, Loader2, Mountain, CarFront, Radar } from 'lucide-react'
|
||||
import EmptyState from '../shared/EmptyState'
|
||||
import DawarichIcon from '../shared/DawarichIcon'
|
||||
import AirTrailIcon from '../shared/AirTrailIcon'
|
||||
@@ -12,6 +12,9 @@ import { SettingsCard, SettingsColumns, StatusPill } from '../Settings/settingsK
|
||||
import { type Addon, type CollabFeatures, COLLAB_SUB_FEATURES, getAddonLabel } from './addons/addonModel'
|
||||
import { useAddonManager } from './addons/useAddonManager'
|
||||
import AiAddonTile from './addons/AiAddonTile'
|
||||
import MailIngestAddonTile from './mailIngest/MailIngestAddonTile'
|
||||
import PaddleRegionsPanel from './paddle/PaddleRegionsPanel'
|
||||
import ToggleSwitch from '../Settings/ToggleSwitch'
|
||||
import { ImmichIcon, SynologyIcon } from './addons/PhotoProviderIcons'
|
||||
import WandererMark from '../Tours/wanderer/WandererMark'
|
||||
|
||||
@@ -65,13 +68,24 @@ const TYPE_META: Record<string, { icon: ComponentType<{ size?: number }>; labelK
|
||||
integration: { icon: Link2, labelKey: 'admin.addons.type.integration', hintKey: 'admin.addons.integrationHint' },
|
||||
}
|
||||
|
||||
export default function AddonManager({ bagTrackingEnabled, onToggleBagTracking, collabFeatures, onToggleCollabFeature, aside }: {
|
||||
/** The live flight status switch, an instance setting that sits with the trip addons. */
|
||||
export interface FlightLiveOption {
|
||||
on: boolean
|
||||
/** The server environment (FLIGHT_LIVE_ENABLED) holds it; the switch shows the state and says why. */
|
||||
locked: boolean
|
||||
managed: boolean
|
||||
onToggle: () => void
|
||||
}
|
||||
|
||||
export default function AddonManager({ bagTrackingEnabled, onToggleBagTracking, collabFeatures, onToggleCollabFeature, flightLive, mailImport = false }: {
|
||||
bagTrackingEnabled?: boolean
|
||||
onToggleBagTracking?: () => void
|
||||
collabFeatures?: CollabFeatures
|
||||
onToggleCollabFeature?: (key: string) => void
|
||||
/** Cards that set up what the integrations reach (flight status, booking mails), under them in the right column. */
|
||||
aside?: ReactNode
|
||||
/** Live flight status, a row of the trip card: it follows the trips' booked flights. */
|
||||
flightLive?: FlightLiveOption
|
||||
/** Booking mail import, a row of the integration card with its setup dialog; off on a managed install. */
|
||||
mailImport?: boolean
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const {
|
||||
@@ -181,6 +195,8 @@ export default function AddonManager({ bagTrackingEnabled, onToggleBagTracking,
|
||||
onToggle={() => void toggle()}
|
||||
/>
|
||||
)),
|
||||
// The paddle water data the tour planner reads, set up in a dialog of its own.
|
||||
<PaddleRegionsPanel key="paddle-regions" />,
|
||||
]
|
||||
}
|
||||
return null
|
||||
@@ -202,6 +218,9 @@ export default function AddonManager({ bagTrackingEnabled, onToggleBagTracking,
|
||||
)
|
||||
}
|
||||
|
||||
/** Whether a card holds rows beside its own addons: the AI tile, an instance option. */
|
||||
const extraRows = (key: string) =>
|
||||
(key === 'trip' && !!flightLive) || (key === 'integration' && (aiAddons.length > 0 || mailImport))
|
||||
/* A card per type, the way every other admin tab sets its cards: Trip in the
|
||||
left column, Global and Integration in the right one, each card with the
|
||||
dialogs' head band carrying the type, its count and what it means. */
|
||||
@@ -209,14 +228,14 @@ export default function AddonManager({ bagTrackingEnabled, onToggleBagTracking,
|
||||
{ key: 'trip', addons: tripAddons },
|
||||
{ key: 'global', addons: globalAddons },
|
||||
{ key: 'integration', addons: integrationAddons },
|
||||
].filter(g => g.addons.length > 0 || (g.key === 'integration' && aiAddons.length > 0))
|
||||
].filter(g => g.addons.length > 0 || extraRows(g.key))
|
||||
|
||||
const card = (g: (typeof groups)[number]) => {
|
||||
const meta = TYPE_META[g.key]
|
||||
const all = g.key === 'integration' ? [...aiAddons, ...g.addons] : g.addons
|
||||
const visible = g.addons
|
||||
const ai = g.key === 'integration' && aiAddons.length > 0
|
||||
if (!visible.length && !ai) return null
|
||||
if (!visible.length && !ai && !extraRows(g.key)) return null
|
||||
const on = all.filter(a => a.enabled).length
|
||||
return (
|
||||
<SettingsCard
|
||||
@@ -235,6 +254,10 @@ export default function AddonManager({ bagTrackingEnabled, onToggleBagTracking,
|
||||
{/* The AI addons share a connection and a settings dialog, so they head the card as one tile. */}
|
||||
{ai && <AiAddonTile addons={aiAddons} onToggle={handleToggle} />}
|
||||
{visible.map(tile)}
|
||||
{/* Not addons but instance options of the same kind, as rows of the same card;
|
||||
the count above stays the addons'. */}
|
||||
{g.key === 'trip' && flightLive && <FlightLiveTile option={flightLive} />}
|
||||
{g.key === 'integration' && mailImport && <MailIngestAddonTile />}
|
||||
</div>
|
||||
</SettingsCard>
|
||||
)
|
||||
@@ -251,5 +274,21 @@ export default function AddonManager({ bagTrackingEnabled, onToggleBagTracking,
|
||||
)
|
||||
}
|
||||
|
||||
return <SettingsColumns start={cards.start} end={<>{cards.end}{aside}</>} />
|
||||
return <SettingsColumns start={cards.start} end={cards.end} />
|
||||
}
|
||||
|
||||
/** Live flight status as a trip row: on, it follows every booked flight on its day. */
|
||||
function FlightLiveTile({ option }: { option: FlightLiveOption }) {
|
||||
const { t } = useTranslation()
|
||||
const name = t('flightLive.adminTitle')
|
||||
const hint = option.managed ? t('flightLive.adminHintManaged') : t('flightLive.adminHint')
|
||||
return (
|
||||
<AddonTile
|
||||
icon={<Radar size={18} />}
|
||||
name={name}
|
||||
description={option.locked ? `${hint} ${t('flightLive.envLocked')}` : hint}
|
||||
enabled={option.on}
|
||||
trailing={<ToggleSwitch on={option.on} label={t('flightLive.adminToggle')} disabled={option.locked} onToggle={option.onToggle} />}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import React, { useId, type ReactNode } from 'react';
|
||||
import { useTranslation } from '../../i18n';
|
||||
import {
|
||||
DialogButton,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogShell,
|
||||
DialogTile,
|
||||
FooterSpacer,
|
||||
NEUTRAL_TINT,
|
||||
} from '../shared/DialogShell';
|
||||
|
||||
/**
|
||||
* The dialog an addon's setup row opens: the icon tile, the addon it belongs
|
||||
* to above the title, what it sets up below, and one Close, since everything
|
||||
* inside saves on its own (booking mails, paddle water data).
|
||||
*/
|
||||
export default function AddonSetupDialog({
|
||||
icon,
|
||||
eyebrow,
|
||||
title,
|
||||
sub,
|
||||
onClose,
|
||||
blocked = false,
|
||||
children,
|
||||
}: {
|
||||
icon: ReactNode;
|
||||
eyebrow: string;
|
||||
title: string;
|
||||
sub: string;
|
||||
onClose: () => void;
|
||||
/** A confirmation stacked on top holds the dialog while it is open. */
|
||||
blocked?: boolean;
|
||||
children: ReactNode;
|
||||
}): React.ReactElement {
|
||||
const { t } = useTranslation();
|
||||
const labelId = useId();
|
||||
return (
|
||||
<DialogShell
|
||||
onClose={onClose}
|
||||
labelledBy={labelId}
|
||||
width="detail"
|
||||
blocked={blocked}
|
||||
header={
|
||||
<DialogHeader
|
||||
tile={<DialogTile>{icon}</DialogTile>}
|
||||
tint={NEUTRAL_TINT}
|
||||
labelId={labelId}
|
||||
eyebrow={eyebrow}
|
||||
title={title}
|
||||
sub={sub}
|
||||
subWraps
|
||||
onClose={onClose}
|
||||
/>
|
||||
}
|
||||
footer={
|
||||
<DialogFooter>
|
||||
<FooterSpacer />
|
||||
<DialogButton variant="primary" onClick={onClose}>
|
||||
{t('common.close')}
|
||||
</DialogButton>
|
||||
</DialogFooter>
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</DialogShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { ChevronRight, Settings2 } from 'lucide-react';
|
||||
import React, { type ReactNode } from 'react';
|
||||
import { fs } from '../shared/DialogShell';
|
||||
|
||||
/**
|
||||
* The last row of an addon's shelf that opens its settings dialog: a gear, what
|
||||
* the dialog sets up, and a chevron. It keeps a card of addons as short as its
|
||||
* switches and puts the long forms behind one tap (AI, booking mails, paddle
|
||||
* water data). A badge says what waits inside, such as requests to look at.
|
||||
*/
|
||||
export default function AddonSetupRow({
|
||||
label,
|
||||
onOpen,
|
||||
badge,
|
||||
}: {
|
||||
label: string;
|
||||
onOpen: () => void;
|
||||
badge?: ReactNode;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpen}
|
||||
className="flex min-h-[44px] w-full items-center gap-2.5 border-0 bg-transparent py-1.5 pe-4 ps-[60px] text-start transition-colors hover:bg-surface-hover focus-visible:bg-surface-hover focus-visible:outline-none"
|
||||
>
|
||||
<span className="grid h-6 w-6 flex-none place-items-center text-content-muted">
|
||||
<Settings2 size={14} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate font-medium text-content" style={fs(12.5, 'body')}>
|
||||
{label}
|
||||
</span>
|
||||
{badge}
|
||||
<ChevronRight size={15} strokeWidth={2.2} className="flex-none text-content-faint rtl:rotate-180" />
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import { ChevronRight, Settings2, Sparkles } from 'lucide-react';
|
||||
import { Sparkles } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { useTranslation } from '../../../i18n';
|
||||
import { StatusPill } from '../../Settings/settingsKit';
|
||||
import { fs } from '../../shared/DialogShell';
|
||||
import AddonSetupRow from '../AddonSetupRow';
|
||||
import AddonSubRow from '../AddonSubRow';
|
||||
import AddonTile from '../AddonTile';
|
||||
import { type Addon, getAddonLabel } from './addonModel';
|
||||
@@ -54,23 +55,7 @@ export default function AiAddonTile({
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{tile.canSetUp && (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
onClick={tile.openDialog}
|
||||
className="flex min-h-[44px] w-full items-center gap-2.5 border-0 bg-transparent py-1.5 pe-4 ps-[60px] text-start transition-colors hover:bg-surface-hover focus-visible:bg-surface-hover focus-visible:outline-none"
|
||||
>
|
||||
<span className="grid h-6 w-6 flex-none place-items-center text-content-muted">
|
||||
<Settings2 size={14} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate font-medium text-content" style={fs(12.5, 'body')}>
|
||||
{t('admin.addons.ai.setup')}
|
||||
</span>
|
||||
<ChevronRight size={15} strokeWidth={2.2} className="flex-none text-content-faint rtl:rotate-180" />
|
||||
</button>
|
||||
</li>
|
||||
)}
|
||||
{tile.canSetUp && <AddonSetupRow label={t('admin.addons.ai.setup')} onOpen={tile.openDialog} />}
|
||||
</AddonTile>
|
||||
{tile.dialogOpen && <AiSettingsDialog addons={addons} onClose={tile.closeDialog} />}
|
||||
</>
|
||||
|
||||
+42
-33
@@ -1,22 +1,17 @@
|
||||
import { AlertTriangle, CheckCircle, Copy, Loader2, Mail, PlugZap, Save, XCircle } from 'lucide-react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import { useTranslation } from '../../../i18n';
|
||||
import type { TranslationFn } from '../../../types';
|
||||
import { copyText } from '../../../utils/clipboard';
|
||||
import { relativeTime } from '../../../utils/relativeTime';
|
||||
import {
|
||||
HintMark,
|
||||
SETTINGS_BUTTON,
|
||||
SETTINGS_BUTTON_PRIMARY,
|
||||
SettingRow,
|
||||
SettingRows,
|
||||
SettingsCard,
|
||||
StatusPill,
|
||||
} from '../../Settings/settingsKit';
|
||||
import { HintMark, SETTINGS_BUTTON, SETTINGS_BUTTON_PRIMARY, StatusPill } from '../../Settings/settingsKit';
|
||||
import ToggleSwitch from '../../Settings/ToggleSwitch';
|
||||
import CustomSelect from '../../shared/CustomSelect';
|
||||
import { EditorField, GRID_2, INPUT, READONLY_BOX } from '../../shared/dialogParts';
|
||||
import { useToast } from '../../shared/Toast';
|
||||
import AddonSetupDialog from '../AddonSetupDialog';
|
||||
import AddonSetupRow from '../AddonSetupRow';
|
||||
import AddonTile from '../AddonTile';
|
||||
import {
|
||||
TRANSPORTS,
|
||||
problemText,
|
||||
@@ -306,32 +301,46 @@ function Setup({ admin, form, t, locale }: { admin: MailIngestAdmin; form: MailA
|
||||
}
|
||||
|
||||
/**
|
||||
* The booking mail import in the admin settings of a self-hosted install: the
|
||||
* instance switch, how mail arrives (IMAP or a signed webhook), the forwarding
|
||||
* address template, the AI allowance per person and day, a connection test and
|
||||
* the status in counts. Not shown on a managed install, where the operator
|
||||
* runs the TREK Cloud relay.
|
||||
* The booking mail import as a row of the integration card: its switch, and
|
||||
* while it is on one row to the dialog that sets it up (how mail arrives, the
|
||||
* forwarding address template, the AI allowance per person and day, a
|
||||
* connection test and the status in counts). Not shown on a managed install,
|
||||
* where the operator runs the TREK Cloud relay.
|
||||
*/
|
||||
export default function MailIngestAdminCard() {
|
||||
export default function MailIngestAddonTile() {
|
||||
const { t, locale } = useTranslation();
|
||||
const admin = useMailIngestAdmin(true);
|
||||
const [open, setOpen] = useState(false);
|
||||
const name = t('mailAdmin.title');
|
||||
return (
|
||||
<SettingsCard icon={Mail} title={t('mailAdmin.title')} hint={t('mailAdmin.hint')}>
|
||||
<SettingRows>
|
||||
<SettingRow
|
||||
label={t('mailAdmin.enabled')}
|
||||
hint={t('mailAdmin.enabledHint')}
|
||||
control={
|
||||
<ToggleSwitch
|
||||
on={admin.enabled}
|
||||
label={t('mailAdmin.enabled')}
|
||||
disabled={!admin.loaded}
|
||||
onToggle={() => admin.toggle(!admin.enabled)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SettingRows>
|
||||
{admin.enabled && admin.form && <Setup admin={admin} form={admin.form} t={t} locale={locale} />}
|
||||
</SettingsCard>
|
||||
<>
|
||||
<AddonTile
|
||||
icon={<Mail size={15} />}
|
||||
name={name}
|
||||
description={`${t('mailAdmin.hint')} ${t('mailAdmin.enabledHint')}`}
|
||||
enabled={admin.enabled}
|
||||
trailing={
|
||||
<ToggleSwitch
|
||||
on={admin.enabled}
|
||||
label={t('mailAdmin.enabled')}
|
||||
disabled={!admin.loaded}
|
||||
onToggle={() => admin.toggle(!admin.enabled)}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{admin.enabled && admin.form && <AddonSetupRow label={t('mailAdmin.setup')} onOpen={() => setOpen(true)} />}
|
||||
</AddonTile>
|
||||
{open && admin.enabled && admin.form && (
|
||||
<AddonSetupDialog
|
||||
icon={<Mail size={20} strokeWidth={2} />}
|
||||
eyebrow={name}
|
||||
title={t('mailAdmin.setup')}
|
||||
sub={t('mailAdmin.hint')}
|
||||
onClose={() => setOpen(false)}
|
||||
>
|
||||
<Setup admin={admin} form={admin.form} t={t} locale={locale} />
|
||||
</AddonSetupDialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -78,17 +78,22 @@ function adminState(overrides: Partial<Admin> = {}, search: Partial<Admin['searc
|
||||
};
|
||||
}
|
||||
|
||||
function show(overrides: Partial<Admin> = {}, search: Partial<Admin['search']> = {}) {
|
||||
/** The panel as the Tours shelf shows it: a setup row, opened into its dialog unless asked not to. */
|
||||
function show(overrides: Partial<Admin> = {}, search: Partial<Admin['search']> = {}, { open = true } = {}) {
|
||||
const state = adminState(overrides, search);
|
||||
hook.usePaddleRegionsAdmin.mockReturnValue(state);
|
||||
return { state, ...render(<PaddleRegionsPanel />) };
|
||||
const view = render(
|
||||
<ul>
|
||||
<PaddleRegionsPanel />
|
||||
</ul>
|
||||
);
|
||||
if (open && state.toursOn) fireEvent.click(setupRow());
|
||||
return { state, ...view };
|
||||
}
|
||||
|
||||
/** The card's title row, where the number of regions sits beside the title. */
|
||||
function titleRow(): HTMLElement {
|
||||
const row = screen.getByRole('heading', { name: 'Paddle water data' }).parentElement;
|
||||
if (!row) throw new Error('no title row');
|
||||
return row;
|
||||
/** The shelf row that opens the dialog, where the count of requests or regions sits beside the title. */
|
||||
function setupRow(): HTMLElement {
|
||||
return screen.getAllByRole('button', { name: /^Paddle water data/ })[0];
|
||||
}
|
||||
|
||||
function rowOf(name: string): HTMLElement {
|
||||
@@ -100,7 +105,7 @@ function rowOf(name: string): HTMLElement {
|
||||
describe('PaddleRegionsPanel', () => {
|
||||
it('FE-ADMIN-PADDLEREG-001: renders nothing while the Tours addon is off', () => {
|
||||
const { container } = show({ toursOn: false, regions: [READY] });
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
expect(container.querySelector('ul')).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it('FE-ADMIN-PADDLEREG-002: shows the card with its hint, the attribution and the empty state', () => {
|
||||
@@ -110,7 +115,7 @@ describe('PaddleRegionsPanel', () => {
|
||||
expect(screen.getByText(EMPTY)).toBeInTheDocument();
|
||||
expect(screen.getByText(ATTRIBUTION)).toBeInTheDocument();
|
||||
// No count beside the title while there is no region.
|
||||
expect(titleRow()).toHaveTextContent(/^Paddle water data$/);
|
||||
expect(setupRow()).toHaveTextContent(/^Paddle water data$/);
|
||||
const search = screen.getByRole('searchbox', { name: 'Add a region' });
|
||||
expect(search).toBeEnabled();
|
||||
expect(search).toHaveAttribute('placeholder', 'Search Geofabrik, for example Oberpfalz');
|
||||
@@ -277,12 +282,31 @@ describe('PaddleRegionsPanel', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('FE-ADMIN-PADDLEREG-019: the title carries the number of regions', () => {
|
||||
it('FE-ADMIN-PADDLEREG-019: the setup row carries the open requests, else the number of regions', () => {
|
||||
show({ regions: [READY, WAITING, FAILED_FIRST] });
|
||||
expect(within(titleRow()).getByText('3')).toBeInTheDocument();
|
||||
expect(within(setupRow()).getByText('3')).toBeInTheDocument();
|
||||
expect(screen.getAllByTestId('paddle-region-row')).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('FE-ADMIN-PADDLEREG-019b: an open request outranks the region count, a declined one does not count', () => {
|
||||
const base = { bytes: 1, requested_by: 'elmo', requested_at: '2026-10-18T09:00:00Z' };
|
||||
show(
|
||||
{
|
||||
regions: [READY, WAITING],
|
||||
requests: [
|
||||
{ ...base, id: 'norway', name: 'Norway', reason: 'too_large', declined: true },
|
||||
{ ...base, id: 'saale', name: 'Saale', reason: 'limit', declined: false },
|
||||
],
|
||||
},
|
||||
{},
|
||||
{ open: false }
|
||||
);
|
||||
expect(within(setupRow()).getByText('1')).toBeInTheDocument();
|
||||
expect(within(setupRow()).queryByText('2')).toBeNull();
|
||||
// Closed until the row is opened.
|
||||
expect(screen.queryByRole('dialog')).toBeNull();
|
||||
});
|
||||
|
||||
it('FE-ADMIN-PADDLEREG-020: removing asks first, naming the region, and confirming hands it to the hook', () => {
|
||||
const { state } = show({ regions: [READY], removing: READY });
|
||||
const message = 'Oberpfalz and its obstacle data are removed. Paddle tours there then show no data.';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { PaddleRegion, PaddleRegionCatalogEntry } from '@trek/shared';
|
||||
import { Check, ChevronRight, Loader2, Plus, RefreshCw, Search, Trash2, Waves, WifiOff } from 'lucide-react';
|
||||
import { useId } from 'react';
|
||||
import { useId, useState } from 'react';
|
||||
import { useDateFormat } from '../../../hooks/useDateFormat';
|
||||
import { useTranslation } from '../../../i18n';
|
||||
import { formatDisplayDate } from '../../../utils/dateFormat';
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
SettingRows,
|
||||
SETTINGS_BUTTON,
|
||||
SETTINGS_ICON_BUTTON,
|
||||
SettingsCard,
|
||||
SettingsHint,
|
||||
StatusPill,
|
||||
} from '../../Settings/settingsKit';
|
||||
@@ -17,6 +16,8 @@ import { EditorField, INPUT } from '../../shared/dialogParts';
|
||||
import { fs } from '../../shared/DialogShell';
|
||||
import ErrorBoundary from '../../shared/ErrorBoundary';
|
||||
import { Tooltip } from '../../shared/Tooltip';
|
||||
import AddonSetupDialog from '../AddonSetupDialog';
|
||||
import AddonSetupRow from '../AddonSetupRow';
|
||||
import { AutoLoadSettings, AutoOriginPill, RequestList } from './PaddleAutoLoadParts';
|
||||
import { progressPercent, regionStatusTone } from './paddleRegionsModel';
|
||||
import { usePaddleRegionsAdmin } from './usePaddleRegionsAdmin';
|
||||
@@ -27,8 +28,10 @@ type Admin = ReturnType<typeof usePaddleRegionsAdmin>;
|
||||
* PAD-05A in the admin area: the regions TREK reads paddle obstacles for,
|
||||
* picked from Geofabrik's list, and (PAD-11C) how TREK loads the region of a
|
||||
* place a paddler plans in by itself, with the regions that wait for an admin.
|
||||
* The desktop admin shows this card under the addons while the Tours addon
|
||||
* is on; the phone has MAdminPaddleRegionsPanel on the same hook.
|
||||
* The desktop admin shows it as a row of the Tours addon that opens it as a
|
||||
* dialog while the addon is on; the row counts what waits for the admin (the
|
||||
* requests) or else the regions. The phone has MAdminPaddleRegionsPanel on
|
||||
* the same hook.
|
||||
*/
|
||||
export default function PaddleRegionsPanel() {
|
||||
return (
|
||||
@@ -41,14 +44,42 @@ export default function PaddleRegionsPanel() {
|
||||
function Panel() {
|
||||
const { t } = useTranslation();
|
||||
const admin = usePaddleRegionsAdmin();
|
||||
const [open, setOpen] = useState(false);
|
||||
if (!admin.toursOn) return null;
|
||||
const title = t('admin.paddleRegions.title');
|
||||
// A declined request no longer waits for anyone; only the open ones ask for a look.
|
||||
const waiting = admin.requests.filter((r) => !r.declined).length;
|
||||
const badge =
|
||||
waiting > 0 ? (
|
||||
<StatusPill tone="warning">{waiting}</StatusPill>
|
||||
) : admin.regions.length > 0 ? (
|
||||
<StatusPill>{admin.regions.length}</StatusPill>
|
||||
) : undefined;
|
||||
const close = () => setOpen(false);
|
||||
return (
|
||||
<SettingsCard
|
||||
icon={Waves}
|
||||
title={t('admin.paddleRegions.title')}
|
||||
hint={t('admin.paddleRegions.hint')}
|
||||
badge={admin.regions.length > 0 ? <StatusPill>{admin.regions.length}</StatusPill> : undefined}
|
||||
>
|
||||
<>
|
||||
<AddonSetupRow label={title} onOpen={() => setOpen(true)} badge={badge} />
|
||||
{open && (
|
||||
<AddonSetupDialog
|
||||
icon={<Waves size={20} strokeWidth={2} />}
|
||||
eyebrow={t('admin.addons.catalog.tours.name')}
|
||||
title={title}
|
||||
sub={t('admin.paddleRegions.hint')}
|
||||
onClose={close}
|
||||
blocked={admin.removing !== null}
|
||||
>
|
||||
<PanelBody admin={admin} />
|
||||
</AddonSetupDialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** What the dialog holds: the state of the list, the settings, the requests, the search and the regions. */
|
||||
function PanelBody({ admin }: { admin: Admin }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{admin.offline && (
|
||||
<p
|
||||
role="status"
|
||||
@@ -86,7 +117,7 @@ function Panel() {
|
||||
message={t('admin.paddleRegions.removeMessage', { name: admin.removing?.name ?? '' })}
|
||||
confirmLabel={t('common.remove')}
|
||||
/>
|
||||
</SettingsCard>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import MAdminSchoolHolidayCatalog from './MAdminSchoolHolidayCatalog'
|
||||
import MAdminPaddleRegionsPanel from './MAdminPaddleRegionsPanel'
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
ArrowUp,
|
||||
@@ -246,10 +245,17 @@ export default function MAdmin() {
|
||||
onToggleBagTracking={toggleBagTracking}
|
||||
collabFeatures={collabFeatures}
|
||||
onToggleCollabFeature={toggleCollabFeature}
|
||||
// Live flight status and the booking mail import are rows of the addon groups,
|
||||
// and the paddle water data a row under Tours (desktop parity).
|
||||
flightLive={{
|
||||
on: admin.flightLive,
|
||||
locked: admin.flightLiveLocked,
|
||||
managed: !!managed,
|
||||
onToggle: () =>
|
||||
void admin.handleToggleAuthSetting('flight_live_enabled', !admin.flightLive, admin.setFlightLive),
|
||||
}}
|
||||
mailImport={!managed}
|
||||
/>
|
||||
{/* How the integrations reach the world (live flights, booking mails), beside the addons they serve. */}
|
||||
<MAdminSettingsSection admin={admin} t={t} part="features" />
|
||||
<MAdminPaddleRegionsPanel />
|
||||
</div>
|
||||
)}
|
||||
{activeTab === 'plugins' && <MAdminPluginsPanel />}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useTranslation } from '../../../i18n'
|
||||
import { useIsDark } from '../../../hooks/useIsDark'
|
||||
import {
|
||||
Puzzle, ListChecks, Wallet, FileText, CalendarDays, Globe, Briefcase, Image, Terminal, Link2, Compass, BookOpen,
|
||||
Sparkles, Luggage, Plane, Bookmark, Users, Mountain, CarFront, Settings2, ChevronRight,
|
||||
Sparkles, Luggage, Plane, Bookmark, Users, Mountain, CarFront, Radar,
|
||||
} from 'lucide-react'
|
||||
import DawarichIcon from '../../../components/shared/DawarichIcon'
|
||||
import AirTrailIcon from '../../../components/shared/AirTrailIcon'
|
||||
@@ -21,7 +21,10 @@ import AiSettingsDialog from '../../../components/Admin/addons/AiAdminConfig'
|
||||
import { AI_ADDON_ICONS, type AiAddonId } from '../../../components/Admin/addons/aiAddons'
|
||||
import { useAiAddonTile } from '../../../components/Admin/addons/useAiAddonTile'
|
||||
import { ImmichIcon, SynologyIcon } from '../../../components/Admin/addons/PhotoProviderIcons'
|
||||
import { MAdminCard } from './MAdminUi'
|
||||
import { MAdminCard, MAdminOptionRow, MAdminSetupRow } from './MAdminUi'
|
||||
import MAdminPaddleRegionsPanel from './MAdminPaddleRegionsPanel'
|
||||
import MMailIngestAdminCard from './MMailIngestAdminCard'
|
||||
import type { FlightLiveOption } from '../../../components/Admin/AddonManager'
|
||||
import MHintLabel from '../../components/MHintLabel'
|
||||
import WandererMark from '../../../components/Tours/wanderer/WandererMark'
|
||||
import MSkeleton from '../../components/MSkeleton'
|
||||
@@ -59,7 +62,16 @@ function AddonIcon({ name, size = 18, enabled = true }: AddonIconProps) {
|
||||
return <Icon size={size} />
|
||||
}
|
||||
|
||||
export default function MAdminAddonManager({ bagTrackingEnabled, onToggleBagTracking, collabFeatures, onToggleCollabFeature }: { bagTrackingEnabled?: boolean; onToggleBagTracking?: () => void; collabFeatures?: CollabFeatures; onToggleCollabFeature?: (key: string) => void }) {
|
||||
export default function MAdminAddonManager({ bagTrackingEnabled, onToggleBagTracking, collabFeatures, onToggleCollabFeature, flightLive, mailImport = false }: {
|
||||
bagTrackingEnabled?: boolean
|
||||
onToggleBagTracking?: () => void
|
||||
collabFeatures?: CollabFeatures
|
||||
onToggleCollabFeature?: (key: string) => void
|
||||
/** Live flight status, a row of the trip group (desktop parity). */
|
||||
flightLive?: FlightLiveOption
|
||||
/** Booking mail import, a row of the integration group with its setup sheet; off on a managed install. */
|
||||
mailImport?: boolean
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const dark = useIsDark()
|
||||
const {
|
||||
@@ -98,7 +110,7 @@ export default function MAdminAddonManager({ bagTrackingEnabled, onToggleBagTrac
|
||||
) : (
|
||||
<>
|
||||
{/* Trip Addons */}
|
||||
{tripAddons.length > 0 && (
|
||||
{(tripAddons.length > 0 || flightLive) && (
|
||||
<MAdminCard>
|
||||
<MGroupHead icon={Briefcase} label={t('admin.addons.type.trip')} hint={t('admin.addons.tripHint')} />
|
||||
{tripAddons.map((addon, i) => (
|
||||
@@ -135,6 +147,7 @@ export default function MAdminAddonManager({ bagTrackingEnabled, onToggleBagTrac
|
||||
onToggle={() => void toggle()}
|
||||
/>
|
||||
))}
|
||||
<MAdminPaddleRegionsPanel />
|
||||
</>
|
||||
)}
|
||||
{addon.id === 'collab' && addon.enabled && collabFeatures && onToggleCollabFeature && (
|
||||
@@ -153,6 +166,7 @@ export default function MAdminAddonManager({ bagTrackingEnabled, onToggleBagTrac
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{flightLive && <MFlightLiveRow option={flightLive} first={tripAddons.length === 0} />}
|
||||
</MAdminCard>
|
||||
)}
|
||||
|
||||
@@ -171,13 +185,14 @@ export default function MAdminAddonManager({ bagTrackingEnabled, onToggleBagTrac
|
||||
)}
|
||||
|
||||
{/* Integration Addons, headed by the AI ones as one group, as on the desktop */}
|
||||
{(integrationAddons.length > 0 || aiAddons.length > 0) && (
|
||||
{(integrationAddons.length > 0 || aiAddons.length > 0 || mailImport) && (
|
||||
<MAdminCard>
|
||||
<MGroupHead icon={Link2} label={t('admin.addons.type.integration')} hint={t('admin.addons.integrationHint')} />
|
||||
{aiAddons.length > 0 && <MAiAddons addons={aiAddons} onToggle={handleToggle} />}
|
||||
{integrationAddons.map((addon, i) => (
|
||||
<MAddonRow key={addon.id} addon={addon} onToggle={handleToggle} t={t} first={i === 0 && aiAddons.length === 0} />
|
||||
))}
|
||||
{mailImport && <MMailIngestAdminCard first={integrationAddons.length === 0 && aiAddons.length === 0} />}
|
||||
</MAdminCard>
|
||||
)}
|
||||
</>
|
||||
@@ -216,16 +231,28 @@ interface MAddonRowProps {
|
||||
function MAddonRow({ addon, onToggle, t, first }: MAddonRowProps) {
|
||||
const label = getAddonLabel(t, addon)
|
||||
return (
|
||||
<div className={`flex items-center gap-3 py-[11px] ${first ? '' : 'border-t border-[color:var(--m-rowbr)]'}`}>
|
||||
{/* overflow-hidden so a brand mark that fills the slot keeps its rounded corners. */}
|
||||
<span className="flex h-[38px] w-[38px] flex-none items-center justify-center overflow-hidden rounded-[11px] bg-[color:var(--m-ic)] text-m-ink">
|
||||
<AddonIcon name={addon.icon} size={18} enabled={addon.enabled} />
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<MHintLabel label={label.name} hint={label.description} />
|
||||
</div>
|
||||
<MToggle checked={addon.enabled} ariaLabel={label.name} onChange={() => onToggle(addon)} />
|
||||
</div>
|
||||
<MAdminOptionRow
|
||||
icon={<AddonIcon name={addon.icon} size={18} enabled={addon.enabled} />}
|
||||
title={label.name}
|
||||
hint={label.description}
|
||||
first={first}
|
||||
trailing={<MToggle checked={addon.enabled} ariaLabel={label.name} onChange={() => onToggle(addon)} />}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/** Live flight status as a trip row, locked with a word when the server environment holds it. */
|
||||
function MFlightLiveRow({ option, first }: { option: FlightLiveOption; first: boolean }) {
|
||||
const { t } = useTranslation()
|
||||
const hint = option.managed ? t('flightLive.adminHintManaged') : t('flightLive.adminHint')
|
||||
return (
|
||||
<MAdminOptionRow
|
||||
icon={<Radar size={18} />}
|
||||
title={t('flightLive.adminTitle')}
|
||||
hint={option.locked ? `${hint} ${t('flightLive.envLocked')}` : hint}
|
||||
first={first}
|
||||
trailing={<MToggle checked={option.on} ariaLabel={t('flightLive.adminToggle')} disabled={option.locked} onChange={option.onToggle} />}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -301,17 +328,7 @@ function MAiAddons({ addons, onToggle }: { addons: Addon[]; onToggle: (addon: Ad
|
||||
/>
|
||||
)
|
||||
})}
|
||||
{tile.canSetUp && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={tile.openDialog}
|
||||
className="flex w-full items-center gap-3 border-t border-[color:var(--m-rowbr)] py-[11px] ps-[50px] text-start"
|
||||
>
|
||||
<Settings2 size={14} className="flex-none text-m-faint" />
|
||||
<span className="min-w-0 flex-1 truncate text-[0.75rem] font-bold text-m-ink">{t('admin.addons.ai.setup')}</span>
|
||||
<ChevronRight size={15} className="flex-none text-m-faint rtl:rotate-180" />
|
||||
</button>
|
||||
)}
|
||||
{tile.canSetUp && <MAdminSetupRow label={t('admin.addons.ai.setup')} onOpen={tile.openDialog} />}
|
||||
{tile.dialogOpen && <AiSettingsDialog addons={addons} onClose={tile.closeDialog} />}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
Waves,
|
||||
WifiOff,
|
||||
} from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
AUTO_LOAD_MODES,
|
||||
autoLoadSizes,
|
||||
@@ -28,8 +29,9 @@ import { useTranslation } from '../../../i18n';
|
||||
import { formatDisplayDate } from '../../../utils/dateFormat';
|
||||
import MBadge from '../../components/MBadge';
|
||||
import MChip from '../../components/MChip';
|
||||
import MSheet from '../../components/MSheet';
|
||||
import MConfirmSheet from '../settings/MConfirmSheet';
|
||||
import { MAdminButton, MAdminCard, MAdminClampedText } from './MAdminUi';
|
||||
import { MAdminButton, MAdminClampedText, MAdminSetupRow, MAdminSheetFrame } from './MAdminUi';
|
||||
|
||||
type Admin = ReturnType<typeof usePaddleRegionsAdmin>;
|
||||
|
||||
@@ -393,32 +395,49 @@ function Regions({ admin }: { admin: Admin }) {
|
||||
|
||||
/**
|
||||
* PAD-05A/PAD-11C on the phone: the regions TREK reads paddle data for, how it
|
||||
* loads a paddler's region by itself and the regions that wait for an admin.
|
||||
* usePaddleRegionsAdmin is the desktop card's state; this is only the markup.
|
||||
* loads a paddler's region by itself and the regions that wait for an admin, as
|
||||
* a row under the Tours addon that opens them in a sheet. The row counts the
|
||||
* open requests, else the regions. usePaddleRegionsAdmin is the desktop
|
||||
* dialog's state; this is only the markup.
|
||||
*/
|
||||
export default function MAdminPaddleRegionsPanel() {
|
||||
const { t } = useTranslation();
|
||||
const admin = usePaddleRegionsAdmin();
|
||||
const [open, setOpen] = useState(false);
|
||||
if (!admin.toursOn) return null;
|
||||
const title = t('admin.paddleRegions.title');
|
||||
// A declined request no longer waits for anyone; only the open ones ask for a look.
|
||||
const waiting = admin.requests.filter((r) => !r.declined).length;
|
||||
const badge =
|
||||
waiting > 0 ? (
|
||||
<MBadge caps={false} tone="strong">
|
||||
{waiting}
|
||||
</MBadge>
|
||||
) : admin.regions.length > 0 ? (
|
||||
<MBadge caps={false}>{admin.regions.length}</MBadge>
|
||||
) : undefined;
|
||||
return (
|
||||
<MAdminCard>
|
||||
<div className="flex items-start gap-3">
|
||||
<span className="flex h-[38px] w-[38px] flex-none items-center justify-center rounded-[11px] bg-[color:var(--m-ic)] text-m-ink">
|
||||
<Waves size={18} />
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 truncate text-[length:calc(14px*var(--fs-scale-body,1))] font-extrabold text-m-ink">
|
||||
{t('admin.paddleRegions.title')}
|
||||
</span>
|
||||
{admin.regions.length > 0 && <MBadge caps={false}>{admin.regions.length}</MBadge>}
|
||||
</div>
|
||||
<MAdminClampedText className="mt-[2px] text-[length:calc(10px*var(--fs-scale-caption,1))]">
|
||||
{t('admin.paddleRegions.hint')}
|
||||
</MAdminClampedText>
|
||||
</div>
|
||||
</div>
|
||||
<>
|
||||
<MAdminSetupRow label={title} onOpen={() => setOpen(true)} badge={badge} />
|
||||
{open && (
|
||||
<MSheet open onClose={() => setOpen(false)} variant="bottom" material="glass" ariaLabel={title}>
|
||||
<MAdminSheetFrame icon={<Waves size={19} strokeWidth={1.8} />} title={title} onClose={() => setOpen(false)}>
|
||||
<p className="m-0 font-geist text-[length:calc(10px*var(--fs-scale-caption,1))] leading-relaxed text-m-muted">
|
||||
{t('admin.paddleRegions.hint')}
|
||||
</p>
|
||||
<PanelBody admin={admin} />
|
||||
</MAdminSheetFrame>
|
||||
</MSheet>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** What the sheet holds: the state of the list, the settings, the requests, the search and the regions. */
|
||||
function PanelBody({ admin }: { admin: Admin }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<>
|
||||
{admin.offline && (
|
||||
<p
|
||||
role="status"
|
||||
@@ -462,6 +481,6 @@ export default function MAdminPaddleRegionsPanel() {
|
||||
danger
|
||||
onConfirm={admin.confirmRemove}
|
||||
/>
|
||||
</MAdminCard>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import type { useAdmin } from '../../../pages/admin/useAdmin'
|
||||
import MToggle from '../../components/MToggle'
|
||||
import { MBlockDisclosure, MProviderBlock, MTrekApiBlock } from './MApiProviderBlocks'
|
||||
import MAdminOidcCard from './MAdminOidcCard'
|
||||
import MMailIngestAdminCard from './MMailIngestAdminCard'
|
||||
import MAdminGoogleDailyLimit from './MAdminGoogleDailyLimit'
|
||||
import MAdminPlaceContrib from './MAdminPlaceContrib'
|
||||
import MAdminServiceQuota from './MAdminServiceQuota'
|
||||
@@ -27,41 +26,22 @@ interface MAdminSettingsSectionProps {
|
||||
t: TranslationFn
|
||||
/**
|
||||
* Which section this renders, cut the way the desktop tabs are: who may sign
|
||||
* in and what it takes (security), what the install talks to outside
|
||||
* (services), and the setup of the features the addons switch on (features).
|
||||
* in and what it takes (security) or what the install talks to outside
|
||||
* (services). Live flight status and the booking mail import are rows of the
|
||||
* addon groups (MAdminAddonManager).
|
||||
*/
|
||||
part: 'security' | 'services' | 'features'
|
||||
part: 'security' | 'services'
|
||||
}
|
||||
|
||||
type PartProps = Omit<MAdminSettingsSectionProps, 'part'>
|
||||
|
||||
// The admin's security, services and feature setup sections as phone cards,
|
||||
// The admin's security and services sections as phone cards,
|
||||
// one function each. All state and mutations come from useAdmin.
|
||||
export default function MAdminSettingsSection({ admin, t, part }: MAdminSettingsSectionProps) {
|
||||
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 {
|
||||
@@ -482,23 +462,3 @@ function ServicesPart({ admin, t }: PartProps) {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The live flight status switch, locked with a word when the server environment holds it. */
|
||||
function FlightLiveCard({ t, managed, on, locked, onChange }: {
|
||||
t: TranslationFn
|
||||
managed: boolean
|
||||
on: boolean
|
||||
locked: boolean
|
||||
onChange: (on: boolean) => void
|
||||
}) {
|
||||
return (
|
||||
<MAdminCard>
|
||||
<MAdminCardHead title={t('flightLive.adminTitle')} hint={managed ? t('flightLive.adminHintManaged') : t('flightLive.adminHint')} />
|
||||
<MAdminRow
|
||||
title={t('flightLive.adminToggle')}
|
||||
hint={locked ? t('flightLive.envLocked') : undefined}
|
||||
trailing={<MToggle checked={on} ariaLabel={t('flightLive.adminToggle')} disabled={locked} onChange={onChange} />}
|
||||
/>
|
||||
</MAdminCard>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { InputHTMLAttributes, ReactNode, useState } from 'react'
|
||||
import { ChevronDown, Eye, EyeOff, Loader2, X } from 'lucide-react'
|
||||
import { ChevronDown, ChevronRight, Eye, EyeOff, Loader2, Settings2, X } from 'lucide-react'
|
||||
import { useTranslation } from '../../../i18n'
|
||||
import MIconBtn from '../../components/MIconBtn'
|
||||
import MHintLabel from '../../components/MHintLabel'
|
||||
@@ -61,6 +61,58 @@ export function MAdminRow({
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A row of the addons screen: the icon tile, the name with its description
|
||||
* behind the info mark, and the switch. Addons and the instance options that
|
||||
* sit with them (live flight status, booking mails) share it.
|
||||
*/
|
||||
export function MAdminOptionRow({
|
||||
icon,
|
||||
title,
|
||||
hint,
|
||||
trailing,
|
||||
first = false,
|
||||
}: {
|
||||
icon: ReactNode
|
||||
title: string
|
||||
hint?: string
|
||||
trailing: ReactNode
|
||||
first?: boolean
|
||||
}) {
|
||||
return (
|
||||
<div className={`flex items-center gap-3 py-[11px] ${first ? '' : 'border-t border-[color:var(--m-rowbr)]'}`}>
|
||||
{/* overflow-hidden so a brand mark that fills the slot keeps its rounded corners. */}
|
||||
<span className="flex h-[38px] w-[38px] flex-none items-center justify-center overflow-hidden rounded-[11px] bg-[color:var(--m-ic)] text-m-ink">
|
||||
{icon}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<MHintLabel label={title} hint={hint} />
|
||||
</div>
|
||||
{trailing}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The last row under an addon that opens its settings: a gear, what it sets up,
|
||||
* an optional badge for what waits inside, and a chevron (AI, booking mails,
|
||||
* paddle water data).
|
||||
*/
|
||||
export function MAdminSetupRow({ label, onOpen, badge }: { label: string; onOpen: () => void; badge?: ReactNode }) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpen}
|
||||
className="flex w-full items-center gap-3 border-t border-[color:var(--m-rowbr)] py-[11px] ps-[50px] text-start"
|
||||
>
|
||||
<Settings2 size={14} 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">{label}</span>
|
||||
{badge}
|
||||
<ChevronRight size={15} className="flex-none text-m-faint rtl:rotate-180" />
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A description that keeps to two lines until it is tapped. On a phone the long
|
||||
* ones (a map provider's terms, how a loader decides) pushed every control off
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Inbox, Upload, Webhook, type LucideIcon } from 'lucide-react';
|
||||
import { Inbox, Mail, Upload, Webhook, type LucideIcon } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
TRANSPORTS,
|
||||
problemText,
|
||||
@@ -15,15 +16,16 @@ import { useTranslation } from '../../../i18n';
|
||||
import type { TranslationFn } from '../../../types';
|
||||
import { relativeTime } from '../../../utils/relativeTime';
|
||||
import MSegmented from '../../components/MSegmented';
|
||||
import MSheet from '../../components/MSheet';
|
||||
import MToggle from '../../components/MToggle';
|
||||
import {
|
||||
MAdminButton,
|
||||
MAdminCard,
|
||||
MAdminCardHead,
|
||||
MAdminField,
|
||||
MAdminInput,
|
||||
MAdminRow,
|
||||
MAdminOptionRow,
|
||||
MAdminSecretInput,
|
||||
MAdminSetupRow,
|
||||
MAdminSheetFrame,
|
||||
} from './MAdminUi';
|
||||
|
||||
interface PartProps {
|
||||
@@ -250,19 +252,23 @@ function Setup({ admin, form, t, locale }: PartProps & { locale: string }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The booking mail import in the phone's admin settings, the same card as on
|
||||
* the desktop (useMailIngestAdmin): the switch, how mail arrives, the address
|
||||
* template, the AI allowance, the test and the status. Self-hosted only.
|
||||
* The booking mail import as a row of the phone's integration group, the same
|
||||
* as on the desktop (useMailIngestAdmin): the switch, and while it is on a row
|
||||
* to the sheet that sets it up (how mail arrives, the address template, the AI
|
||||
* allowance, the test and the status). Self-hosted only.
|
||||
*/
|
||||
export default function MMailIngestAdminCard() {
|
||||
export default function MMailIngestAdminCard({ first = false }: { first?: boolean }) {
|
||||
const { t, locale } = useTranslation();
|
||||
const admin = useMailIngestAdmin(true);
|
||||
const [open, setOpen] = useState(false);
|
||||
const setupLabel = t('mailAdmin.setup');
|
||||
return (
|
||||
<MAdminCard>
|
||||
<MAdminCardHead title={t('mailAdmin.title')} hint={t('mailAdmin.hint')} />
|
||||
<MAdminRow
|
||||
title={t('mailAdmin.enabled')}
|
||||
hint={t('mailAdmin.enabledHint')}
|
||||
<>
|
||||
<MAdminOptionRow
|
||||
icon={<Mail size={18} />}
|
||||
title={t('mailAdmin.title')}
|
||||
hint={`${t('mailAdmin.hint')} ${t('mailAdmin.enabledHint')}`}
|
||||
first={first}
|
||||
trailing={
|
||||
<MToggle
|
||||
checked={admin.enabled}
|
||||
@@ -272,7 +278,18 @@ export default function MMailIngestAdminCard() {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{admin.enabled && admin.form && <Setup admin={admin} form={admin.form} t={t} locale={locale} />}
|
||||
</MAdminCard>
|
||||
{admin.enabled && admin.form && <MAdminSetupRow label={setupLabel} onOpen={() => setOpen(true)} />}
|
||||
{open && admin.enabled && admin.form && (
|
||||
<MSheet open onClose={() => setOpen(false)} variant="bottom" material="glass" ariaLabel={setupLabel}>
|
||||
<MAdminSheetFrame
|
||||
icon={<Mail size={19} strokeWidth={1.8} />}
|
||||
title={setupLabel}
|
||||
onClose={() => setOpen(false)}
|
||||
>
|
||||
<Setup admin={admin} form={admin.form} t={t} locale={locale} />
|
||||
</MAdminSheetFrame>
|
||||
</MSheet>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@ vi.mock('../components/Admin/BackupPanel', () => ({
|
||||
vi.mock('../components/Admin/GitHubPanel', () => ({
|
||||
default: () => <div data-testid="github-panel" />,
|
||||
}));
|
||||
vi.mock('../components/Admin/paddle/PaddleRegionsPanel', () => ({
|
||||
default: () => <div data-testid="paddle-regions-panel" />,
|
||||
}));
|
||||
|
||||
// AddonManager is stubbed but keeps its two callbacks reachable — the page owns
|
||||
// the optimistic toggle logic behind them.
|
||||
@@ -225,8 +222,6 @@ describe('AdminPage', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: /^addons$/i }));
|
||||
|
||||
expect(screen.getByTestId('addon-manager')).toBeInTheDocument();
|
||||
// The paddle water data sit under the addons; the panel hides itself while Tours is off.
|
||||
expect(screen.getByTestId('paddle-regions-panel')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import SchoolHolidayCatalog from '../components/Admin/SchoolHolidayCatalog'
|
||||
import PaddleRegionsPanel from '../components/Admin/paddle/PaddleRegionsPanel'
|
||||
import React, { Fragment } from 'react'
|
||||
import DevNotificationsPanel from '../components/Admin/DevNotificationsPanel'
|
||||
import DefaultUserSettingsTab from '../components/Admin/DefaultUserSettingsTab'
|
||||
@@ -166,10 +165,17 @@ function AdminPageDesktop(): React.ReactElement {
|
||||
onToggleBagTracking={toggleBagTracking}
|
||||
collabFeatures={collabFeatures}
|
||||
onToggleCollabFeature={toggleCollabFeature}
|
||||
// How the integrations reach the world: live flight status, booking mails.
|
||||
aside={<AdminSettingsTab admin={admin} t={t} part="features" />}
|
||||
// Live flight status follows the trips' flights; the booking mail import is
|
||||
// the operator's relay on a managed install.
|
||||
flightLive={{
|
||||
on: admin.flightLive,
|
||||
locked: admin.flightLiveLocked,
|
||||
managed,
|
||||
onToggle: () =>
|
||||
void admin.handleToggleAuthSetting('flight_live_enabled', !admin.flightLive, admin.setFlightLive),
|
||||
}}
|
||||
mailImport={!managed}
|
||||
/>
|
||||
<PaddleRegionsPanel />
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -13,13 +13,12 @@ import AdminSettingsTab from './AdminSettingsTab';
|
||||
type Spy = ReturnType<typeof vi.fn>;
|
||||
type Spies = Record<string, Spy> & { toast: Record<string, Spy> };
|
||||
|
||||
/** The three tabs the settings are split into (security, services, features), on one page. */
|
||||
/** The two tabs the settings are split into (security, services), on one page. */
|
||||
function AllParts({ admin, t }: { admin: AdminHook; t: ReturnType<typeof useTranslation>['t'] }) {
|
||||
return (
|
||||
<>
|
||||
<AdminSettingsTab admin={admin} t={t} part="security" />
|
||||
<AdminSettingsTab admin={admin} t={t} part="services" />
|
||||
<AdminSettingsTab admin={admin} t={t} part="features" />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import {
|
||||
AlertTriangle, CheckCircle, Compass, Eye, EyeOff, FileType, Fingerprint, KeyRound, Loader2, LockKeyhole, LogIn,
|
||||
Plane, RefreshCw, Save, XCircle,
|
||||
RefreshCw, Save, XCircle,
|
||||
} from 'lucide-react'
|
||||
import ToggleSwitch from '../../components/Settings/ToggleSwitch'
|
||||
import CustomSelect from '../../components/shared/CustomSelect'
|
||||
@@ -14,7 +14,6 @@ import GoogleOptions from './GoogleOptions'
|
||||
import GoogleDailyLimitRow from '../../components/Admin/GoogleDailyLimitRow'
|
||||
import ProviderBlock from './ProviderBlock'
|
||||
import TrekApiCard from './TrekApiCard'
|
||||
import MailIngestAdminCard from '../../components/Admin/mailIngest/MailIngestAdminCard'
|
||||
import PlaceContribPanel from '../../components/Admin/PlaceContribPanel'
|
||||
import { useAdminSettingsActions } from '../../components/Admin/useAdminSettingsActions'
|
||||
import { placesGoogleOnlyHint } from '../../utils/placeSource'
|
||||
@@ -25,11 +24,10 @@ interface AdminSettingsTabProps {
|
||||
admin: ReturnType<typeof useAdmin>
|
||||
t: TranslationFn
|
||||
/**
|
||||
* Which tab this renders: sign-in and its safety (security), what the
|
||||
* install talks to outside (services), or the setup of the features the
|
||||
* addons tab switches on (features).
|
||||
* Which tab this renders: sign-in and its safety (security) or what the
|
||||
* install talks to outside (services).
|
||||
*/
|
||||
part: 'security' | 'services' | 'features'
|
||||
part: 'security' | 'services'
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +124,6 @@ export default function AdminSettingsTab({ admin, t, part }: AdminSettingsTabPro
|
||||
oidcConfig, setOidcConfig, savingOidc,
|
||||
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,
|
||||
@@ -395,34 +392,6 @@ export default function AdminSettingsTab({ admin, t, part }: AdminSettingsTabPro
|
||||
)}
|
||||
</>
|
||||
)
|
||||
const flightCard = (
|
||||
<>
|
||||
{/* Live flight status: open ADS-B data, no key, on by default; the admin may keep it off. */}
|
||||
<SettingsCard icon={Plane} title={t('flightLive.adminTitle')} hint={managed ? t('flightLive.adminHintManaged') : t('flightLive.adminHint')}>
|
||||
<SettingRows>
|
||||
<SettingRow
|
||||
label={t('flightLive.adminToggle')}
|
||||
hint={flightLiveLocked ? t('flightLive.envLocked') : undefined}
|
||||
control={
|
||||
<ToggleSwitch
|
||||
on={flightLive}
|
||||
label={t('flightLive.adminToggle')}
|
||||
disabled={flightLiveLocked}
|
||||
onToggle={() => void handleToggleAuthSetting('flight_live_enabled', !flightLive, setFlightLive)}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SettingRows>
|
||||
</SettingsCard>
|
||||
</>
|
||||
)
|
||||
const mailCard = (
|
||||
<>
|
||||
{/* Booking mail import: how forwarded booking mails reach this install. On a managed
|
||||
install the operator runs the TREK Cloud relay, so the card is not shown there. */}
|
||||
{!managed && <MailIngestAdminCard />}
|
||||
</>
|
||||
)
|
||||
const servicesCard = (
|
||||
<>
|
||||
{/* Place search and routing: TREK's own services first, then which provider
|
||||
@@ -714,16 +683,9 @@ export default function AdminSettingsTab({ admin, t, part }: AdminSettingsTabPro
|
||||
)
|
||||
|
||||
// What used to be one "Settings" tab, split by what an admin comes for:
|
||||
// who may sign in and how (security), what the install talks to outside
|
||||
// (services), and how the features in the addons tab are set up there.
|
||||
if (part === 'features') {
|
||||
return (
|
||||
<>
|
||||
{flightCard}
|
||||
{mailCard}
|
||||
</>
|
||||
)
|
||||
}
|
||||
// who may sign in and how (security) and what the install talks to outside
|
||||
// (services). Live flight status and the booking mail import are rows of the
|
||||
// addons tab's cards now.
|
||||
if (part === 'services') {
|
||||
// Place search and the services on the left, the keys and file types on the right.
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user