260728_01_ENH: 통화중 뒤로가기, 새로고침(단축키) 막기
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { Suspense, useEffect, useMemo, useRef, useState } from "react";
|
import { Suspense, useEffect, useMemo, useState } from "react";
|
||||||
import { useRouter, useSearchParams } from "next/navigation";
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
import { ArrowLeft, CalendarClock, RefreshCw } from "lucide-react";
|
import { ArrowLeft, CalendarClock, RefreshCw } from "lucide-react";
|
||||||
import { useMounted } from "@kri/common/hooks";
|
import { useMounted } from "@kri/common/hooks";
|
||||||
@@ -40,7 +40,6 @@ const ListContactPageContent = () => {
|
|||||||
const userRole = auth?.user?.userRole ?? 0;
|
const userRole = auth?.user?.userRole ?? 0;
|
||||||
const ctiCallPhase = useCtiCallPhase();
|
const ctiCallPhase = useCtiCallPhase();
|
||||||
const shouldBlockNavigation = CTI_CALL_PHASE.includes(ctiCallPhase);
|
const shouldBlockNavigation = CTI_CALL_PHASE.includes(ctiCallPhase);
|
||||||
const allowPageExitRef = useRef(false);
|
|
||||||
|
|
||||||
const queriesEnabled = mounted && prjctIdx > 0;
|
const queriesEnabled = mounted && prjctIdx > 0;
|
||||||
const enabled = queriesEnabled && !!sid;
|
const enabled = queriesEnabled && !!sid;
|
||||||
@@ -49,13 +48,29 @@ const ListContactPageContent = () => {
|
|||||||
if (!shouldBlockNavigation) return;
|
if (!shouldBlockNavigation) return;
|
||||||
|
|
||||||
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
||||||
if (allowPageExitRef.current) return;
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
//구형 브라우저를 커버하기 위함
|
||||||
event.returnValue = true;
|
event.returnValue = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleReloadShortcut = (event: KeyboardEvent) => {
|
||||||
|
const isReloadShortcut =
|
||||||
|
event.key === "F5" ||
|
||||||
|
((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "r");
|
||||||
|
|
||||||
|
if (!isReloadShortcut) return;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
if (!event.repeat) alert("통화 중에는 새로고침할 수 없습니다.");
|
||||||
|
};
|
||||||
|
|
||||||
window.addEventListener("beforeunload", handleBeforeUnload);
|
window.addEventListener("beforeunload", handleBeforeUnload);
|
||||||
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
window.addEventListener("keydown", handleReloadShortcut, true);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("beforeunload", handleBeforeUnload);
|
||||||
|
window.removeEventListener("keydown", handleReloadShortcut, true);
|
||||||
|
};
|
||||||
}, [shouldBlockNavigation]);
|
}, [shouldBlockNavigation]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -85,12 +100,7 @@ const ListContactPageContent = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shouldLeave = window.confirm("통화 중입니다. 현재 페이지를 떠나시겠습니까?");
|
alert("통화 중에는 페이지를 이동할 수 없습니다.");
|
||||||
if (shouldLeave) {
|
|
||||||
allowPageExitRef.current = true;
|
|
||||||
window.history.back();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
isRestoringHistory = true;
|
isRestoringHistory = true;
|
||||||
window.history.forward();
|
window.history.forward();
|
||||||
@@ -126,7 +136,7 @@ const ListContactPageContent = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (sid) return;
|
if (sid) return;
|
||||||
alert("sid가 없으면 진행할 수 없습니다.");
|
alert("sid가 없으면 진행할 수 없습니다.");
|
||||||
router.back();
|
router.push("/list/manage");
|
||||||
}, [sid, router]);
|
}, [sid, router]);
|
||||||
|
|
||||||
const handleNavigateToSid = (nextSid: string) => {
|
const handleNavigateToSid = (nextSid: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user