Skip to content

Commit d89bcbb

Browse files
author
Vikas Agarwal
committed
Github issue#1205, Back button does not work on wizard pages
— Initial commit with basic behaviour working. It still needs more testing for edge cases.
1 parent 91dcc4a commit d89bcbb

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/config/projectWizard/index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ export function findProductsOfCategory(category) {
211211
}
212212

213213
export function findProductCategory(product) {
214-
if (product === 'generic_dev') {
215-
return 'Development'
216-
}
217-
if (product === 'generic_design') {
218-
return 'Design'
219-
}
220214
for(const pType in products) {
221215
for(const prd in products[pType].subtypes) {
222216
const subType = products[pType].subtypes[prd]

src/projects/create/components/ProjectWizard.jsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)