From bd44b7cbae7b509ed0c1d27f283066c83650c20d Mon Sep 17 00:00:00 2001 From: nikita-jpg <56046344+nikita-jpg@users.noreply.github.com> Date: Thu, 27 Jul 2023 20:33:51 +0000 Subject: [PATCH 1/3] feat: add useOnboardingPreset, add presetsNames to export --- src/controller.test.ts | 4 ++-- src/hooks.tsx | 9 +++++++++ src/index.ts | 15 +++++++++++++-- src/types.ts | 3 ++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/controller.test.ts b/src/controller.test.ts index fca5582..701f886 100644 --- a/src/controller.test.ts +++ b/src/controller.test.ts @@ -10,7 +10,7 @@ const getOptions = ( presets: { createProject: { name: 'Creating project', - description: '', + description: [''], steps: [ { slug: 'openBoard', @@ -31,7 +31,7 @@ const getOptions = ( }, createQueue: { name: 'Creating queue', - description: '', + description: [''], steps: [], }, }, diff --git a/src/hooks.tsx b/src/hooks.tsx index b5a61aa..046dbd5 100644 --- a/src/hooks.tsx +++ b/src/hooks.tsx @@ -66,10 +66,19 @@ export function getHooks { + const resetPresetProgress = async () => { + await controller.resetPresetProgress([preset]); + }; + + return resetPresetProgress; + }; + return { useOnboardingPreset, useOnboardingStep, useOnboardingHint, useOnboarding, + useResetOnboarding, }; } diff --git a/src/index.ts b/src/index.ts index a23afa5..6d0b15d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,14 +48,25 @@ export function createOnboarding>(options: // @ts-ignore passStepRef = controller.passStep; - const {useOnboarding, useOnboardingPreset, useOnboardingStep, useOnboardingHint} = - getHooks(controller); + const { + useOnboarding, + useOnboardingPreset, + useOnboardingStep, + useOnboardingHint, + useResetOnboarding, + } = getHooks(controller); + + const presetsNames = Object.keys( + controller.options.config.presets, + ) as unknown as keyof typeof controller.options.config.presets; return { useOnboardingStep, useOnboardingPreset, useOnboardingHint, useOnboarding, + useResetOnboarding, controller, + presetsNames, }; } diff --git a/src/types.ts b/src/types.ts index 3f364ba..5bb3531 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,4 @@ +import type {ReactNode} from 'react'; import type {LoggerOptions} from './logger'; type HintPlacement = @@ -30,7 +31,7 @@ export type PresetStep = { export type Preset = { name: string; - description: string; + description: ReactNode[]; type?: 'default' | 'hidden'; steps: PresetStep[]; hidden?: boolean; From b67a163f44af9798d860d7a352e8c9fb640baff5 Mon Sep 17 00:00:00 2001 From: nikita-jpg <56046344+nikita-jpg@users.noreply.github.com> Date: Fri, 28 Jul 2023 06:49:59 +0000 Subject: [PATCH 2/3] refactor: resetPresetProgress in useOnboardingPreset --- src/hooks.tsx | 14 +++++--------- src/index.ts | 10 ++-------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/hooks.tsx b/src/hooks.tsx index 046dbd5..3e11012 100644 --- a/src/hooks.tsx +++ b/src/hooks.tsx @@ -39,9 +39,14 @@ export function getHooks { + await controller.resetPresetProgress([preset]); + }; + return { addPreset, finishPreset, + resetPresetProgress, }; }; @@ -66,19 +71,10 @@ export function getHooks { - const resetPresetProgress = async () => { - await controller.resetPresetProgress([preset]); - }; - - return resetPresetProgress; - }; - return { useOnboardingPreset, useOnboardingStep, useOnboardingHint, useOnboarding, - useResetOnboarding, }; } diff --git a/src/index.ts b/src/index.ts index 6d0b15d..d753c63 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,13 +48,8 @@ export function createOnboarding>(options: // @ts-ignore passStepRef = controller.passStep; - const { - useOnboarding, - useOnboardingPreset, - useOnboardingStep, - useOnboardingHint, - useResetOnboarding, - } = getHooks(controller); + const {useOnboarding, useOnboardingPreset, useOnboardingStep, useOnboardingHint} = + getHooks(controller); const presetsNames = Object.keys( controller.options.config.presets, @@ -65,7 +60,6 @@ export function createOnboarding>(options: useOnboardingPreset, useOnboardingHint, useOnboarding, - useResetOnboarding, controller, presetsNames, }; From 3ada0cffd49a6b1b3a39c32c0a8d5c4367ccd949 Mon Sep 17 00:00:00 2001 From: nikita-jpg <56046344+nikita-jpg@users.noreply.github.com> Date: Fri, 28 Jul 2023 08:01:43 +0000 Subject: [PATCH 3/3] refactor: made the preset description optional --- src/controller.test.ts | 2 -- src/types.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/controller.test.ts b/src/controller.test.ts index 701f886..15a7fc8 100644 --- a/src/controller.test.ts +++ b/src/controller.test.ts @@ -10,7 +10,6 @@ const getOptions = ( presets: { createProject: { name: 'Creating project', - description: [''], steps: [ { slug: 'openBoard', @@ -31,7 +30,6 @@ const getOptions = ( }, createQueue: { name: 'Creating queue', - description: [''], steps: [], }, }, diff --git a/src/types.ts b/src/types.ts index 5bb3531..8200519 100644 --- a/src/types.ts +++ b/src/types.ts @@ -31,7 +31,7 @@ export type PresetStep = { export type Preset = { name: string; - description: ReactNode[]; + description?: ReactNode[]; type?: 'default' | 'hidden'; steps: PresetStep[]; hidden?: boolean;