@@ -21,21 +21,13 @@ class Wizard extends React.Component {
21
21
// find if wizard contains any dynamic steps (nextStep is mapper object)
22
22
const isDynamic = this . props . isDynamic ? true : this . props . fields . find ( ( { nextStep } ) => typeof nextStep === 'object' ) ? true : false ;
23
23
24
- // insert into navigation schema first step if dynamic, otherwise create the whole schema
25
- // if the wizard is dynamic, the navigation is build progressively
26
- const firstStep = this . props . fields . find ( ( { stepKey } ) => stepKey === 1 || stepKey === '1' ) ;
27
-
28
- const navSchema = isDynamic ?
29
- [ { title : firstStep . title , index : 0 , primary : true , substepOf : firstStep . substepOf } ]
30
- : this . createSchema ( ) ;
31
-
32
24
this . state = {
33
25
activeStep : this . props . fields [ 0 ] . stepKey ,
34
26
prevSteps : [ ] ,
35
27
activeStepIndex : 0 ,
36
28
maxStepIndex : 0 ,
37
29
isDynamic, // wizard contains nextStep mapper
38
- navSchema, // schema of navigation
30
+ navSchema : this . createSchema ( ) ,
39
31
loading : true ,
40
32
} ;
41
33
}
@@ -55,21 +47,6 @@ class Wizard extends React.Component {
55
47
}
56
48
}
57
49
58
- insertDynamicStep = ( nextStep , navSchema ) => {
59
- const { title, substepOf } = this . props . fields . find ( ( { stepKey } ) => stepKey === nextStep ) ;
60
- const lastStep = navSchema [ navSchema . length - 1 ] ;
61
-
62
- return [
63
- ...navSchema ,
64
- {
65
- title,
66
- substepOf,
67
- index : lastStep . index + 1 ,
68
- primary : ( ! substepOf ) || ( substepOf && substepOf !== lastStep . substepOf ) ,
69
- } ,
70
- ] ;
71
- }
72
-
73
50
handleNext = ( nextStep , getRegisteredFields ) =>
74
51
this . setState ( prevState =>
75
52
( {
@@ -78,7 +55,7 @@ class Wizard extends React.Component {
78
55
prevSteps : prevState . prevSteps . includes ( prevState . activeStep ) ? prevState . prevSteps : [ ...prevState . prevSteps , prevState . activeStep ] ,
79
56
activeStepIndex : prevState . activeStepIndex + 1 ,
80
57
maxStepIndex : ( prevState . activeStepIndex + 1 ) > prevState . maxStepIndex ? prevState . maxStepIndex + 1 : prevState . maxStepIndex ,
81
- navSchema : this . state . isDynamic ? this . insertDynamicStep ( nextStep , prevState . navSchema ) : prevState . navSchema ,
58
+ navSchema : this . state . isDynamic ? this . createSchema ( ) : prevState . navSchema ,
82
59
} ) ) ;
83
60
84
61
handlePrev = ( ) => this . jumpToStep ( this . state . activeStepIndex - 1 ) ;
@@ -116,11 +93,12 @@ class Wizard extends React.Component {
116
93
activeStepIndex : index ,
117
94
} ) ) ;
118
95
119
- // jumping in dynamic form disables returning to back (!)
120
- if ( this . state . isDynamic ) {
96
+ // jumping in dynamic form disables returning to back if jumped on compileMapper step (!)
97
+ if ( this . state . isDynamic && typeof this . findCurrentStep ( this . state . prevSteps [ index ] ) . nextStep === 'object' ) {
121
98
this . setState ( ( prevState ) => ( {
122
99
navSchema : prevState . navSchema . slice ( 0 , index + 1 ) ,
123
100
prevSteps : prevState . prevSteps . slice ( 0 , index + 1 ) ,
101
+ maxStepIndex : prevState . prevSteps . slice ( 0 , index + 1 ) . length ,
124
102
} ) ) ;
125
103
}
126
104
@@ -136,6 +114,7 @@ class Wizard extends React.Component {
136
114
137
115
// builds schema used for generating of the navigation links
138
116
createSchema = ( ) => {
117
+ const { formOptions } = this . props ;
139
118
let schema = [ ] ;
140
119
let field = this . props . fields . find ( ( { stepKey } ) => stepKey === 1 || stepKey === '1' ) ; // find first wizard step
141
120
let index = 0 ;
@@ -149,7 +128,19 @@ class Wizard extends React.Component {
149
128
primary : ( ! schema [ schema . length - 1 ] || ! field . substepOf || field . substepOf !== schema [ schema . length - 1 ] . substepOf ) } ,
150
129
] ;
151
130
152
- field = this . props . fields . find ( ( { stepKey } ) => stepKey === field . nextStep ) ;
131
+ let nextStep = field . nextStep ;
132
+
133
+ if ( typeof field . nextStep === 'object' ) {
134
+ const { values } = formOptions . getState ( ) ;
135
+
136
+ nextStep = nextStep . stepMapper [ get ( values , nextStep . when ) ] ;
137
+ }
138
+
139
+ if ( nextStep ) {
140
+ field = this . props . fields . find ( ( { stepKey } ) => stepKey === nextStep ) ;
141
+ } else {
142
+ field = undefined ;
143
+ }
153
144
}
154
145
155
146
return schema ;
0 commit comments