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