@@ -51,6 +51,7 @@ class ProjectWizard extends Component {
5151 const incompleteProject = JSON . parse ( incompleteProjectStr )
5252 const incompleteProduct = _ . get ( incompleteProject , 'details.products[0]' )
5353 let wizardStep = WZ_STEP_INCOMP_PROJ_CONF
54+ let updateQuery = { }
5455 if ( incompleteProduct && params && params . product ) {
5556 // assumes the params.product to be id of a product because incomplete project is set only
5657 // after user selects a particular product
@@ -59,20 +60,21 @@ class ProjectWizard extends Component {
5960 // load project detais page directly if product of save project and deep link are the same
6061 if ( product . id === incompleteProduct ) {
6162 wizardStep = WZ_STEP_FILL_PROJ_DETAILS
62- } else { // for different product type, update local state with URL params
63- const projectType = findProductCategory ( params . product )
64- _ . set ( incompleteProject , 'type' , projectType . id )
65- _ . set ( incompleteProject , 'details.products[0]' , product . id )
63+ updateQuery = { $merge : incompleteProject }
64+ } else {
65+ // explicitly ignores the wizardStep returned by the method
66+ // we need to call this method just to get updateQuery updated with correct project type and product
67+ this . loadProjectAndProductFromURL ( params , updateQuery )
6668 }
6769 }
6870 }
6971 this . setState ( {
70- project : update ( this . state . project , { $merge : incompleteProject } ) ,
71- dirtyProject : update ( this . state . dirtyProject , { $merge : incompleteProject } ) ,
72- wizardStep : wizardStep ,
72+ project : update ( this . state . project , updateQuery ) ,
73+ dirtyProject : update ( this . state . dirtyProject , updateQuery ) ,
74+ wizardStep,
7375 isProjectDirty : false
7476 } , ( ) => {
75- typeof onStepChange === 'function' && onStepChange ( this . state . wizardStep )
77+ typeof onStepChange === 'function' && onStepChange ( this . state . wizardStep , this . state . project )
7678 } )
7779 } else {
7880 // if there is no incomplete project in the local storage, load the wizard with appropriate step
@@ -111,7 +113,7 @@ class ProjectWizard extends Component {
111113 let wizardStep = type && product ? WZ_STEP_FILL_PROJ_DETAILS : null
112114 const updateQuery = { }
113115 if ( params && params . product ) { // if there exists product path param
114- wizardStep = this . loadProjectAndProductFromURL ( params . product , updateQuery )
116+ wizardStep = this . loadProjectAndProductFromURL ( params , updateQuery )
115117 } else { // if there is not product path param, it should be first step of the wizard
116118 updateQuery [ 'type' ] = { $set : null }
117119 updateQuery [ 'details' ] = { products : { $set : [ ] } }
@@ -132,22 +134,28 @@ class ProjectWizard extends Component {
132134 /**
133135 * Loads project type and product from the given URL parameter.
134136 *
135- * @param {string } urlParam URL parameter value which represents either project type or product
137+ * @param {object } urlParams URL parameters map
136138 * @param {object } updateQuery query object which would be updated according to parsed project type and product
137139 *
138140 * @return {number } step where wizard should move after parsing the URL param
139141 */
140- loadProjectAndProductFromURL ( urlParam , updateQuery ) {
142+ loadProjectAndProductFromURL ( urlParams , updateQuery ) {
143+ const productParam = urlParams && urlParams . product
144+ const statusParam = urlParams && urlParams . status
145+ if ( 'incomplete' === statusParam ) {
146+ return WZ_STEP_INCOMP_PROJ_CONF
147+ }
148+ if ( ! productParam ) return
141149 // first try the path param to be a project category
142- let projectType = findCategory ( urlParam , true )
150+ let projectType = findCategory ( productParam , true )
143151 if ( projectType ) { // if its a category
144152 updateQuery [ 'type' ] = { $set : projectType . id }
145153 return WZ_STEP_SELECT_PROD_TYPE
146154 } else {
147155 // if it is not a category, it should be a product and we should be able to find a category for it
148- projectType = findProductCategory ( urlParam , true )
156+ projectType = findProductCategory ( productParam , true )
149157 // finds product object from product alias
150- const product = findProduct ( urlParam , true )
158+ const product = findProduct ( productParam , true )
151159 if ( projectType ) { // we can have `incomplete` as params.product
152160 updateQuery [ 'type' ] = { $set : projectType . id }
153161 updateQuery [ 'details' ] = { products : { $set : [ product . id ] } }
@@ -180,21 +188,25 @@ class ProjectWizard extends Component {
180188 * Removed incomplete project from the local storage and resets the state. Also, moves wizard to the first step.
181189 */
182190 removeIncompleteProject ( ) {
183- const { onStepChange, onProjectUpdate } = this . props
191+ const { onStepChange } = this . props
184192 // remove incomplete project from local storage
185193 window . localStorage . removeItem ( LS_INCOMPLETE_PROJECT )
186194 const projectType = _ . get ( this . state . project , 'type' )
187195 const product = _ . get ( this . state . project , 'details.products[0]' )
188196 let wizardStep = WZ_STEP_SELECT_PROJ_TYPE
197+ let project = null
189198 if ( product ) {
199+ project = { type : projectType , details : { products : [ product ] } }
190200 wizardStep = WZ_STEP_FILL_PROJ_DETAILS
191201 } else if ( projectType ) {
202+ project = { type : projectType , details : { products : [ ] } }
192203 wizardStep = WZ_STEP_SELECT_PROD_TYPE
193204 }
194205 this . setState ( {
195- wizardStep : wizardStep
206+ project : _ . merge ( { } , project ) ,
207+ dirtyProject : _ . merge ( { } , project ) ,
208+ wizardStep
196209 } , ( ) => {
197- typeof onProjectUpdate === 'function' && onProjectUpdate ( this . state . dirtyProject , true )
198210 typeof onStepChange === 'function' && onStepChange ( this . state . wizardStep , this . state . project )
199211 } )
200212 }
0 commit comments