Skip to content

Commit 6504ba9

Browse files
author
Vikas Agarwal
committed
Merge branch 'dev' into feature/chatbot-product-type
2 parents 0abcb32 + e444cb9 commit 6504ba9

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

src/config/projectWizard/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import _ from 'lodash'
2+
import typeToSpecification from '../projectSpecification/typeToSpecification'
3+
14
const products = {
25
Design: {
36
icon: 'product-app-visual-design',
@@ -114,3 +117,32 @@ export function findProductCategory(product) {
114117
}
115118
}
116119
}
120+
121+
/**
122+
* Finds field from the project creation template
123+
*
124+
* @param {string} product id of the product. It should resolve to a template where search is to be made.
125+
* @param {string} sectionId id of the section in the product template
126+
* @param {string} subSectionId id of the sub section under the section identified by sectionId
127+
* @param {string} fieldName name of the field to be fetched
128+
*
129+
* @return {object} field from the template, if found, null otherwise
130+
*/
131+
export function getProjectCreationTemplateField(product, sectionId, subSectionId, fieldName) {
132+
let specification = 'topcoder.v1'
133+
if (product)
134+
specification = typeToSpecification[product]
135+
const sections = require(`../projectQuestions/${specification}`).basicSections
136+
const section = _.find(sections, {id: sectionId})
137+
let subSection = null
138+
if (subSectionId && section) {
139+
subSection = _.find(section.subSections, {id : subSectionId })
140+
}
141+
if (subSection) {
142+
if (subSectionId === 'questions') {
143+
return _.find(subSection.questions, { fieldName })
144+
}
145+
return subSection.fieldName === fieldName ? subSection : null
146+
}
147+
return null
148+
}

src/projects/create/components/ProjectWizard.jsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash'
22
import { unflatten } from 'flat'
33
import React, { Component, PropTypes } from 'react'
44

5-
import config, { findProductCategory } from '../../../config/projectWizard'
5+
import config, { findProductCategory, getProjectCreationTemplateField } from '../../../config/projectWizard'
66
import Wizard from '../../../components/Wizard'
77
import SelectProduct from './SelectProduct'
88
import IncompleteProjectConfirmation from './IncompleteProjectConfirmation'
@@ -155,7 +155,7 @@ class ProjectWizard extends Component {
155155
const updateQuery = { }
156156
const detailsQuery = { products : [product] }
157157
// restore common fields from dirty project
158-
this.restoreCommonDetails(updateQuery, detailsQuery)
158+
this.restoreCommonDetails(product, updateQuery, detailsQuery)
159159
updateQuery.details = { $set : detailsQuery}
160160
if (projectType) {
161161
updateQuery.type = {$set : projectType }
@@ -175,7 +175,7 @@ class ProjectWizard extends Component {
175175
*
176176
* Added for Github issue#1037
177177
*/
178-
restoreCommonDetails(updateQuery, detailsQuery) {
178+
restoreCommonDetails(updatedProduct, updateQuery, detailsQuery) {
179179
const name = _.get(this.state.dirtyProject, 'name')
180180
// if name was already entered, restore it
181181
if (name) {
@@ -191,6 +191,44 @@ class ProjectWizard extends Component {
191191
if (utm) {
192192
detailsQuery.utm = { code : utm.code }
193193
}
194+
const appDefinitionQuery = {}
195+
const goal = _.get(this.state.dirtyProject, 'details.appDefinition.goal')
196+
// finds the goal field from the updated product template
197+
const goalField = getProjectCreationTemplateField(
198+
updatedProduct,
199+
'appDefinition',
200+
'questions',
201+
'details.appDefinition.goal.value'
202+
)
203+
// if goal was already entered and updated product template has the field, restore it
204+
if (goalField && goal) {
205+
appDefinitionQuery.goal = goal
206+
}
207+
const users = _.get(this.state.dirtyProject, 'details.appDefinition.users')
208+
// finds the users field from the target product template
209+
const usersField = getProjectCreationTemplateField(
210+
updatedProduct,
211+
'appDefinition',
212+
'questions',
213+
'details.appDefinition.users.value'
214+
)
215+
// if users was already entered and updated product template has the field, restore it
216+
if (usersField && users) {
217+
appDefinitionQuery.users = users
218+
}
219+
const notes = _.get(this.state.dirtyProject, 'details.appDefinition.notes')
220+
// finds the notes field from the target product template
221+
const notesField = getProjectCreationTemplateField(
222+
updatedProduct,
223+
'appDefinition',
224+
'notes',
225+
'details.appDefinition.notes'
226+
)
227+
// if notes was already entered and updated product template has the field, restore it
228+
if (notesField && notes) {
229+
appDefinitionQuery.notes = notes
230+
}
231+
detailsQuery.appDefinition = appDefinitionQuery
194232
}
195233

196234
handleProjectChange(change) {

0 commit comments

Comments
 (0)