@@ -61,10 +61,23 @@ function ClientWizardForm({
6161 const theme = useContext ( ThemeContext )
6262 const selectedTheme = theme . state . theme
6363 const [ modal , setModal ] = useState ( false )
64- const [ currentStep , setCurrentStep ] = useState ( sequence [ 0 ] )
64+ const [ currentStep , setCurrentStep ] = useState ( ( ) => {
65+ const initialActiveSteps = isEdit
66+ ? sequence
67+ : sequence . filter ( ( step ) => step !== 'ClientActiveTokens' )
68+ return initialActiveSteps [ 0 ]
69+ } )
6570 const dispatch = useDispatch ( )
6671 const { permissions : cedarPermissions } = useSelector ( ( state ) => state . cedarPermissions )
6772
73+ const activeSteps = useMemo ( ( ) => {
74+ return isEdit ? sequence : sequence . filter ( ( step ) => step !== 'ClientActiveTokens' )
75+ } , [ isEdit ] )
76+
77+ const validCurrentStep = useMemo ( ( ) => {
78+ return activeSteps . includes ( currentStep ) ? currentStep : activeSteps [ 0 ]
79+ } , [ activeSteps , currentStep ] )
80+
6881 const clientResourceId = ADMIN_UI_RESOURCES . Clients
6982 const clientScopes = useMemo (
7083 ( ) => CEDAR_RESOURCE_SCOPES [ clientResourceId ] || [ ] ,
@@ -80,6 +93,12 @@ function ClientWizardForm({
8093 authorizeHelper ( clientScopes )
8194 } , [ authorizeHelper , clientScopes ] )
8295
96+ useEffect ( ( ) => {
97+ if ( activeSteps . length > 0 && ! activeSteps . includes ( currentStep ) ) {
98+ setCurrentStep ( activeSteps [ 0 ] )
99+ }
100+ } , [ activeSteps , currentStep ] )
101+
83102 const initialValues = {
84103 inum : client_data . inum ,
85104 dn : client_data . dn ,
@@ -176,24 +195,40 @@ function ClientWizardForm({
176195 return sequence [ index ]
177196 }
178197 function prevStep ( ) {
179- setCurrentStep ( sequence [ sequence . indexOf ( currentStep ) - 1 ] )
198+ const currentIndex = activeSteps . indexOf ( validCurrentStep )
199+
200+ if ( currentIndex > 0 ) {
201+ setCurrentStep ( activeSteps [ currentIndex - 1 ] )
202+ }
180203 }
181204 function nextStep ( ) {
205+ const currentIndex = activeSteps . indexOf ( validCurrentStep )
206+
182207 if (
183208 formRef . current . values . grantTypes . includes ( 'authorization_code' ) ||
184209 formRef . current . values . grantTypes . includes ( 'implicit' )
185210 ) {
186211 if ( formRef && formRef . current && formRef . current . values . redirectUris . length > 0 ) {
187- setCurrentStep ( sequence [ sequence . indexOf ( currentStep ) + 1 ] )
212+ if ( currentIndex < activeSteps . length - 1 ) {
213+ setCurrentStep ( activeSteps [ currentIndex + 1 ] )
214+ }
188215 } else {
189216 toast . info ( 'Please add atleast 1 redirect URL' )
190217 }
191218 } else {
192- setCurrentStep ( sequence [ sequence . indexOf ( currentStep ) + 1 ] )
219+ if ( currentIndex < activeSteps . length - 1 ) {
220+ setCurrentStep ( activeSteps [ currentIndex + 1 ] )
221+ }
193222 }
194223 }
195224 function isComplete ( stepId ) {
196- return sequence . indexOf ( stepId ) < sequence . indexOf ( currentStep )
225+ const stepIndex = activeSteps . indexOf ( stepId )
226+ const currentIndex = activeSteps . indexOf ( validCurrentStep )
227+
228+ if ( stepIndex === - 1 || currentIndex === - 1 ) {
229+ return false
230+ }
231+ return stepIndex < currentIndex
197232 }
198233 function submitForm ( message ) {
199234 commitMessage = message
@@ -218,8 +253,9 @@ function ClientWizardForm({
218253 }
219254 }
220255
221- const isFirstStep = currentStep === sequence [ 0 ]
222- const isLastStep = currentStep === sequence [ sequence . length - 1 ]
256+ const isFirstStep = activeSteps . length > 0 && validCurrentStep === activeSteps [ 0 ]
257+ const isLastStep =
258+ activeSteps . length > 0 && validCurrentStep === activeSteps [ activeSteps . length - 1 ]
223259
224260 useEffect ( ( ) => {
225261 return function cleanup ( ) {
@@ -229,7 +265,7 @@ function ClientWizardForm({
229265 useEffect ( ( ) => { } , [ cedarPermissions ] )
230266
231267 const activeClientStep = ( formik ) => {
232- switch ( currentStep ) {
268+ switch ( validCurrentStep ) {
233269 case sequence [ 0 ] :
234270 return (
235271 < div >
@@ -414,9 +450,9 @@ function ClientWizardForm({
414450 </ div >
415451 < CardBody className = "d-flex justify-content-center pt-3 wizard-wrapper" >
416452 < Wizard
417- activeStep = { currentStep }
453+ activeStep = { validCurrentStep }
418454 onStepChanged = { changeStep }
419- initialActiveStep = { sequence [ 0 ] }
455+ initialActiveStep = { activeSteps [ 0 ] }
420456 >
421457 < WizardStep
422458 data-testid = { sequence [ 0 ] }
0 commit comments