Skip to content

Commit

Permalink
feat: add estimations tab to project add / edit forms
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstefanequilobe committed Feb 10, 2022
1 parent 7aceaf5 commit 06c54c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/forms/CreateProjectForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ const CreateProjectForm = withRouter(
dataToSend.coBenefits = newCoBenefits;
}

if (!_.isEmpty(estimationsState)) {
dataToSend.estimations = estimationsState;
}

if (!_.isEmpty(newLabels)) {
dataToSend.labels = newLabels;
}
Expand All @@ -201,6 +197,10 @@ const CreateProjectForm = withRouter(
dataToSend.relatedProjects = newRelatedProjects;
}

if (!_.isEmpty(estimationsState)) {
dataToSend.estimations = estimationsState;
}

dispatch(postNewProject(dataToSend));
} else {
setTabValue(prev => prev + 1);
Expand Down
33 changes: 33 additions & 0 deletions src/components/forms/EditProjectsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
SelectSizeEnum,
SelectTypeEnum,
SelectStateEnum,
EstimationsRepeater,
} from '..';
import LabelsRepeater from './LabelsRepeater';
import IssuanceRepeater from './IssuanceRepeater';
Expand All @@ -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);
Expand Down Expand Up @@ -157,6 +159,7 @@ const EditProjectsForm = ({ onClose }) => {
validationBody: climatewarehouseProjects.validationBody,
validationDate: climatewarehouseProjects.validationDate,
});

setIssuance(
climatewarehouseProjects.issuances.map(issuanceKey =>
_.pick(
Expand All @@ -169,6 +172,7 @@ const EditProjectsForm = ({ onClose }) => {
),
),
);

setLocations(
climatewarehouseProjects.projectLocations.map(projectLoc =>
_.pick(
Expand All @@ -179,11 +183,13 @@ const EditProjectsForm = ({ onClose }) => {
),
),
);

setCoBenefits(
climatewarehouseProjects.coBenefits.map(cobenefit =>
_.pick(cobenefit, 'cobenefit'),
),
);

setLabelsRepeaterValues(
climatewarehouseProjects.labels.map(label =>
_.pick(
Expand All @@ -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 = () => {
Expand Down Expand Up @@ -241,6 +259,10 @@ const EditProjectsForm = ({ onClose }) => {
dataToSend.relatedProjects = relatedProjects;
}

if (!_.isEmpty(estimationsState)) {
dataToSend.estimations = estimationsState;
}

dispatch(updateProjectRecord(dataToSend));
};

Expand Down Expand Up @@ -297,6 +319,11 @@ const EditProjectsForm = ({ onClose }) => {
id: 'related-projects',
})}
/>
<Tab
label={intl.formatMessage({
id: 'estimations',
})}
/>
</Tabs>
<div>
<TabPanel
Expand Down Expand Up @@ -946,6 +973,12 @@ const EditProjectsForm = ({ onClose }) => {
setRelatedProjectsState={setRelatedProjects}
/>
</TabPanel>
<TabPanel value={tabValue} index={6}>
<EstimationsRepeater
estimationsState={estimationsState}
setEstimationsState={setEstimationsState}
/>
</TabPanel>
</div>
</div>
}
Expand Down

0 comments on commit 06c54c4

Please sign in to comment.