From e99cf443128a31e0dc09ae503e0d8f70254ef5fc Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Thu, 18 Nov 2021 16:42:11 +1300 Subject: [PATCH] Slight refactor of redirect logic code --- frontend/src/components/steps/zone/ZoneSelector.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/steps/zone/ZoneSelector.js b/frontend/src/components/steps/zone/ZoneSelector.js index 7bacaf6..7b47b33 100644 --- a/frontend/src/components/steps/zone/ZoneSelector.js +++ b/frontend/src/components/steps/zone/ZoneSelector.js @@ -29,12 +29,10 @@ export default function ZoneSelector(props) { const redirectHabitat = zoneSegment && zoneSegment.zone && zoneSegment.zone.redirect_habitat; setZoneSegment(zoneSegment); - if (redirectHabitat) { - props.updateFilterState({ "habitat": { "id": redirectHabitat.id, "name": redirectHabitat.name } }); - props.setRedirectBack(true) - } else { - props.updateFilterState({ "zone": zoneSegment.zone }); - } + // If there is a redirect habitat set then redirect otherwise set the zone as state + const newFilterState = redirectHabitat ? { "habitat": { "id": redirectHabitat.id, "name": redirectHabitat.name }} : { "zone": zoneSegment.zone }; + props.updateFilterState(newFilterState); + props.setRedirectBack(Boolean(redirectHabitat)); props.setNextDisabled(false); }