Skip to content

Commit

Permalink
allow click on protected areas when there are not change
Browse files Browse the repository at this point in the history
  • Loading branch information
anamontiaga committed Jan 8, 2024
1 parent eeed3e9 commit ec38291
Showing 1 changed file with 39 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,64 +120,48 @@ export const WDPAThreshold = ({ onGoBack }: { onGoBack: () => void }): JSX.Eleme
const areProjectPAreasSelected = !!projectPAreasSelectedIds.length;

const handleSubmit = useCallback(
(values, form) => {
(values) => {
const { wdpaThreshold } = values;

const thresholdTouched = form.getFieldState('wdpaThreshold')?.dirty;

if (thresholdTouched) {
setSubmitting(true);
saveScenarioProtectedAreasMutation.mutate(
{
id: `${sid}`,
data: {
areas: selectedProtectedAreas,
threshold: +(wdpaThreshold * 100).toFixed(0),
},
setSubmitting(true);
saveScenarioProtectedAreasMutation.mutate(
{
id: `${sid}`,
data: {
areas: selectedProtectedAreas,
threshold: +(wdpaThreshold * 100).toFixed(0),
},
{
onSuccess: () => {
addToast(
'save-scenario-wdpa',
<>
<h2 className="font-medium">Success!</h2>
<p className="text-sm">Scenario protected areas threshold saved</p>
</>,
{
level: 'success',
}
);
},
onError: () => {
addToast(
'error-scenario-wdpa',
<>
<h2 className="font-medium">Error!</h2>
<p className="text-sm">Scenario protected areas threshold not saved</p>
</>,
{
level: 'error',
}
);
},
onSettled: () => {
setSubmitting(false);
},
}
);
}
if (!thresholdTouched) {
addToast(
'save-scenario-wdpa',
<>
<h2 className="font-medium"></h2>
<p className="text-sm">No modifications have been made to the protected areas.</p>
</>,
{
level: 'info',
}
);
}
},
{
onSuccess: () => {
addToast(
'save-scenario-wdpa',
<>
<h2 className="font-medium">Success!</h2>
<p className="text-sm">Scenario protected areas threshold saved</p>
</>,
{
level: 'success',
}
);
},
onError: () => {
addToast(
'error-scenario-wdpa',
<>
<h2 className="font-medium">Error!</h2>
<p className="text-sm">Scenario protected areas threshold not saved</p>
</>,
{
level: 'error',
}
);
},
onSettled: () => {
setSubmitting(false);
},
}
);
},
[saveScenarioProtectedAreasMutation, selectedProtectedAreas, sid, addToast]
);
Expand Down

0 comments on commit ec38291

Please sign in to comment.