From 24fd6f16d2cf19bbd0fa432cb0befbd576ecc519 Mon Sep 17 00:00:00 2001 From: KansaiGaijin <83641841+KansaiGaijin@users.noreply.github.com> Date: Thu, 30 Jul 2026 14:35:02 +1200 Subject: [PATCH] fix: commit default campaign claim in ensure_admin_exists, surface setup errors to user --- backend/app/auth.py | 9 +++++---- frontend/src/pages/Setup.tsx | 25 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/backend/app/auth.py b/backend/app/auth.py index 09d0770..57eaf49 100644 --- a/backend/app/auth.py +++ b/backend/app/auth.py @@ -102,7 +102,8 @@ def ensure_admin_exists(): # Claim the "default" campaign for the admin so setup wizard works admin = db.get_user_by_username(ADMIN_USERNAME) if admin: - conn.execute( - "UPDATE campaigns SET created_by = ? WHERE id = 'default' AND created_by IS NULL", - (admin["id"],), - ) + with db.tx(): + conn.execute( + "UPDATE campaigns SET created_by = ? WHERE id = 'default' AND created_by IS NULL", + (admin["id"],), + ) diff --git a/frontend/src/pages/Setup.tsx b/frontend/src/pages/Setup.tsx index 84818b7..7163d1d 100644 --- a/frontend/src/pages/Setup.tsx +++ b/frontend/src/pages/Setup.tsx @@ -21,6 +21,8 @@ const DEFAULT_SETTINGS: Record = { export default function Setup({ onComplete }: { onComplete: () => void }) { const [step, setStep] = useState(1); const [settings, setSettings] = useState>(DEFAULT_SETTINGS); + const [saving, setSaving] = useState(false); + const [error, setError] = useState(""); // On first load, try to fetch existing settings from the "default" campaign // (which is always created by init_db). @@ -36,9 +38,17 @@ export default function Setup({ onComplete }: { onComplete: () => void }) { const handleBack = () => setStep(prev => prev - 1); const handleSave = async () => { - await api.updateCampaignSettings('default', settings); - await api.updateSettings({ onboarding_completed: true }); - onComplete(); + setSaving(true); + setError(""); + try { + await api.updateCampaignSettings('default', settings); + await api.updateSettings({ onboarding_completed: true }); + onComplete(); + } catch (err: any) { + setError(err.message || "Failed to save settings"); + } finally { + setSaving(false); + } }; return ( @@ -213,12 +223,15 @@ export default function Setup({ onComplete }: { onComplete: () => void }) { )} + {error && ( +
{error}
+ )}
- -