diff --git a/src/components/calls-page/calls-page.tsx b/src/components/calls-page/calls-page.tsx index db6e256..e0c7564 100644 --- a/src/components/calls-page/calls-page.tsx +++ b/src/components/calls-page/calls-page.tsx @@ -74,21 +74,29 @@ export const CallsPage = () => { const runExitAllCalls = async () => { setProductionId(null); navigate("/"); - Object.entries(calls).forEach(([callId]) => { - if (callId) { - dispatch({ - type: "REMOVE_CALL", - payload: { id: callId }, - }); - } - }); + if (!isEmpty) { + Object.entries(calls).forEach(([callId]) => { + if (callId) { + dispatch({ + type: "REMOVE_CALL", + payload: { id: callId }, + }); + } + }); + } }; return ( setConfirmExitModalOpen(true)} + resetOnExitRequest={() => { + if (isEmpty) { + runExitAllCalls(); + } else { + setConfirmExitModalOpen(true); + } + }} /> {confirmExitModalOpen && ( setConfirmExitModalOpen(false)}> diff --git a/src/components/header.tsx b/src/components/header.tsx index 352609f..51ce1a9 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -35,23 +35,28 @@ export const Header: FC = () => { const navigate = useNavigate(); const location = useLocation(); const { playExitSound } = useAudioCue(); + const isEmpty = Object.values(calls).length === 0; const runExitAllCalls = () => { setConfirmExitModalOpen(false); navigate("/"); playExitSound(); - Object.entries(calls).forEach(([callId]) => { - if (callId) { - dispatch({ - type: "REMOVE_CALL", - payload: { id: callId }, - }); - } - }); + if (!isEmpty) { + Object.entries(calls).forEach(([callId]) => { + if (callId) { + dispatch({ + type: "REMOVE_CALL", + payload: { id: callId }, + }); + } + }); + } }; const returnToRoot = () => { - if (location.pathname.includes("/line")) { + if (location.pathname.includes("/line") && isEmpty) { + runExitAllCalls(); + } else if (location.pathname.includes("/line")) { setConfirmExitModalOpen(true); } else { navigate("/");