Files
TREK/client/src/mobile/screens/admin/MAdmin.tsx
T
Maurice 0b7cee0b0d feat(mobile): the trip's tabs, administration, collections and the journal use the large screen
On an iPad or an unfolded foldable the list screens kept one phone-wide
column in the middle of the page. They now lay out for the room they have:

- Transports, bookings, polls and tasks put their cards in a grid of as many
  phone-wide columns as the page holds (CardGrid), three on a 13" iPad on
  its side, two upright, one in a narrow Split View.
- Costs: with room for two panes (split size class) the summary (total,
  owe and owed, settle up, final budget, categories) stands in a pane of its
  own beside the expenses, each scrolling on its own (TabPanes). The search
  field sits in the expenses' column again instead of running past it.
- Files: a grid of tiles with each photo's picture; with room for two panes
  the picked file is previewed beside the grid with what it belongs to and
  its actions, the way Files on an iPad does. The signed preview address
  comes through fileRepo.previewUrl.
- Packing: the categories stand in columns, each card whole in its column;
  the action menu drops from its button at a popover's width.
- To-dos: the four smart filters as tiles and the trip's lists in a pane
  beside the tasks, which take the filter's name as their head.
- Collab: the chat stays in view at the trailing edge beside the notes,
  links or polls, and the header switches only the board. The chat keeps its
  place in the tree, so a fold or a rotation into two panes keeps the draft;
  a chat at its newest message stays there when its box changes size. Notes
  stand as a board in columns.
- Administration and settings share a section list beside the page
  (MSectionNav); the stats grid takes four columns.
- Collections: the lists stand in a column beside the places, which take two
  columns, and the head names the list on show.
- Journal: the entries become a feed beside the map, under their days, with
  photo, place and the start of the story, in step with the map like the
  strip of cards it replaces; it fades out under the header.
- The assistant opens as a tall panel at the trailing edge over a dimmed
  page, as Slide Over would, instead of covering the whole screen.
- The rail fits every name: a word too wide for it shrinks the label before
  it is hyphenated, and the admin entry uses its short name.
- The journeys and notifications headers keep to their column.
- The address screen of the native shell sets the photo as a panel beside
  the choices on a large screen on its side.

On a foldable that reports its fold, a leading pane ends at the fold and a
trailing one starts there. Phones keep their layout.
2026-11-07 23:25:12 +01:00

266 lines
12 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import MAdminSchoolHolidayCatalog from './MAdminSchoolHolidayCatalog'
import MAdminPaddleRegionsPanel from './MAdminPaddleRegionsPanel'
import { useState } from 'react'
import {
ArrowUp,
Bell,
Blocks,
Briefcase,
Bug,
ChevronDown,
ChevronLeft,
Database,
FileText,
Github,
HardDrive,
Map,
Plug,
Puzzle,
ScrollText,
Settings as SettingsIcon,
Shield,
SlidersHorizontal,
UserCog,
UserPlus,
Users,
} from 'lucide-react'
import type { LucideIcon } from 'lucide-react'
import { useTranslation } from '../../../i18n'
import { useCountUp } from '../../../hooks/useCountUp'
import { useAdmin } from '../../../pages/admin/useAdmin'
import MAdminAddonManager from './MAdminAddonManager'
import MAdminMcpTokensPanel from './MAdminMcpTokensPanel'
import MAdminPluginsPanel from './MAdminPluginsPanel'
import MAdminAuditLogPanel from './MAdminAuditLogPanel'
import MAdminBackupPanel from './MAdminBackupPanel'
import MAdminCategoryManager from './MAdminCategoryManager'
import MAdminDefaultUserSettings from './MAdminDefaultUserSettings'
import MAdminDevNotificationsPanel from './MAdminDevNotificationsPanel'
import MAdminGitHubPanel from './MAdminGitHubPanel'
import MAdminPackingTemplateManager from './MAdminPackingTemplateManager'
import MAdminNotificationsSection from './MAdminNotificationsSection'
import MAdminSettingsSection from './MAdminSettingsSection'
import MAdminSheets from './MAdminSheets'
import MAdminStoragePanel from './MAdminStoragePanel'
import MAdminUsersSection from './MAdminUsersSection'
import { MAdminButton } from './MAdminUi'
import { managedAdminTabs } from '../../../managed'
import { useIsSplit } from '../../../hooks/sizeClass'
import MSectionNav, { MSectionRow, type MSection } from '../../components/MSectionNav'
// Stat card of the 2×2 grid (design §6.3): 34px icon tile, 19px/800 number,
// small tracking label. Count-up animation matches the desktop stat cards.
function MAdminStat({ label, value, icon: Icon }: { label: string; value: number; icon: LucideIcon }) {
const animated = useCountUp(value, 900)
return (
<div className="flex items-center gap-[11px] rounded-2xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-sheetop)] px-[14px] py-[13px]">
<span className="flex h-[34px] w-[34px] flex-none items-center justify-center rounded-[11px] bg-[color:var(--m-ic)] text-m-ink">
<Icon size={16} strokeWidth={2} />
</span>
<div>
<div className="text-[1.1875rem] font-extrabold leading-none text-m-ink">{animated}</div>
<div className="mt-[2px] font-geist text-[0.59375rem] font-bold tracking-[0.06em] text-m-faint">{label}</div>
</div>
</div>
)
}
/**
* Mobile admin screen (design §6): section switcher pill with the 11-entry
* dropdown, update banner, stats grid and the users section; every other
* desktop admin section stays reachable through the dropdown.
*/
export default function MAdmin() {
const { t, locale } = useTranslation()
const admin = useAdmin()
const {
demoMode, mcpEnabled, devMode, managed, navigate,
activeTab, setActiveTab, stats, serverTimezone,
bagTrackingEnabled, collabFeatures,
setShowCreateUser,
updateInfo, setShowUpdateModal,
saveDemoBaseline, toggleBagTracking, toggleCollabFeature,
} = admin
const [sectionsOpen, setSectionsOpen] = useState(false)
// With room for two panes the sections stand in a list beside the page, as in
// settings, instead of behind the header's dropdown.
const split = useIsSplit()
// Same sections and gating as the desktop sidebar, ordered and iconed like
// the design's dropdown (§6.1).
const sections: MSection[] = [
{ id: 'users', label: t('admin.tabs.users'), icon: Users },
{ id: 'defaults', label: t('admin.tabs.defaults'), icon: UserCog },
{ id: 'config', label: t('admin.tabs.config'), icon: SlidersHorizontal },
{ id: 'settings', label: t('admin.tabs.settings'), icon: SettingsIcon },
{ id: 'addons', label: t('admin.tabs.addons'), icon: Blocks },
...(managed ? [] : [{ id: 'plugins', label: t('admin.tabs.plugins'), icon: Puzzle }]),
...(managed ? [] : [{ id: 'storage', label: t('admin.tabs.storage'), icon: HardDrive }]),
{ id: 'notifications', label: t('admin.tabs.notifications'), icon: Bell },
...(mcpEnabled ? [{ id: 'mcp-tokens', label: t('admin.tabs.mcpTokens'), icon: Plug }] : []),
// Same two the desktop list drops: releases and backup schedule belong to
// whoever operates the install.
...(managed ? [] : [{ id: 'github', label: t('admin.tabs.github'), icon: Github }]),
...(managed ? [] : [{ id: 'backup', label: t('admin.tabs.backup'), icon: Database }]),
{ id: 'audit', label: t('admin.tabs.audit'), icon: ScrollText },
...(devMode ? [{ id: 'dev-notifications', label: 'Dev: Notifications', icon: Bug }] : []),
// The install's own tabs (managed/index.tsx), after the built-in ones as on the desktop.
...managedAdminTabs.map(tab => ({ id: tab.id, label: tab.label, icon: tab.Icon })),
]
const activeSection = sections.find((s) => s.id === activeTab) ?? sections[0]
return (
// Flow screen: scrolls with the document (#1809), so no height and no
// scroll container of its own.
<div className="px-4 pb-[calc(var(--bottom-nav-h,84px)+16px)] pt-[var(--m-safe-top,12px)] wide:mx-auto wide:max-w-[1040px] wide:px-6 split:grid split:max-w-[1240px] split:grid-cols-[260px_minmax(0,1fr)] split:items-start split:gap-8">
{split && (
<MSectionNav
title={t('admin.title')}
backLabel={t('common.back')}
onBack={() => void navigate('/dashboard')}
sections={sections}
activeId={activeSection.id}
onPick={setActiveTab}
action={
<button
type="button"
aria-label={t('admin.createUser')}
onClick={() => setShowCreateUser(true)}
className="flex h-[34px] w-[34px] flex-none items-center justify-center rounded-full bg-m-act text-m-actfg outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--m-act)] focus-visible:ring-offset-2"
>
<UserPlus size={15} strokeWidth={2.2} />
</button>
}
/>
)}
<div className="min-w-0">
{/* Header: back · section switcher · create user */}
{!split && (
<div className="mb-3 flex items-center gap-2">
<button
type="button"
aria-label={t('common.back')}
onClick={() => navigate('/dashboard')}
className="flex h-[38px] w-[38px] flex-none items-center justify-center rounded-full border border-[color:var(--m-gbr)] bg-[color:var(--m-sheet)] text-m-ink shadow-[0_5px_12px_-8px_rgba(0,0,0,.18)]"
>
<ChevronLeft size={18} strokeWidth={2.2} />
</button>
<button
type="button"
aria-label={t('admin.title')}
aria-expanded={sectionsOpen}
onClick={() => setSectionsOpen((v) => !v)}
className="flex h-[38px] min-w-0 flex-1 items-center gap-[7px] rounded-full border border-[color:var(--m-gbr)] bg-[color:var(--m-sheet)] px-[14px] text-[0.8125rem] font-bold text-m-ink shadow-[0_5px_12px_-8px_rgba(0,0,0,.18)]"
>
<Shield size={14} strokeWidth={2.2} className="flex-none" />
<span className="min-w-0 flex-1 truncate text-start">{activeSection.label}</span>
<ChevronDown size={13} strokeWidth={2} className="flex-none text-m-faint" />
</button>
<button
type="button"
aria-label={t('admin.createUser')}
onClick={() => setShowCreateUser(true)}
className="flex h-[38px] w-[38px] flex-none items-center justify-center rounded-full bg-m-act text-m-actfg shadow-[0_5px_12px_-8px_rgba(0,0,0,.3)]"
>
<UserPlus size={16} strokeWidth={2.2} />
</button>
</div>
)}
{/* Section dropdown */}
{sectionsOpen && !split && (
<div className="-mt-[6px] mb-3 rounded-2xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-sheetop)] p-[6px] shadow-[0_16px_40px_-20px_rgba(0,0,0,.4)]">
{sections.map((section) => (
<MSectionRow
key={section.id}
section={section}
active={section.id === activeSection.id}
onPick={() => {
setActiveTab(section.id)
setSectionsOpen(false)
}}
/>
))}
</div>
)}
{/* Update banner (§6.2) — real update check, shown on every section */}
{updateInfo && (
<div className="mb-3 flex items-center gap-[10px] rounded-2xl border border-[color:color-mix(in_srgb,var(--m-st-pending)_28%,transparent)] bg-[color:color-mix(in_srgb,var(--m-st-pending)_10%,transparent)] px-[14px] py-3">
<span className="flex h-[34px] w-[34px] flex-none items-center justify-center rounded-full bg-[color:var(--m-st-pending)] text-white">
<ArrowUp size={17} strokeWidth={2.4} />
</span>
<div className="min-w-0 flex-1">
<div className="text-[0.78125rem] font-extrabold text-m-ink">{t('admin.update.available')}</div>
<div className="font-geist text-[0.625rem] text-m-muted">
{t('mobileAdmin.updateLine', { version: `v${updateInfo.latest}`, current: `v${updateInfo.current}` })}
</div>
</div>
<MAdminButton onClick={() => setShowUpdateModal(true)}>{t('mobileAdmin.updateAction')}</MAdminButton>
</div>
)}
{/* Demo baseline (demo instances only) */}
{demoMode && (
<div className="mb-3 flex items-center gap-[10px] rounded-2xl border border-[color:color-mix(in_srgb,var(--m-st-pending)_28%,transparent)] bg-[color:color-mix(in_srgb,var(--m-st-pending)_10%,transparent)] px-[14px] py-3">
<div className="min-w-0 flex-1">
<div className="text-[0.78125rem] font-extrabold text-m-ink">{t('admin.demoBaseline.title')}</div>
<div className="font-geist text-[0.625rem] leading-relaxed text-m-muted">
{t('admin.demoBaseline.hint')}
</div>
</div>
<MAdminButton onClick={saveDemoBaseline}>{t('admin.demoBaseline.button')}</MAdminButton>
</div>
)}
{/* Stats grid (§6.3) */}
{stats && (
<div className="mb-3 grid grid-cols-2 gap-[10px] wide:grid-cols-4">
<MAdminStat label={t('admin.stats.users', { count: stats.totalUsers })} value={stats.totalUsers} icon={Users} />
<MAdminStat label={t('admin.stats.trips', { count: stats.totalTrips })} value={stats.totalTrips} icon={Briefcase} />
<MAdminStat label={t('admin.stats.places', { count: stats.totalPlaces })} value={stats.totalPlaces} icon={Map} />
<MAdminStat label={t('admin.stats.files', { count: stats.totalFiles || 0 })} value={stats.totalFiles || 0} icon={FileText} />
</div>
)}
{/* Active section */}
{activeTab === 'users' && <MAdminUsersSection admin={admin} t={t} locale={locale} />}
{activeTab === 'settings' && <MAdminSettingsSection admin={admin} t={t} />}
{activeTab === 'notifications' && <MAdminNotificationsSection admin={admin} t={t} />}
{activeTab === 'defaults' && <MAdminDefaultUserSettings />}
{activeTab === 'config' && (
<div className="space-y-4">
<MAdminPackingTemplateManager />
<MAdminCategoryManager />
<MAdminSchoolHolidayCatalog />
</div>
)}
{activeTab === 'addons' && (
<div className="space-y-4">
<MAdminAddonManager
bagTrackingEnabled={bagTrackingEnabled}
onToggleBagTracking={toggleBagTracking}
collabFeatures={collabFeatures}
onToggleCollabFeature={toggleCollabFeature}
/>
<MAdminPaddleRegionsPanel />
</div>
)}
{activeTab === 'plugins' && <MAdminPluginsPanel />}
{activeTab === 'storage' && <MAdminStoragePanel />}
{activeTab === 'mcp-tokens' && <MAdminMcpTokensPanel />}
{activeTab === 'github' && <MAdminGitHubPanel isPrerelease={updateInfo?.is_prerelease ?? false} />}
{activeTab === 'backup' && <MAdminBackupPanel />}
{activeTab === 'audit' && <MAdminAuditLogPanel serverTimezone={serverTimezone} />}
{activeTab === 'dev-notifications' && <MAdminDevNotificationsPanel />}
{managedAdminTabs.map(tab =>
activeTab === tab.id ? <div key={tab.id}>{tab.mobileElement ?? tab.element}</div> : null,
)}
</div>
<MAdminSheets admin={admin} t={t} />
</div>
)
}