diff --git a/client/src/app/pages/applications/applications-table/applications-table.tsx b/client/src/app/pages/applications/applications-table/applications-table.tsx index 065c0ee0c6..990ee9e830 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -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 { @@ -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", + }); } }; @@ -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", + }); } }; diff --git a/client/src/app/pages/archetypes/archetypes-page.tsx b/client/src/app/pages/archetypes/archetypes-page.tsx index 170e7e30bc..82eefd106b 100644 --- a/client/src/app/pages/archetypes/archetypes-page.tsx +++ b/client/src/app/pages/archetypes/archetypes-page.tsx @@ -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 { @@ -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", + }); } }; @@ -152,8 +145,7 @@ const Archetypes: React.FC = () => { }; const { mutate: deleteReview } = useDeleteReviewMutation( - onDeleteReviewSuccess, - onDeleteError + onDeleteReviewSuccess ); const discardReview = async (archetype: Archetype) => { @@ -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", + }); } }; diff --git a/client/src/app/queries/reviews.ts b/client/src/app/queries/reviews.ts index c841da5880..1bde4905a2 100644 --- a/client/src/app/queries/reviews.ts +++ b/client/src/app/queries/reviews.ts @@ -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, }); };