diff --git a/src/components/forms/CreateProjectForm.js b/src/components/forms/CreateProjectForm.js index 2cae163a..e59f3f38 100644 --- a/src/components/forms/CreateProjectForm.js +++ b/src/components/forms/CreateProjectForm.js @@ -173,10 +173,6 @@ const CreateProjectForm = withRouter( dataToSend.coBenefits = newCoBenefits; } - if (!_.isEmpty(estimationsState)) { - dataToSend.estimations = estimationsState; - } - if (!_.isEmpty(newLabels)) { dataToSend.labels = newLabels; } @@ -201,6 +197,10 @@ const CreateProjectForm = withRouter( dataToSend.relatedProjects = newRelatedProjects; } + if (!_.isEmpty(estimationsState)) { + dataToSend.estimations = estimationsState; + } + dispatch(postNewProject(dataToSend)); } else { setTabValue(prev => prev + 1); diff --git a/src/components/forms/EditProjectsForm.js b/src/components/forms/EditProjectsForm.js index 5b7928a5..a1caddc8 100644 --- a/src/components/forms/EditProjectsForm.js +++ b/src/components/forms/EditProjectsForm.js @@ -28,6 +28,7 @@ import { SelectSizeEnum, SelectTypeEnum, SelectStateEnum, + EstimationsRepeater, } from '..'; import LabelsRepeater from './LabelsRepeater'; import IssuanceRepeater from './IssuanceRepeater'; @@ -47,6 +48,7 @@ const EditProjectsForm = ({ onClose }) => { const [issuance, setIssuance] = useState([]); const [locations, setLocations] = useState([]); const [relatedProjects, setRelatedProjects] = useState([]); + const [estimationsState, setEstimationsState] = useState([]); const [coBenefits, setCoBenefits] = useState([]); const [editedProjects, setEditProjects] = useState({}); const [tabValue, setTabValue] = useState(0); @@ -157,6 +159,7 @@ const EditProjectsForm = ({ onClose }) => { validationBody: climatewarehouseProjects.validationBody, validationDate: climatewarehouseProjects.validationDate, }); + setIssuance( climatewarehouseProjects.issuances.map(issuanceKey => _.pick( @@ -169,6 +172,7 @@ const EditProjectsForm = ({ onClose }) => { ), ), ); + setLocations( climatewarehouseProjects.projectLocations.map(projectLoc => _.pick( @@ -179,11 +183,13 @@ const EditProjectsForm = ({ onClose }) => { ), ), ); + setCoBenefits( climatewarehouseProjects.coBenefits.map(cobenefit => _.pick(cobenefit, 'cobenefit'), ), ); + setLabelsRepeaterValues( climatewarehouseProjects.labels.map(label => _.pick( @@ -199,11 +205,23 @@ const EditProjectsForm = ({ onClose }) => { ), ), ); + setRelatedProjects( climatewarehouseProjects.relatedProjects.map(relatedProject => _.pick(relatedProject, 'relationshipType', 'registry'), ), ); + + setEstimationsState( + climatewarehouseProjects.estimations.map(estimation => + _.pick( + estimation, + 'creditingPeriodStart', + 'creditingPeriodEnd', + 'unitCount', + ), + ), + ); }, [climatewarehouseProjects]); const handleEditProjects = () => { @@ -241,6 +259,10 @@ const EditProjectsForm = ({ onClose }) => { dataToSend.relatedProjects = relatedProjects; } + if (!_.isEmpty(estimationsState)) { + dataToSend.estimations = estimationsState; + } + dispatch(updateProjectRecord(dataToSend)); }; @@ -297,6 +319,11 @@ const EditProjectsForm = ({ onClose }) => { id: 'related-projects', })} /> +
{ setRelatedProjectsState={setRelatedProjects} /> + + +
}