From 19d83e0b261bcc6309216b8737b9e2ba06ca7b08 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 20 Jul 2023 16:51:53 +0200 Subject: [PATCH] feat: wizard steps are now optional --- src/lib/components/step.svelte | 3 +- src/lib/components/steps.svelte | 2 ++ src/lib/layout/wizard.svelte | 30 ++++++++++++------- .../console/createOrganizationCloud.svelte | 15 ++++------ .../wizard/cloudOrganization/step1.svelte | 15 +++++++++- .../console/wizard/cloudOrganization/store.ts | 12 ++++++++ 6 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/lib/components/step.svelte b/src/lib/components/step.svelte index cb6cad774..ec1f7a546 100644 --- a/src/lib/components/step.svelte +++ b/src/lib/components/step.svelte @@ -5,7 +5,7 @@ export let current = false; export let currentSub = 0; export let isSub = false; - export let step: { text: string; substeps?: { text: string }[] }; + export let step: { text: string; disabled?: boolean; substeps?: { text: string }[] };
  • {#if isSub} diff --git a/src/lib/components/steps.svelte b/src/lib/components/steps.svelte index 7837c3be9..3743823fe 100644 --- a/src/lib/components/steps.svelte +++ b/src/lib/components/steps.svelte @@ -5,6 +5,7 @@ export let steps: { text: string; optional: boolean; + disabled?: boolean; substeps?: { text: string; }[]; @@ -22,6 +23,7 @@ {#each steps as step, index} {@const stepNumber = index + 1} {#if firstOptional === index} + {step.disabled}
  • OPTIONAL

  • diff --git a/src/lib/layout/wizard.svelte b/src/lib/layout/wizard.svelte index 4bfdce11e..11c62048b 100644 --- a/src/lib/layout/wizard.svelte +++ b/src/lib/layout/wizard.svelte @@ -5,6 +5,7 @@ label: string; component: typeof SvelteComponent; optional?: boolean; + disabled?: boolean; } >; @@ -78,11 +79,23 @@ trackEvent('wizard_finish'); dispatch('finish'); } else { + if (steps.get(currentStep + 1)?.disabled) { + currentStep++; + while (steps.get(currentStep)?.disabled) { + currentStep++; + } + } else { + currentStep++; + } trackEvent('wizard_next'); - currentStep++; } } + function previousStep() { + trackEvent('wizard_back'); + currentStep--; + } + $: sortedSteps = [...steps].sort(([a], [b]) => (a > b ? 1 : -1)); $: isLastStep = currentStep === steps.size; @@ -111,9 +124,10 @@ ({ + steps={sortedSteps.map(([, { label, optional, disabled }]) => ({ text: label, - optional + optional, + disabled }))} {currentStep} /> @@ -141,16 +155,10 @@ {:else if isLastStep} - + {:else} - + {/if} diff --git a/src/routes/console/createOrganizationCloud.svelte b/src/routes/console/createOrganizationCloud.svelte index f31001466..cb8d86829 100644 --- a/src/routes/console/createOrganizationCloud.svelte +++ b/src/routes/console/createOrganizationCloud.svelte @@ -7,8 +7,7 @@ import Step2 from './wizard/cloudOrganization/step2.svelte'; import Step3 from './wizard/cloudOrganization/step3.svelte'; import Step4 from './wizard/cloudOrganization/step4.svelte'; - import { createOrganization } from './wizard/cloudOrganization/store'; - import type { WizardStepsType } from '$lib/layout/wizard.svelte'; + import { createOrganization, stepsComponents } from './wizard/cloudOrganization/store'; import { goto, invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; @@ -78,21 +77,19 @@ }; }); - const stepsComponents: WizardStepsType = new Map(); - - stepsComponents.set(1, { + $stepsComponents.set(1, { label: 'Organization details', component: Step1 }); - stepsComponents.set(2, { + $stepsComponents.set(2, { label: 'Payment details', component: Step2 }); - stepsComponents.set(3, { + $stepsComponents.set(3, { label: 'Invite collaborators', component: Step3 }); - stepsComponents.set(4, { + $stepsComponents.set(4, { label: 'Review & confirm', component: Step4 }); @@ -100,7 +97,7 @@ diff --git a/src/routes/console/wizard/cloudOrganization/step1.svelte b/src/routes/console/wizard/cloudOrganization/step1.svelte index 8700fcebe..4a8ba0e76 100644 --- a/src/routes/console/wizard/cloudOrganization/step1.svelte +++ b/src/routes/console/wizard/cloudOrganization/step1.svelte @@ -5,13 +5,26 @@ import { WizardStep } from '$lib/layout'; import { tierFree, tierPro, tierScale } from '$lib/stores/billing'; import { organizationList, type Organization } from '$lib/stores/organization'; - import { createOrganization } from './store'; + import { createOrganization, stepsComponents, updateComponentStatus } from './store'; let showCustomId = false; $: anyOrgFree = $organizationList.teams?.find( (org) => (org as Organization)?.billingPlan === 'tier-0' ); + + $: if ($createOrganization.billingPlan === 'tier-0') { + $stepsComponents = updateComponentStatus($stepsComponents, 2, true); + $stepsComponents = updateComponentStatus($stepsComponents, 3, true); + } + + $: if ( + $createOrganization.billingPlan === 'tier-2' || + $createOrganization.billingPlan === 'tier-1' + ) { + $stepsComponents = updateComponentStatus($stepsComponents, 2, false); + $stepsComponents = updateComponentStatus($stepsComponents, 3, false); + } diff --git a/src/routes/console/wizard/cloudOrganization/store.ts b/src/routes/console/wizard/cloudOrganization/store.ts index f498456dd..a376bdc55 100644 --- a/src/routes/console/wizard/cloudOrganization/store.ts +++ b/src/routes/console/wizard/cloudOrganization/store.ts @@ -1,6 +1,18 @@ +import type { WizardStepsType } from '$lib/layout/wizard.svelte'; import type { Tier } from '$lib/stores/billing'; import { writable } from 'svelte/store'; +export const stepsComponents = writable(new Map()); + +export function updateComponentStatus(map: WizardStepsType, key: number, status: boolean) { + const updatedComponent = { + ...map.get(key), + disabled: status + }; + map.set(key, updatedComponent); + return map; +} + export const createOrganization = writable<{ id?: string; name: string;