From bd9666aabf5a01e05dc7c82f696747b3f4b690cd Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Sivakumar Date: Wed, 29 Jul 2026 11:46:22 +0530 Subject: [PATCH] Block saving a wizard-enabled onboarding schema with no fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Enable verification wizard flow" checkbox and step/field editing were decoupled with no validation tying them together — an admin could toggle the wizard on and hit Save before adding any fields to a step, instantly publishing a wizard with nothing to fill in. Save is now disabled (with an inline message naming the empty step) until every non-review step has at least one field. Mirrors the same check added server-side in nxtgauge-backend-rust's create_onboarding_config. Co-Authored-By: Claude Sonnet 5 --- .../admin/OnboardingSchemaEditor.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/admin/OnboardingSchemaEditor.tsx b/src/components/admin/OnboardingSchemaEditor.tsx index 3a6c97d..6785348 100644 --- a/src/components/admin/OnboardingSchemaEditor.tsx +++ b/src/components/admin/OnboardingSchemaEditor.tsx @@ -185,9 +185,25 @@ export default function OnboardingSchemaEditor() { ); }; + // Mirrors the backend check in create_onboarding_config — catches it before + // the round trip so an admin can't accidentally publish a wizard with + // nothing to fill in (checkbox on, but a step never got any fields added). + const validationError = (): string | null => { + if (!enableWizardFlow()) return null; + if (steps().length === 0) return 'Cannot enable the wizard flow with no steps configured.'; + const emptyStep = steps().find((s) => s.type !== 'review' && s.fields.length === 0); + if (emptyStep) return `Cannot enable the wizard flow: step "${emptyStep.title || '(untitled step)'}" has no fields.`; + return null; + }; + const handleSave = async () => { const id = roleId(); if (!id) return; + const error = validationError(); + if (error) { + setMessage(error); + return; + } setSaving(true); setMessage(''); try { @@ -259,9 +275,10 @@ export default function OnboardingSchemaEditor() {