Skip to content

Commit

Permalink
stays in scenario/protected-areas after applying changes
Browse files Browse the repository at this point in the history
  • Loading branch information
agnlez committed Nov 20, 2023
1 parent 410417f commit cd3252d
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useCallback, useMemo, useState, useEffect } from 'react';

import { Form as FormRFF, Field as FieldRFF } from 'react-final-form';

// import { useDispatch, useSelector } from 'react-redux';
import { useRouter } from 'next/router';

import { useAppDispatch, useAppSelector } from 'store/hooks';
Expand All @@ -21,18 +20,17 @@ import Slider from 'components/forms/slider';
import { composeValidators } from 'components/forms/validations';
import InfoButton from 'components/info-button';
import Loading from 'components/loading';
import { TABS } from 'layout/project/navigation/constants';
import Section from 'layout/section';

import THRESHOLD_IMG from 'images/info-buttons/img_threshold.png';

import ProtectedAreasSelected from '../pa-selected';

export const WDPAThreshold = ({ onGoBack }): JSX.Element => {
export const WDPAThreshold = ({ onGoBack }: { onGoBack: () => void }): JSX.Element => {
const [submitting, setSubmitting] = useState(false);

const { addToast } = useToasts();
const { push, query } = useRouter();
const { query } = useRouter();
const { pid, sid } = query as { pid: string; sid: string };

const { wdpaCategories } = useAppSelector((state) => state[`/scenarios/${sid}/edit`]);
Expand Down Expand Up @@ -137,7 +135,6 @@ export const WDPAThreshold = ({ onGoBack }): JSX.Element => {
},
{
onSuccess: () => {
setSubmitting(false);
addToast(
'save-scenario-wdpa',
<>
Expand All @@ -148,11 +145,9 @@ export const WDPAThreshold = ({ onGoBack }): JSX.Element => {
level: 'success',
}
);
push(`/projects/${pid}/scenarios/${sid}/edit?tab=${TABS['scenario-cost-surface']}`);
onGoBack();
},
onError: () => {
setSubmitting(false);

addToast(
'error-scenario-wdpa',
<>
Expand All @@ -164,10 +159,13 @@ export const WDPAThreshold = ({ onGoBack }): JSX.Element => {
}
);
},
onSettled: () => {
setSubmitting(false);
},
}
);
},
[saveScenarioProtectedAreasMutation, selectedProtectedAreas, sid, addToast, pid, push]
[saveScenarioProtectedAreasMutation, selectedProtectedAreas, sid, addToast, onGoBack]
);

useEffect(() => {
Expand Down

0 comments on commit cd3252d

Please sign in to comment.