@@ -72,6 +72,7 @@ class CreateContainer extends React.Component {
7272 this . createProject = this . createProject . bind ( this )
7373 this . onLeave = this . onLeave . bind ( this )
7474 this . closeWizard = this . closeWizard . bind ( this )
75+ this . prepareProjectForCreation = this . prepareProjectForCreation . bind ( this )
7576 }
7677
7778 componentWillReceiveProps ( nextProps ) {
@@ -164,7 +165,13 @@ class CreateContainer extends React.Component {
164165 // stores the incomplete project in local storage
165166 onLeave ( e ) { // eslint-disable-line no-unused-vars
166167 const { wizardStep, isProjectDirty } = this . state
168+ const { templates : { projectTemplates } } = this . props
169+
167170 if ( wizardStep === ProjectWizard . Steps . WZ_STEP_FILL_PROJ_DETAILS && isProjectDirty ) { // Project Details step
171+
172+ const projectTemplateKey = _ . get ( this . state . updatedProject , 'details.products[0]' )
173+ const projectTemplate = getProjectTemplateByKey ( projectTemplates , projectTemplateKey )
174+ this . prepareProjectForCreation ( this . state . updatedProject , projectTemplate )
168175 console . log ( 'saving incomplete project' , this . state . updatedProject )
169176 window . localStorage . setItem ( LS_INCOMPLETE_PROJECT , JSON . stringify ( this . state . updatedProject ) )
170177 }
@@ -176,6 +183,32 @@ class CreateContainer extends React.Component {
176183 // }
177184 }
178185
186+ /**
187+ * Helper method to add additional details required to create project
188+ *
189+ * @param {Object } project project data captured from user
190+ * @param {Object } projectTemplate project template to be used
191+ */
192+ prepareProjectForCreation ( project , projectTemplate ) {
193+ const gaClickId = Cookies . get ( GA_CLICK_ID )
194+ const gaClientId = Cookies . get ( GA_CLIENT_ID )
195+ if ( gaClientId || gaClickId ) {
196+ const googleAnalytics = { }
197+ if ( gaClickId !== 'null' ) {
198+ googleAnalytics [ GA_CLICK_ID ] = gaClickId
199+ }
200+ if ( gaClientId !== 'null' ) {
201+ googleAnalytics [ GA_CLIENT_ID ] = gaClientId
202+ }
203+ _ . set ( project , 'details.utm.google' , googleAnalytics )
204+ }
205+ if ( projectTemplate ) {
206+ project . version = 'v3'
207+ project . templateId = projectTemplate . id
208+ project . type = projectTemplate . category
209+ }
210+ }
211+
179212 /**
180213 * Creates new project if user is already logged in, otherwise, redirects user for registration/login.
181214 */
@@ -185,24 +218,7 @@ class CreateContainer extends React.Component {
185218
186219 this . setState ( { creatingProject : true } , ( ) => {
187220 if ( this . props . userRoles && this . props . userRoles . length > 0 ) {
188- // if user is logged in and has a valid role, create project
189- // uses dirtyProject from the state as it has the latest changes from the user
190- // this.props.createProjectAction(project)
191- const gaClickId = Cookies . get ( GA_CLICK_ID )
192- const gaClientId = Cookies . get ( GA_CLIENT_ID )
193- if ( gaClientId || gaClickId ) {
194- const googleAnalytics = { }
195- if ( gaClickId !== 'null' ) {
196- googleAnalytics [ GA_CLICK_ID ] = gaClickId
197- }
198- if ( gaClientId !== 'null' ) {
199- googleAnalytics [ GA_CLIENT_ID ] = gaClientId
200- }
201- _ . set ( project , 'details.utm.google' , googleAnalytics )
202- }
203- project . version = 'v3'
204- project . templateId = projectTemplate . id
205- project . type = projectTemplate . category
221+ this . prepareProjectForCreation ( project , projectTemplate )
206222 this . props . createProjectAction ( project )
207223 } else {
208224 // redirect to registration/login page
0 commit comments