@@ -65,22 +65,24 @@ export enum OnboardingTourStepTargets {
65
65
}
66
66
67
67
const onboardingTourAtom = atomWithStorage <
68
+ | undefined
68
69
| {
69
70
isLoading ?: true ;
71
+ isCompleted ?: true ;
70
72
currentStepIndex : number ;
71
73
}
72
- | undefined
73
74
> ( "OnboardingTour" , undefined ) ;
74
75
75
- export const OnboardingTourCompletedKey = "OnboardingTourCompleted" ;
76
-
77
76
export const useOnboardingTour = ( ) => {
78
77
const [ tourState , setTourState ] = useAtom ( onboardingTourAtom ) ;
79
78
const { setOpenedSidebarLinks } = useOpenedSidebarLinks ( ) ;
80
79
const isTourStarted = isNumber ( tourState ?. currentStepIndex ) ;
81
80
const theme = useMantineTheme ( ) ;
82
81
const isMobile = useMediaQuery ( `(max-width: ${ theme . breakpoints . sm } )` ) ;
82
+
83
83
const isTourLoading = tourState ?. isLoading ;
84
+ const canTourBeStarted =
85
+ typeof tourState === "undefined" || tourState . isCompleted ;
84
86
85
87
const deployBackgroundJobMutation = useMutation ( {
86
88
mutationFn : async ( ) => {
@@ -96,8 +98,11 @@ export const useOnboardingTour = () => {
96
98
} ;
97
99
98
100
const completeTour = ( ) => {
99
- setTourState ( undefined ) ;
100
- localStorage . setItem ( OnboardingTourCompletedKey , "true" ) ;
101
+ setTourState (
102
+ produce ( tourState , ( draft ) => {
103
+ if ( draft ) draft . isCompleted = true ;
104
+ } ) ,
105
+ ) ;
101
106
window . location . href = "/" ;
102
107
} ;
103
108
@@ -250,20 +255,22 @@ export const useOnboardingTour = () => {
250
255
content : < StepWrapper > { step . content } </ StepWrapper > ,
251
256
} ) ) ;
252
257
const isOnLastTourStep =
253
- tourState ?. currentStepIndex === onboardingTourSteps . length ;
258
+ tourState ?. currentStepIndex === onboardingTourSteps . length &&
259
+ ! tourState ?. isCompleted ;
254
260
255
261
useEffect ( ( ) => {
256
262
if ( typeof isMobile === "undefined" || isMobile ) return ;
257
263
258
- const completed = localStorage . getItem ( OnboardingTourCompletedKey ) ;
259
- if ( ! completed && ! isTourStarted ) startTour ( ) ;
260
- } , [ isMobile ] ) ;
264
+ if ( canTourBeStarted && ! isTourStarted ) startTour ( ) ;
265
+ } , [ isMobile , canTourBeStarted ] ) ;
261
266
262
267
return {
268
+ startTour,
263
269
completeTour,
264
270
isTourStarted,
265
271
advanceTourStep,
266
272
isOnLastTourStep,
273
+ canTourBeStarted,
267
274
onboardingTourSteps,
268
275
currentTourStepIndex : tourState ?. currentStepIndex ,
269
276
} ;
0 commit comments