Slight refactor of redirect logic code

This commit is contained in:
Dana Lambert 2021-11-18 16:42:11 +13:00 committed by Alistair McIntyre
parent caedec0a16
commit e99cf44312

View file

@ -29,12 +29,10 @@ export default function ZoneSelector(props) {
const redirectHabitat = zoneSegment && zoneSegment.zone && zoneSegment.zone.redirect_habitat; const redirectHabitat = zoneSegment && zoneSegment.zone && zoneSegment.zone.redirect_habitat;
setZoneSegment(zoneSegment); setZoneSegment(zoneSegment);
if (redirectHabitat) { // If there is a redirect habitat set then redirect otherwise set the zone as state
props.updateFilterState({ "habitat": { "id": redirectHabitat.id, "name": redirectHabitat.name } }); const newFilterState = redirectHabitat ? { "habitat": { "id": redirectHabitat.id, "name": redirectHabitat.name }} : { "zone": zoneSegment.zone };
props.setRedirectBack(true) props.updateFilterState(newFilterState);
} else { props.setRedirectBack(Boolean(redirectHabitat));
props.updateFilterState({ "zone": zoneSegment.zone });
}
props.setNextDisabled(false); props.setNextDisabled(false);
} }