Skip to content

Commit

Permalink
fix: no confirm modal on direct-link before connection is made
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Dec 16, 2024
1 parent 3a47bb0 commit 271cb3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
26 changes: 17 additions & 9 deletions src/components/calls-page/calls-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Container>
<ButtonWrapper>
<NavigateToRootButton
resetOnExitRequest={() => setConfirmExitModalOpen(true)}
resetOnExitRequest={() => {
if (isEmpty) {
runExitAllCalls();
} else {
setConfirmExitModalOpen(true);
}
}}
/>
{confirmExitModalOpen && (
<Modal onClose={() => setConfirmExitModalOpen(false)}>
Expand Down
23 changes: 14 additions & 9 deletions src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
Expand Down

0 comments on commit 271cb3a

Please sign in to comment.