From 90618c46227a57f9a62f22995cf86dfe3007a878 Mon Sep 17 00:00:00 2001 From: Nathan Panchout Date: Mon, 16 Dec 2024 20:27:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(frontend)=20confirmation=20modal=20to?= =?UTF-8?q?=20disable=20mailbox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/MailDomainsActions.tsx | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/src/frontend/apps/desk/src/features/mail-domains/mailboxes/components/MailDomainsActions.tsx b/src/frontend/apps/desk/src/features/mail-domains/mailboxes/components/MailDomainsActions.tsx index 74d75a0db..a60b82406 100644 --- a/src/frontend/apps/desk/src/features/mail-domains/mailboxes/components/MailDomainsActions.tsx +++ b/src/frontend/apps/desk/src/features/mail-domains/mailboxes/components/MailDomainsActions.tsx @@ -1,4 +1,11 @@ -import { Button } from '@openfun/cunningham-react'; +import { + Button, + Modal, + ModalSize, + VariantType, + useModal, + useToastProvider, +} from '@openfun/cunningham-react'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -20,15 +27,24 @@ export const MailDomainsActions = ({ const { t } = useTranslation(); const [isDropOpen, setIsDropOpen] = useState(false); const isEnabled = mailbox.status === 'enabled'; + const disableModal = useModal(); + const { toast } = useToastProvider(); const { mutate: updateMailboxStatus } = useUpdateMailboxStatus(); const handleUpdateMailboxStatus = () => { - updateMailboxStatus({ - mailDomainSlug: mailDomain.slug, - mailboxId: mailbox.id, - isEnabled: !isEnabled, - }); + disableModal.close(); + updateMailboxStatus( + { + mailDomainSlug: mailDomain.slug, + mailboxId: mailbox.id, + isEnabled: !isEnabled, + }, + { + onError: () => + toast(t('Failed to update mailbox status'), VariantType.ERROR), + }, + ); }; if (mailbox.status === 'pending' || mailbox.status === 'failed') { @@ -52,7 +68,11 @@ export const MailDomainsActions = ({ aria-label={t('Open the modal to update the role of this access')} onClick={() => { setIsDropOpen(false); - handleUpdateMailboxStatus(); + if (isEnabled) { + disableModal.open(); + } else { + handleUpdateMailboxStatus(); + } }} fullWidth color="primary-text" @@ -68,6 +88,28 @@ export const MailDomainsActions = ({ + {t('Disable mailbox')}} + size={ModalSize.MEDIUM} + rightActions={ + + + + + } + > + + {t( + 'Are you sure you want to disable this mailbox? This action results in the deletion of the calendar, address book, etc.', + )} + + ); };