feat: wizard steps are now optional

This commit is contained in:
Arman committed 2023-07-20 16:51:53 +02:00
1 parent f6f487c415
commit 19d83e0b26
6 files changed
+55 -22

No files matched your search

+2 -1
View File
@@ -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 }[] };
</script>
<li
@@ -13,6 +13,7 @@
on:keyup|self={clickOnEnter}
class:steps-item={!isSub}
class:steps-sub-item={isSub}
class:u-opacity-50={step.disabled}
style={`cursor: ${completed ? 'pointer' : 'default'};`}
aria-label={`${completed ? 'done' : current ? 'current' : ''} step`}>
{#if isSub}
+2
View File
@@ -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}
<li class="steps-item">
<h3 class="eyebrow-heading-3">OPTIONAL</h3>
</li>
+19 -11
View File
@@ -5,6 +5,7 @@
label: string;
component: typeof SvelteComponent;
optional?: boolean;
disabled?: boolean;
}
>;
</script>
@@ -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;
</script>
@@ -111,9 +124,10 @@
<slot name="aside">
<Steps
on:step={handleStepClick}
steps={sortedSteps.map(([, { label, optional }]) => ({
steps={sortedSteps.map(([, { label, optional, disabled }]) => ({
text: label,
optional
optional,
disabled
}))}
{currentStep} />
</slot>
@@ -141,16 +155,10 @@
<Button secondary on:click={handleExit}>Cancel</Button>
<Button submit>Next</Button>
{:else if isLastStep}
<Button
secondary
on:click={() => currentStep--}
on:click={() => trackEvent('wizard_back')}>Back</Button>
<Button secondary on:click={previousStep}>Back</Button>
<Button submit>{finalAction}</Button>
{:else}
<Button
secondary
on:click={() => currentStep--}
on:click={() => trackEvent('wizard_back')}>Back</Button>
<Button secondary on:click={previousStep}>Back</Button>
<Button submit>Next</Button>
{/if}
</div>
@@ -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 @@
<Wizard
title="Create organization"
steps={stepsComponents}
steps={$stepsComponents}
finalAction="Start trial"
on:finish={create}
on:exit={onFinish} />
@@ -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);
}
</script>
<WizardStep>
@@ -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<WizardStepsType>(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;