From 8ac0c0c5546b03fe19a84a2aca127e795e38fa18 Mon Sep 17 00:00:00 2001 From: Theo Macron Date: Mon, 22 Jan 2024 17:29:27 +0100 Subject: [PATCH] wip --- .../BootstrapSNCF/ModalSNCF/ModalProvider.tsx | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/front/src/common/BootstrapSNCF/ModalSNCF/ModalProvider.tsx b/front/src/common/BootstrapSNCF/ModalSNCF/ModalProvider.tsx index 16cb7084aa2..87cbdc87102 100644 --- a/front/src/common/BootstrapSNCF/ModalSNCF/ModalProvider.tsx +++ b/front/src/common/BootstrapSNCF/ModalSNCF/ModalProvider.tsx @@ -12,6 +12,7 @@ import React, { } from 'react'; import { Outlet, useLocation } from 'react-router-dom'; import cx from 'classnames'; +import ConfirmModal from './ConfirmModal'; /** * Type of the modal context @@ -47,6 +48,7 @@ export const ModalContext = createContext(initialModalContext); export const ModalSNCF: FC = () => { const modalRef = useRef(null); const { isOpen, content, closeModal, size, className } = useContext(ModalContext); + const [isConfirmModalOpen, setConfirmModalOpen] = useState(false); /** * Register click outside event to close the modal. @@ -61,13 +63,8 @@ export const ModalSNCF: FC = () => { !modalRef.current.contains(event.target as HTMLElement) ) { const isXlModal = modalRef.current.classList.contains('modal-xl'); - if ( - isXlModal && - window.confirm( - 'Vous êtes sur le point de quitter le mode édition. Toute modification non sauvegardée sera perdue' - ) - ) { - closeModal(); + if (isXlModal) { + setConfirmModalOpen(true); } else if (!isXlModal) { closeModal(); } @@ -80,6 +77,15 @@ export const ModalSNCF: FC = () => { }; }, [isOpen, closeModal]); + const handleConfirm = () => { + setConfirmModalOpen(false); + closeModal(); + }; + + const handleCancel = () => { + setConfirmModalOpen(false); + }; + if (!content) { return null; } @@ -91,6 +97,7 @@ export const ModalSNCF: FC = () => { role="dialog" aria-hidden="true" > + {isConfirmModalOpen && }