@@ -97,12 +97,37 @@ class ProjectWizard extends Component {
9797 }
9898
9999 componentWillReceiveProps ( nextProps ) {
100- const { onStepChange } = nextProps
100+ const { onStepChange, params } = nextProps
101101 const type = _ . get ( nextProps . project , 'type' , null )
102102 const product = _ . get ( nextProps . project , 'details.products[0]' , null )
103- const wizardStep = type && product ? WZ_STEP_FILL_PROJ_DETAILS : null
104- if ( wizardStep ) {
103+ // redirect user to project details form, if we already have category and product available
104+ let wizardStep = type && product ? WZ_STEP_FILL_PROJ_DETAILS : null
105+ const updateQuery = { }
106+ if ( params && params . product ) { // if there exists product path param
107+ // first try the path param to be a project category
108+ let projectType = findCategory ( params . product )
109+ if ( projectType ) { // if its a category
110+ updateQuery [ 'type' ] = { $set : projectType . id }
111+ wizardStep = WZ_STEP_SELECT_PROD_TYPE
112+ } else {
113+ // if it is not a category, it should be a product and we should be able to find a category for it
114+ projectType = findProductCategory ( params . product )
115+ if ( projectType ) { // we can have `incomplete` as params.product
116+ updateQuery [ 'type' ] = { $set : projectType . id }
117+ updateQuery [ 'details' ] = { products : { $set : [ params . product ] } }
118+ wizardStep = WZ_STEP_FILL_PROJ_DETAILS
119+ }
120+ }
121+ } else { // if there is not product path param, it should be first step of the wizard
122+ updateQuery [ 'type' ] = { $set : null }
123+ updateQuery [ 'details' ] = { products : { $set : [ ] } }
124+ wizardStep = WZ_STEP_SELECT_PROJ_TYPE
125+ }
126+ // if wizard setp deduced above and stored in state are not the same, update the state
127+ if ( wizardStep && this . state . wizardStep !== wizardStep ) {
105128 this . setState ( {
129+ project : update ( this . state . project , updateQuery ) ,
130+ dirtyProject : update ( this . state . dirtyProject , updateQuery ) ,
106131 wizardStep
107132 } , ( ) => {
108133 typeof onStepChange === 'function' && onStepChange ( this . state . wizardStep )
0 commit comments