Skip to content

Commit 4f5b38e

Browse files
author
Vikas Agarwal
committed
Github issue#1102, Process/add ref code from deep link
— Done Github issue#1037, Project spec information is not saved when changing project types — Done
1 parent e77252c commit 4f5b38e

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

src/projects/create/components/ProjectWizard.jsx

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ class ProjectWizard extends Component {
3636
this.removeIncompleteProject = this.removeIncompleteProject.bind(this)
3737
this.handleOnCreateProject = this.handleOnCreateProject.bind(this)
3838
this.handleStepChange = this.handleStepChange.bind(this)
39+
this.restoreCommonDetails = this.restoreCommonDetails.bind(this)
3940
}
4041

4142
componentDidMount() {
42-
const { params, onStepChange } = this.props
43+
const { params, onStepChange, location } = this.props
4344
// load incomplete project from local storage
4445
const incompleteProjectStr = window.localStorage.getItem(LS_INCOMPLETE_PROJECT)
4546
if(incompleteProjectStr) {
@@ -64,6 +65,16 @@ class ProjectWizard extends Component {
6465
wizardStep = WZ_STEP_FILL_PROJ_DETAILS
6566
}
6667
}
68+
// retrieve refcode from query param
69+
const refcode = _.get(location, 'query.refcode')
70+
if (refcode) {
71+
// if refcode exists, update the updateQuery to set that refcode
72+
if (_.get(updateQuery, 'details')) {
73+
updateQuery['details']['utm'] = { $set : { code : refcode }}
74+
} else {
75+
updateQuery['details'] = { utm : { $set : { code : refcode }}}
76+
}
77+
}
6778
this.setState({
6879
project: update(this.state.project, updateQuery),
6980
dirtyProject: update(this.state.dirtyProject, updateQuery),
@@ -138,11 +149,12 @@ class ProjectWizard extends Component {
138149
updateProducts(projectType, product) {
139150
window.scrollTo(0, 0)
140151
const { onStepChange } = this.props
141-
const products = _.get(this.state.project, 'details.products')
142-
let updateQuery = { details: { products : { $set : [product] }}}
143-
if (!products) {
144-
updateQuery = { details: { $set : { products : [product] }}}
145-
}
152+
// const products = _.get(this.state.project, 'details.products')
153+
let updateQuery = { }
154+
const detailsQuery = { products : [product] }
155+
// restore common fields from dirty project
156+
this.restoreCommonDetails(updateQuery, detailsQuery)
157+
updateQuery.details = { $set : detailsQuery}
146158
if (projectType) {
147159
updateQuery.type = {$set : projectType }
148160
}
@@ -155,6 +167,29 @@ class ProjectWizard extends Component {
155167
})
156168
}
157169

170+
/**
171+
* Restores common details of the project while changing product type.
172+
*
173+
* Added for Github issue#1037
174+
*/
175+
restoreCommonDetails(updateQuery, detailsQuery) {
176+
const name = _.get(this.state.dirtyProject, 'name')
177+
// if name was already entered, restore it
178+
if (name) {
179+
updateQuery.name = { $set: name }
180+
}
181+
const description = _.get(this.state.dirtyProject, 'description')
182+
// if description was already entered, restore it
183+
if (description) {
184+
updateQuery.description = { $set: description }
185+
}
186+
const utm = _.get(this.state.dirtyProject, 'details.utm')
187+
// if UTM code was already entered, restore it
188+
if (utm) {
189+
detailsQuery.utm = { code : utm.code }
190+
}
191+
}
192+
158193
handleProjectChange(change) {
159194
const { onProjectUpdate } = this.props
160195
this.setState({

0 commit comments

Comments
 (0)