From 0be60c2ffd0d961c743b8e34a01a6514158cbf42 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Sun, 26 May 2019 10:51:55 +0800 Subject: [PATCH] send project estimation during project creation to the server --- src/config/projectWizard/index.js | 5 ++++- .../create/containers/CreateContainer.jsx | 21 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/config/projectWizard/index.js b/src/config/projectWizard/index.js index 228c54b07..ad7b28821 100644 --- a/src/config/projectWizard/index.js +++ b/src/config/projectWizard/index.js @@ -557,7 +557,10 @@ function getFilteredBuildingBlocks(priceConfig, buildingBlocks, preparedConditio } } _.forEach(filterdBlocks, fb => { - const bb = buildingBlocks[fb] + const bb = { + ...buildingBlocks[fb], + buildingBlockKey: fb, + } matchedBlocks.push(bb) }) }) diff --git a/src/projects/create/containers/CreateContainer.jsx b/src/projects/create/containers/CreateContainer.jsx index b400d8cf6..82b08bf81 100644 --- a/src/projects/create/containers/CreateContainer.jsx +++ b/src/projects/create/containers/CreateContainer.jsx @@ -17,6 +17,7 @@ import { ViewTypes } from 'appirio-tech-react-components/components/Wizard/Wizar import './CreateContainer.scss' import ProjectTypeIcon from '../../../components/ProjectTypeIcon' import { getNewProjectLink } from '../../../helpers/projectHelper' +import { getProductEstimate } from '../../../config/projectWizard' import { CREATE_PROJECT_FAILURE, @@ -136,9 +137,11 @@ class CreateContainer extends React.Component { componentWillMount() { const { processing, userRoles, match, history, templates } = this.props + let projectTemplate // if we are on the project page validate project param if (match.path === '/new-project/:project?/:status?') { const project = match.params.project + projectTemplate = getProjectTemplateByAlias(templates.projectTemplates, project) if ( // if project is defined in URL @@ -149,7 +152,7 @@ class CreateContainer extends React.Component { // project templates are loaded templates.projectTemplates && // if project template doesn't exist - !getProjectTemplateByAlias(templates.projectTemplates, project) + !projectTemplate ) { history.replace('/404') } @@ -163,7 +166,12 @@ class CreateContainer extends React.Component { // if project wizard is loaded after redirection from register page // TODO should we validate the project again? console.log('calling createProjectAction...') - this.props.createProjectAction(incompleteProject, PROJECT_STATUS_IN_REVIEW) + const projectEstimation = getProductEstimate(projectTemplate, incompleteProject) + const projectWithEstimation = { + ...incompleteProject, + estimation: _.get(projectEstimation, 'estimateBlocks', []), + } + this.props.createProjectAction(projectWithEstimation, PROJECT_STATUS_IN_REVIEW) } } else { // if there is not incomplete project, clear the exisitng project from the redux state @@ -241,12 +249,17 @@ class CreateContainer extends React.Component { */ createProject(project) { const { templates: { projectTemplates }} = this.props - const projectTemplate = _.find(projectTemplates, _.get(project, 'templateId')) + const projectTemplate = _.find(projectTemplates, { id: _.get(project, 'templateId') }) this.setState({ creatingProject: true }, () => { if (this.props.userRoles && this.props.userRoles.length > 0) { this.prepareProjectForCreation(project, projectTemplate) - this.props.createProjectAction(project) + const projectEstimation = getProductEstimate(projectTemplate, project) + const projectWithEstimation = { + ...project, + estimation: _.get(projectEstimation, 'estimateBlocks', []), + } + this.props.createProjectAction(projectWithEstimation) } else { // redirect to registration/login page const retUrl = window.location.origin + '/new-project-callback'