From 8c8069e9833753f748c1a4389f03d0bf595efde4 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 9 Oct 2026 10:49:44 +0200 Subject: [PATCH] refactor(admin): share the admin shell actions between desktop and phone Saving the demo baseline and the bag tracking and collab feature switches now live in useAdmin. AdminPage and the phone admin screen pass them on instead of carrying their own inline copies. --- client/src/mobile/screens/admin/MAdmin.tsx | 38 ++---------- client/src/pages/AdminPage.tsx | 32 ++-------- client/src/pages/admin/useAdmin.test.tsx | 72 +++++++++++++++++++++- client/src/pages/admin/useAdmin.ts | 33 ++++++++++ 4 files changed, 114 insertions(+), 61 deletions(-) diff --git a/client/src/mobile/screens/admin/MAdmin.tsx b/client/src/mobile/screens/admin/MAdmin.tsx index 9d3aa5ff1..453fc5a88 100644 --- a/client/src/mobile/screens/admin/MAdmin.tsx +++ b/client/src/mobile/screens/admin/MAdmin.tsx @@ -24,7 +24,6 @@ import { Users, } from 'lucide-react' import type { LucideIcon } from 'lucide-react' -import { adminApi } from '../../../api/client' import { useTranslation } from '../../../i18n' import { useCountUp } from '../../../hooks/useCountUp' import { useAdmin } from '../../../pages/admin/useAdmin' @@ -71,12 +70,12 @@ export default function MAdmin() { const { t, locale } = useTranslation() const admin = useAdmin() const { - demoMode, mcpEnabled, devMode, managed, toast, navigate, + demoMode, mcpEnabled, devMode, managed, navigate, activeTab, setActiveTab, stats, serverTimezone, - bagTrackingEnabled, setBagTrackingEnabled, - collabFeatures, setCollabFeatures, + bagTrackingEnabled, collabFeatures, setShowCreateUser, updateInfo, setShowUpdateModal, + saveDemoBaseline, toggleBagTracking, toggleCollabFeature, } = admin const [sectionsOpen, setSectionsOpen] = useState(false) @@ -101,15 +100,6 @@ export default function MAdmin() { ] const activeSection = sections.find((s) => s.id === activeTab) ?? sections[0] - const saveDemoBaseline = async () => { - try { - await adminApi.saveDemoBaseline() - toast.success('Baseline saved! Resets will restore to this state.') - } catch (e) { - toast.error(e.response?.data?.error || 'Failed to save baseline') - } - } - return ( // Flow screen: scrolls with the document (#1809), so no height and no // scroll container of its own. @@ -221,27 +211,9 @@ export default function MAdmin() { {activeTab === 'addons' && ( { - const next = !bagTrackingEnabled - setBagTrackingEnabled(next) - try { - await adminApi.updateBagTracking(next) - } catch { - setBagTrackingEnabled(!next) - } - }} + onToggleBagTracking={toggleBagTracking} collabFeatures={collabFeatures} - onToggleCollabFeature={async (key: string) => { - const previous = collabFeatures[key] - setCollabFeatures({ ...collabFeatures, [key]: !previous }) - try { - await adminApi.updateCollabFeatures({ [key]: !previous }) - } catch { - // Only this key rolls back — a slower request must not undo a toggle - // the admin made in the meantime. - setCollabFeatures(prev => ({ ...prev, [key]: previous })) - } - }} + onToggleCollabFeature={toggleCollabFeature} /> )} {activeTab === 'plugins' && } diff --git a/client/src/pages/AdminPage.tsx b/client/src/pages/AdminPage.tsx index dd47f7691..f86850413 100644 --- a/client/src/pages/AdminPage.tsx +++ b/client/src/pages/AdminPage.tsx @@ -1,6 +1,5 @@ import SchoolHolidayCatalog from '../components/Admin/SchoolHolidayCatalog' import React, { Fragment } from 'react' -import { adminApi } from '../api/client' import DevNotificationsPanel from '../components/Admin/DevNotificationsPanel' import DefaultUserSettingsTab from '../components/Admin/DefaultUserSettingsTab' import { useTranslation } from '../i18n' @@ -41,12 +40,12 @@ function AdminPageDesktop(): React.ReactElement { // each tab/section renders from a dedicated sub-component. const admin = useAdmin() const { - demoMode, mcpEnabled, devMode, managed, toast, + demoMode, mcpEnabled, devMode, managed, activeTab, setActiveTab, stats, - bagTrackingEnabled, setBagTrackingEnabled, - collabFeatures, setCollabFeatures, + bagTrackingEnabled, collabFeatures, serverTimezone, updateInfo, setShowUpdateModal, + saveDemoBaseline, toggleBagTracking, toggleCollabFeature, } = admin const gUsers = t('admin.group.users') @@ -124,14 +123,7 @@ function AdminPageDesktop(): React.ReactElement {

Save current state as the hourly reset point. All admin trips and settings will be preserved.