Block saving a wizard-enabled onboarding schema with no fields
All checks were successful
build-and-release / build (push) Successful in 57s
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:
parent
5316811b45
commit
bd9666aabf
1 changed files with 19 additions and 2 deletions
|
|
@ -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 handleSave = async () => {
|
||||||
const id = roleId();
|
const id = roleId();
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
const error = validationError();
|
||||||
|
if (error) {
|
||||||
|
setMessage(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setMessage('');
|
setMessage('');
|
||||||
try {
|
try {
|
||||||
|
|
@ -259,9 +275,10 @@ export default function OnboardingSchemaEditor() {
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={saving() || loading()}
|
disabled={saving() || loading() || !!validationError()}
|
||||||
onClick={handleSave}
|
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'}
|
{saving() ? 'Saving...' : 'Save Schema'}
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue