Skip to content

Commit

Permalink
update plant index when adding or removing and set percent_area_cover…
Browse files Browse the repository at this point in the history
…ed to 100 if only 1 plant
  • Loading branch information
brennanwebster authored and micheal-w-wells committed Sep 27, 2023
1 parent 01ef3c3 commit b5156de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ const InvasivePlant: React.FC<IInvasivePlantComponent> = ({ index, species, clas
setFormDetails((prevDetails) => {
const newSpeciesArr = [...prevDetails.form_data.invasive_plants];
newSpeciesArr.splice(index, 1);

newSpeciesArr.forEach((item, i) => {
item.index = i;
});

if (newSpeciesArr.length === 1) {
newSpeciesArr[0].percent_area_covered = 100;
}

return {
...prevDetails,
form_data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ const InvasivePlant: React.FC<IInvasivePlantComponent> = ({ index, species, clas
setFormDetails((prevDetails) => {
const newSpeciesArr = [...prevDetails.form_data.invasive_plants];
newSpeciesArr.splice(index, 1);

newSpeciesArr.forEach((item, i) => {
item.index = i;
});

if (newSpeciesArr.length === 1) {
newSpeciesArr[0].percent_area_covered = 100;
}

return {
...prevDetails,
form_data: {
Expand Down

0 comments on commit b5156de

Please sign in to comment.