Skip to content

Commit

Permalink
fix: remove noticebox and add alerterror
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Oct 30, 2024
1 parent f993afd commit e39d360
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
13 changes: 5 additions & 8 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-10-30T11:27:59.565Z\n"
"PO-Revision-Date: 2024-10-30T11:27:59.565Z\n"
"POT-Creation-Date: 2024-10-30T12:38:53.423Z\n"
"PO-Revision-Date: 2024-10-30T12:38:53.423Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -1489,16 +1489,16 @@ msgstr "{{ scheduledEvents }} scheduled"
msgid "Stages and Events"
msgstr "Stages and Events"

msgid "An error occurred while unlinking and deleting the event."
msgstr "An error occurred while unlinking and deleting the event."

msgid ""
"Are you sure you want to unlink and delete the event? This will permanently "
"remove the event and all related data."
msgstr ""
"Are you sure you want to unlink and delete the event? This will permanently "
"remove the event and all related data."

msgid "There was a problem unlinking and deleting the event"
msgstr "There was a problem unlinking and deleting the event"

msgid "Yes, unlink and delete event"
msgstr "Yes, unlink and delete event"

Expand All @@ -1508,9 +1508,6 @@ msgstr "Unlink relationship"
msgid "Are you sure you want to unlink this relationship?"
msgstr "Are you sure you want to unlink this relationship?"

msgid "There was a problem unlinking the relationship"
msgstr "There was a problem unlinking the relationship"

msgid "Yes, unlink relationship"
msgstr "Yes, unlink relationship"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
ModalActions,
ModalContent,
ModalTitle,
NoticeBox,
} from '@dhis2/ui';
import { useDataEngine } from '@dhis2/app-runtime';
import log from 'loglevel';
import { useDataEngine, useAlert } from '@dhis2/app-runtime';
import { useMutation, useQueryClient } from 'react-query';
import { ReactQueryAppNamespace } from 'capture-core/utils/reactQueryHelpers';
import type { Props } from './UnlinkAndDeleteModal.types';
Expand All @@ -22,6 +22,10 @@ export const UnlinkAndDeleteModal = ({
}: Props) => {
const dataEngine = useDataEngine();
const queryClient = useQueryClient();
const { show: showErrorAlert } = useAlert(
i18n.t('An error occurred while unlinking and deleting the event.'),
{ critical: true },
);

const deleteEvent = async () => {
const mutation = {
Expand All @@ -42,6 +46,13 @@ export const UnlinkAndDeleteModal = ({
]);
setOpenModal(false);
},
onError: (error) => {
showErrorAlert();
log.error(
`Failed to unlink and delete event with ID: ${eventId}`,
error,
);
},
});

return (
Expand All @@ -53,14 +64,6 @@ export const UnlinkAndDeleteModal = ({
'Are you sure you want to unlink and delete the event? This will permanently remove the event and all related data.',
)}
</p>
{mutation.isError && (
<NoticeBox
title={i18n.t('There was a problem unlinking and deleting the event')}
error
>
{mutation.error?.message}
</NoticeBox>
)}
</ModalContent>
<ModalActions>
<ButtonStrip end>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
ModalActions,
ButtonStrip,
Button,
NoticeBox,
} from '@dhis2/ui';
import { useDataEngine } from '@dhis2/app-runtime';
import log from 'loglevel';
import { useDataEngine, useAlert } from '@dhis2/app-runtime';
import { useMutation, useQueryClient } from 'react-query';
import { ReactQueryAppNamespace } from 'capture-core/utils/reactQueryHelpers';
import type { Props } from './UnlinkModal.types';
Expand All @@ -22,6 +22,10 @@ export const UnlinkModal = ({
}: Props) => {
const dataEngine = useDataEngine();
const queryClient = useQueryClient();
const { show: showErrorAlert } = useAlert(
i18n.t('An error occurred while unlinking and deleting the event.'),
{ critical: true },
);

const deleteRelationship = async () => {
const mutation = {
Expand All @@ -42,6 +46,13 @@ export const UnlinkModal = ({
]);
setOpenModal(false);
},
onError: (error) => {
showErrorAlert();
log.error(
`Failed to remove relationship with id ${relationshipId}`,
error,
);
},
});

return (
Expand All @@ -51,14 +62,6 @@ export const UnlinkModal = ({
</ModalTitle>
<ModalContent>
<p>{i18n.t('Are you sure you want to unlink this relationship?')}</p>
{mutation.isError && (
<NoticeBox
title={i18n.t('There was a problem unlinking the relationship')}
error
>
{mutation.error?.message}
</NoticeBox>
)}
</ModalContent>
<ModalActions>
<ButtonStrip end>
Expand Down

0 comments on commit e39d360

Please sign in to comment.