@@ -21,6 +21,7 @@ import {
21
21
} from '@mui/material'
22
22
import { useEffect , useState } from 'react'
23
23
import { useTranslation } from 'react-i18next'
24
+ import Joyride , { STATUS } from 'react-joyride'
24
25
import { useLocation , useNavigate } from 'react-router-dom'
25
26
26
27
import icon from '../media/icon.webp'
@@ -36,6 +37,10 @@ const MenuSide = () => {
36
37
const [ drawerWidth , setDrawerWidth ] = useState (
37
38
`${ Math . min ( Math . max ( window . innerWidth * 0.2 , 287 ) , 320 ) } px`
38
39
)
40
+ const [ run , setRun ] = useState ( false )
41
+ const [ stepIndex , setStepIndex ] = useState ( 0 )
42
+ const [ spotlightClicks , setSpotlightClicks ] = useState ( false )
43
+
39
44
const { i18n, t } = useTranslation ( )
40
45
41
46
const navItems = [
@@ -71,11 +76,51 @@ const MenuSide = () => {
71
76
} ,
72
77
]
73
78
79
+ const clickableSteps = [ 4 , 5 ]
80
+
81
+ const steps = [
82
+ {
83
+ target : '.step-0' ,
84
+ content : t ( 'components.step-0' ) ,
85
+ disableBeacon : true ,
86
+ } ,
87
+ {
88
+ target : '.step-1' ,
89
+ content : t ( 'components.step-1' ) ,
90
+ disableBeacon : true ,
91
+ } ,
92
+ {
93
+ target : '.step-2' ,
94
+ content : t ( 'components.step-2' ) ,
95
+ disableBeacon : true ,
96
+ } ,
97
+ {
98
+ target : '.step-3' ,
99
+ content : t ( 'components.step-3' ) ,
100
+ disableBeacon : true ,
101
+ } ,
102
+ {
103
+ target : '.step-4' ,
104
+ content : t ( 'components.step-4' ) ,
105
+ disableBeacon : true ,
106
+ } ,
107
+ {
108
+ target : '.step-5' ,
109
+ content : t ( 'components.step-5' ) ,
110
+ disableBeacon : true ,
111
+ } ,
112
+ ]
113
+
74
114
useEffect ( ( ) => {
75
115
setActive ( pathname . substring ( 1 ) )
76
116
} , [ pathname ] )
77
117
78
118
useEffect ( ( ) => {
119
+ if ( ! localStorage . getItem ( 'hasSeenGuide' ) ) {
120
+ setRun ( true )
121
+ localStorage . setItem ( 'hasSeenGuide' , 'true' )
122
+ }
123
+
79
124
const screenWidth = window . innerWidth
80
125
const maxDrawerWidth = Math . min ( Math . max ( screenWidth * 0.2 , 287 ) , 320 )
81
126
setDrawerWidth ( `${ maxDrawerWidth } px` )
@@ -96,6 +141,40 @@ const MenuSide = () => {
96
141
}
97
142
} , [ ] )
98
143
144
+ const handleJoyrideCallback = ( data ) => {
145
+ const { index, type, status, action } = data
146
+
147
+ if ( type === 'step:before' ) {
148
+ setStepIndex ( index )
149
+ setSpotlightClicks ( clickableSteps . includes ( index ) )
150
+ }
151
+
152
+ if ( status === STATUS . FINISHED || status === STATUS . SKIPPED ) {
153
+ setRun ( false )
154
+ setStepIndex ( 0 )
155
+ }
156
+
157
+ if ( type === 'step:after' ) {
158
+ if ( action !== 'prev' ) {
159
+ setStepIndex ( index + 1 )
160
+ if ( index === 3 ) {
161
+ const target = document . querySelector ( '.step-3' )
162
+ if ( target ) {
163
+ target . click ( )
164
+ }
165
+ }
166
+ } else {
167
+ setStepIndex ( index - 1 )
168
+ if ( index === 4 ) {
169
+ const target = document . querySelector ( '.step-goBack' )
170
+ if ( target ) {
171
+ target . click ( )
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+
99
178
return (
100
179
< Drawer
101
180
variant = "permanent"
@@ -110,6 +189,35 @@ const MenuSide = () => {
110
189
} }
111
190
style = { { zIndex : 1 } }
112
191
>
192
+ < Joyride
193
+ steps = { steps }
194
+ run = { run }
195
+ stepIndex = { stepIndex }
196
+ spotlightClicks = { spotlightClicks }
197
+ callback = { handleJoyrideCallback }
198
+ continuous
199
+ showStepsProgress
200
+ showSkipButton
201
+ showProgress
202
+ scrollToFirstStep
203
+ disableScrolling
204
+ hideCloseButton
205
+ disableScrollParentFix
206
+ locale = { {
207
+ back : t ( 'components.back' ) ,
208
+ close : t ( 'components.close' ) ,
209
+ next : t ( 'components.next' ) ,
210
+ last : t ( 'components.last' ) ,
211
+ skip : t ( 'components.skip' ) ,
212
+ nextLabelWithProgress : t ( 'components.next' ) ,
213
+ } }
214
+ styles = { {
215
+ options : {
216
+ zIndex : 1300 ,
217
+ primaryColor : '#1976D2' ,
218
+ } ,
219
+ } }
220
+ />
113
221
{ /* Title */ }
114
222
< Box
115
223
display = "flex"
@@ -145,7 +253,7 @@ const MenuSide = () => {
145
253
< Box sx = { { flexGrow : 1 } } >
146
254
< Box width = "100%" >
147
255
< Box m = "1.5rem 2rem 2rem 3rem" > </ Box >
148
- < List >
256
+ < List className = "step-0" >
149
257
{ navItems . map ( ( { text, label, icon } ) => {
150
258
if ( ! icon ) {
151
259
return (
0 commit comments