diff --git a/src/lib/layout/wizard.svelte b/src/lib/layout/wizard.svelte index 95f462c07..4a27583c5 100644 --- a/src/lib/layout/wizard.svelte +++ b/src/lib/layout/wizard.svelte @@ -68,10 +68,12 @@ } async function submit() { + let interceptorResponse = null; + if ($wizard.interceptor) { $wizard.nextDisabled = true; try { - await $wizard.interceptor(); + interceptorResponse = await $wizard.interceptor(); } catch (error) { if (!$wizard.interceptorNotificationEnabled) return; addNotification({ @@ -84,6 +86,10 @@ } } + // maintains backward compatibility. + // explicit boolean check as the return type can be undefined/void too! + if (typeof interceptorResponse === 'boolean' && interceptorResponse === false) return; + wizard.setInterceptor(null); if (isLastStep) { if ($wizard.finalAction) { diff --git a/src/lib/layout/wizardStep.svelte b/src/lib/layout/wizardStep.svelte index cddb57463..ffbd91945 100644 --- a/src/lib/layout/wizardStep.svelte +++ b/src/lib/layout/wizardStep.svelte @@ -4,9 +4,14 @@ import { onDestroy } from 'svelte'; /** - * Pass callback that is run before the Form submit, can be canceled with throwing an exception. + * Pass callback that is run before the Form submit, + * can be canceled by throwing an `Exception` or returning `false`. + * + * Example - + * 1. validate > throw Error > notification is shown + * 2. validate > return False > show your UI as no notification is shown. */ - export let beforeSubmit: () => Promise = null; + export let beforeSubmit: () => Promise | Promise = null; export let nextDisabled = false; $: wizard.setNextDisabled(nextDisabled); diff --git a/src/lib/stores/wizard.ts b/src/lib/stores/wizard.ts index 6a752584f..479bd4d33 100644 --- a/src/lib/stores/wizard.ts +++ b/src/lib/stores/wizard.ts @@ -8,7 +8,7 @@ export type WizardStore = { media?: string; component?: typeof SvelteComponent; cover?: typeof SvelteComponent; - interceptor?: () => Promise; + interceptor?: () => Promise | Promise; finalAction?: () => Promise; nextDisabled: boolean; step: number; diff --git a/src/routes/(console)/project-[project]/overview/platforms/wizard/flutter/step1.svelte b/src/routes/(console)/project-[project]/overview/platforms/wizard/flutter/step1.svelte index 207378bbb..b8e87f999 100644 --- a/src/routes/(console)/project-[project]/overview/platforms/wizard/flutter/step1.svelte +++ b/src/routes/(console)/project-[project]/overview/platforms/wizard/flutter/step1.svelte @@ -1,7 +1,7 @@ - + {registee} registration
@@ -185,6 +190,10 @@ required bind:value={$createPlatform.hostname} /> + {#if error} + {error} + {/if} +
{#each suggestions as suggestion} { + error = null; + // double-check the hostname value. if (!isHostnameValid($createPlatform.hostname)) { - throw new Error('Please enter a valid hostname'); + error = 'Please enter a valid hostname'; + return false; } if ($createPlatform.$id) { @@ -47,9 +51,13 @@ $createPlatform.$id = platform.$id; } + + $: if (!$createPlatform.hostname && error) { + error = null; + } - + Hostname registration + + {#if error} + {error} + {/if} +
{#each suggestions as suggestion}