From eeb4ffe8bab8615ec89aeca7478e513ccca019b7 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 30 Sep 2025 11:18:24 -0600 Subject: [PATCH] better queue handling for the confirm modal --- .../BusterNotifications/useConfirmModal.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/web/src/context/BusterNotifications/useConfirmModal.ts b/apps/web/src/context/BusterNotifications/useConfirmModal.ts index d835e0d59..07e3b8840 100644 --- a/apps/web/src/context/BusterNotifications/useConfirmModal.ts +++ b/apps/web/src/context/BusterNotifications/useConfirmModal.ts @@ -26,12 +26,27 @@ interface QueuedModal extends Omit, 'onOk' | 'onCan onClose: () => void; onOk: () => Promise; onCancel?: () => Promise; + closing?: boolean; } export const useConfirmModalContext = () => { const [modalQueue, setModalQueue] = useState([]); const currentModal = modalQueue[0]; // Get the first modal in the queue + // Common handler to close modal and then remove from queue after animation + const closeModalWithDelay = () => { + // Mark modal as closing (triggers close animation) + setModalQueue((prev) => { + if (prev.length === 0) return prev; + return [{ ...prev[0], closing: true }, ...prev.slice(1)]; + }); + + // Remove from queue after animation completes + setTimeout(() => { + setModalQueue((prev) => prev.slice(1)); + }, 250); + }; + const openConfirmModal = ( props: ConfirmProps ): Promise | T => { @@ -47,8 +62,7 @@ export const useConfirmModalContext = () => { } catch (error) { reject(error); } finally { - // Remove the current modal from the queue - setModalQueue((prev) => prev.slice(1)); + closeModalWithDelay(); } }, onCancel: @@ -60,14 +74,13 @@ export const useConfirmModalContext = () => { } catch (error) { reject(error); } finally { - // Remove the current modal from the queue - setModalQueue((prev) => prev.slice(1)); + closeModalWithDelay(); } } : undefined, onClose: () => { resolve(undefined); - setModalQueue((prev) => prev.slice(1)); + closeModalWithDelay(); }, }; @@ -79,7 +92,7 @@ export const useConfirmModalContext = () => { return currentModal ? { ...currentModal, - open: true, + open: !currentModal.closing, } : { ...defaultConfirmModalProps,