Skip to content

Commit

Permalink
🐛 display assessment delete error only once for bulk action (#1588)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Dec 6, 2023
1 parent 1198255 commit cc14acb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,32 +249,11 @@ export const ApplicationsTable: React.FC = () => {
queryClient.invalidateQueries([ApplicationsQueryKey]);
};

const onDeleteAssessmentSuccess = (name: string) => {
pushNotification({
title: t("toastr.success.assessmentDiscarded", {
application: name,
}),
variant: "success",
});
queryClient.invalidateQueries([ApplicationsQueryKey]);
};

const onDeleteError = (error: AxiosError) => {
pushNotification({
title: getAxiosErrorMessage(error),
variant: "danger",
});
};

const { mutate: deleteReview } = useDeleteReviewMutation(
onDeleteReviewSuccess,
onDeleteError
onDeleteReviewSuccess
);

const { mutate: deleteAssessment } = useDeleteAssessmentMutation(
onDeleteAssessmentSuccess,
onDeleteError
);
const { mutate: deleteAssessment } = useDeleteAssessmentMutation();

const discardAssessment = async (application: Application) => {
try {
Expand All @@ -286,10 +265,22 @@ export const ApplicationsTable: React.FC = () => {
applicationName: application.name,
});
})
);
).then(() => {
pushNotification({
title: t("toastr.success.assessmentDiscarded", {
application: application.name,
}),
variant: "success",
});
queryClient.invalidateQueries([ApplicationsQueryKey]);
});
}
} catch (error) {
console.error("Error while deleting assessments:", error);
pushNotification({
title: getAxiosErrorMessage(error as AxiosError),
variant: "danger",
});
}
};

Expand All @@ -303,6 +294,10 @@ export const ApplicationsTable: React.FC = () => {
}
} catch (error) {
console.error("Error while deleting review:", error);
pushNotification({
title: getAxiosErrorMessage(error as AxiosError),
variant: "danger",
});
}
};

Expand Down
40 changes: 18 additions & 22 deletions client/src/app/pages/archetypes/archetypes-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,8 @@ const Archetypes: React.FC = () => {
}),
onError
);
const onDeleteAssessmentSuccess = (name: string) => {
pushNotification({
title: t("toastr.success.assessmentDiscarded", {
application: name,
}),
variant: "success",
});
};

const onDeleteError = (error: AxiosError) => {
pushNotification({
title: getAxiosErrorMessage(error),
variant: "danger",
});
};

const { mutate: deleteAssessment } = useDeleteAssessmentMutation(
onDeleteAssessmentSuccess,
onDeleteError
);
const { mutate: deleteAssessment } = useDeleteAssessmentMutation();

const discardAssessment = async (archetype: Archetype) => {
try {
Expand All @@ -135,10 +117,21 @@ const Archetypes: React.FC = () => {
archetypeId: archetype.id,
});
})
);
).then(() => {
pushNotification({
title: t("toastr.success.assessmentDiscarded", {
application: archetype.name,
}),
variant: "success",
});
});
}
} catch (error) {
console.error("Error while deleting assessments:", error);
pushNotification({
title: getAxiosErrorMessage(error as AxiosError),
variant: "danger",
});
}
};

Expand All @@ -152,8 +145,7 @@ const Archetypes: React.FC = () => {
};

const { mutate: deleteReview } = useDeleteReviewMutation(
onDeleteReviewSuccess,
onDeleteError
onDeleteReviewSuccess
);

const discardReview = async (archetype: Archetype) => {
Expand All @@ -166,6 +158,10 @@ const Archetypes: React.FC = () => {
}
} catch (error) {
console.error("Error while deleting review:", error);
pushNotification({
title: getAxiosErrorMessage(error as AxiosError),
variant: "danger",
});
}
};

Expand Down
8 changes: 4 additions & 4 deletions client/src/app/queries/reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ export interface IReviewMutation {
}

export const useDeleteReviewMutation = (
onSuccess: (name: string) => void,
onError: (err: AxiosError) => void
onSuccess?: (name: string) => void,
onError?: (err: AxiosError) => void
) => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: (args: IReviewMutation) => deleteReview(args.id),
onSuccess: (_, args) => {
onSuccess(args.name);
onSuccess && onSuccess(args.name);
queryClient.invalidateQueries([reviewsQueryKey]);
},
onError: onError,
onError: onError && onError,
});
};

Expand Down

0 comments on commit cc14acb

Please sign in to comment.