Block saving a wizard-enabled onboarding schema with no fields
All checks were successful
build-and-release / build (push) Successful in 57s

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 <noreply@anthropic.com>
This commit is contained in:
Ashwin Kumar Sivakumar 2026-07-29 11:46:22 +05:30
parent 5316811b45
commit bd9666aabf

View file

@ -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() {
<button
type="button"
disabled={saving() || loading()}
disabled={saving() || loading() || !!validationError()}
onClick={handleSave}
style={`height:36px;border-radius:8px;border:none;background:#0D0D2A;color:white;padding:0 16px;font-size:13px;font-weight:700;cursor:pointer;opacity:${saving() || loading() ? 0.6 : 1}`}
title={validationError() || undefined}
style={`height:36px;border-radius:8px;border:none;background:#0D0D2A;color:white;padding:0 16px;font-size:13px;font-weight:700;cursor:pointer;opacity:${saving() || loading() || validationError() ? 0.6 : 1}`}
>
{saving() ? 'Saving...' : 'Save Schema'}
</button>