260727_02_ENH: 통화중 이동 최대한 막기 #12
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { Suspense, useEffect, useMemo, useState } from "react";
|
||||
import { Suspense, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { ArrowLeft, CalendarClock, RefreshCw } from "lucide-react";
|
||||
import { useMounted } from "@kri/common/hooks";
|
||||
@@ -18,6 +18,10 @@ import ReservationListDialog from "@/components/dialog/ReservationListDialog";
|
||||
import { createEmptyListFilter, type listHeader } from "@/types/list";
|
||||
import type { ResultCode } from "@/types/project";
|
||||
import { isManager } from "@/utils/userRole";
|
||||
import {useCtiCallPhase} from "@/hooks/useCtiCallPhase";
|
||||
import {CTI_CALL_PHASE} from "@/const/ctiConst";
|
||||
|
||||
const CALL_NAVIGATION_GUARD_KEY = "__listContactCallNavigationGuard";
|
||||
|
||||
const ListContactPageContent = () => {
|
||||
const router = useRouter();
|
||||
@@ -34,28 +38,67 @@ const ListContactPageContent = () => {
|
||||
const itrntPrjctCd = selectedProject?.itrntPrjctCd ?? "";
|
||||
const userId = auth?.user?.userId ?? "";
|
||||
const userRole = auth?.user?.userRole ?? 0;
|
||||
const ctiCallPhase = useCtiCallPhase();
|
||||
const shouldBlockNavigation = CTI_CALL_PHASE.includes(ctiCallPhase);
|
||||
const allowPageExitRef = useRef(false);
|
||||
|
||||
// 이 페이지 진입 시의 prjctIdx를 기준으로 기록해두고, 이후 외부(프로젝트 선택기 등)에서
|
||||
// prjctIdx가 바뀌면 더 이상 현재 sid가 유효하지 않으므로 목록 관리 화면으로 내보낸다.
|
||||
// isStaleProject는 렌더 시점에 기준 프로젝트와 비교해서, 리다이렉트 effect가 돌기 전에도
|
||||
// 아래 쿼리들이 잘못된 prjctIdx+sid 조합으로 요청을 보내 에러 alert를 띄우는 걸 막는다.
|
||||
const [baselinePrjctIdx, setBaselinePrjctIdx] = useState<number | null>(null);
|
||||
const isStaleProject = baselinePrjctIdx !== null && baselinePrjctIdx !== prjctIdx;
|
||||
const queriesEnabled = mounted && prjctIdx > 0 && !isStaleProject;
|
||||
const queriesEnabled = mounted && prjctIdx > 0;
|
||||
const enabled = queriesEnabled && !!sid;
|
||||
|
||||
useEffect(() => {
|
||||
if (!mounted || prjctIdx <= 0) return;
|
||||
if (!shouldBlockNavigation) return;
|
||||
|
||||
if (baselinePrjctIdx === null) {
|
||||
setBaselinePrjctIdx(prjctIdx);
|
||||
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
||||
if (allowPageExitRef.current) return;
|
||||
event.preventDefault();
|
||||
event.returnValue = true;
|
||||
};
|
||||
|
||||
window.addEventListener("beforeunload", handleBeforeUnload);
|
||||
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
||||
}, [shouldBlockNavigation]);
|
||||
|
||||
useEffect(() => {
|
||||
const hasGuardEntry = window.history.state?.[CALL_NAVIGATION_GUARD_KEY] === true;
|
||||
|
||||
if (!shouldBlockNavigation) {
|
||||
if (hasGuardEntry) window.history.back();
|
||||
return;
|
||||
}
|
||||
|
||||
if (baselinePrjctIdx !== prjctIdx) {
|
||||
router.replace('/list/manage');
|
||||
let isRestoringHistory = false;
|
||||
|
||||
if (!hasGuardEntry) {
|
||||
window.history.pushState(
|
||||
{
|
||||
...window.history.state,
|
||||
[CALL_NAVIGATION_GUARD_KEY]: true,
|
||||
},
|
||||
"",
|
||||
window.location.href,
|
||||
);
|
||||
}
|
||||
}, [baselinePrjctIdx, prjctIdx, mounted, router]);
|
||||
|
||||
const handlePopState = () => {
|
||||
if (isRestoringHistory) {
|
||||
isRestoringHistory = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const shouldLeave = window.confirm("통화 중입니다. 현재 페이지를 떠나시겠습니까?");
|
||||
if (shouldLeave) {
|
||||
allowPageExitRef.current = true;
|
||||
window.history.back();
|
||||
return;
|
||||
}
|
||||
|
||||
isRestoringHistory = true;
|
||||
window.history.forward();
|
||||
};
|
||||
|
||||
window.addEventListener("popstate", handlePopState);
|
||||
return () => window.removeEventListener("popstate", handlePopState);
|
||||
}, [shouldBlockNavigation]);
|
||||
|
||||
const projectInfoQuery = useProjectInfoQuery(prjctIdx, queriesEnabled);
|
||||
const listHeaderQuery = useListHeaderQuery(prjctIdx, queriesEnabled);
|
||||
@@ -87,10 +130,18 @@ const ListContactPageContent = () => {
|
||||
}, [sid, router]);
|
||||
|
||||
const handleNavigateToSid = (nextSid: string) => {
|
||||
if(shouldBlockNavigation){
|
||||
alert("통화 중에는 이동할 수 없습니다.");
|
||||
return;
|
||||
}
|
||||
router.push(`/list/contact?sid=${encodeURIComponent(nextSid)}`);
|
||||
};
|
||||
|
||||
const handleGoToListManage = () => {
|
||||
if(shouldBlockNavigation){
|
||||
alert("통화 중에는 이동할 수 없습니다.");
|
||||
return;
|
||||
}
|
||||
router.push("/list/manage");
|
||||
};
|
||||
|
||||
@@ -119,7 +170,6 @@ const ListContactPageContent = () => {
|
||||
|
||||
if (!sid) return null;
|
||||
if (!mounted || !selectedProject) return <LoadingOverlayAdapter force />;
|
||||
if (isStaleProject) return <LoadingOverlayAdapter force />;
|
||||
|
||||
return (
|
||||
<div className="space-y-6 text-sm">
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { LoginUser } from "@kri/common";
|
||||
|
||||
interface AppHeaderProps {
|
||||
isMain: boolean;
|
||||
isContactPage: boolean;
|
||||
menuOpen: boolean;
|
||||
activeTopId: string;
|
||||
topMenus: TopMenuItem[];
|
||||
@@ -24,6 +25,7 @@ interface AppHeaderProps {
|
||||
|
||||
export function AppHeader({
|
||||
isMain,
|
||||
isContactPage,
|
||||
menuOpen,
|
||||
activeTopId,
|
||||
topMenus,
|
||||
@@ -51,12 +53,12 @@ export function AppHeader({
|
||||
</div>
|
||||
}
|
||||
homePath="/"
|
||||
menus={topMenus}
|
||||
menus={isContactPage? []:topMenus}
|
||||
activeMenuId={activeTopId}
|
||||
menuOpen={menuOpen}
|
||||
showMenuButton={!isMain}
|
||||
showMenuButton={!isMain && !isContactPage}
|
||||
onToggleMenu={onToggleMenu}
|
||||
onNavigate={(path) => onNavigate(path)}
|
||||
onNavigate={(path) => {if(!isContactPage) onNavigate(path)}}
|
||||
className="border-gray-200 bg-white"
|
||||
innerClassName="h-16 px-4"
|
||||
center={
|
||||
|
||||
@@ -108,6 +108,7 @@ export default function AppMainLayout({ children, initialFontSize }: AppMainLayo
|
||||
const userRole = auth.user?.userRole;
|
||||
|
||||
const isMain = pathname === "/";
|
||||
const isContactPage = pathname.startsWith("/list/contact");
|
||||
const isProjectMenu = !pathname.startsWith("/manage");
|
||||
const isViewProjectTitle = !isMain && isProjectMenu && !pathname.startsWith("/project/info");
|
||||
const visibleTopMenus = useMemo(() => filterTopMenusByRole(topMenus, userRole), [userRole]);
|
||||
@@ -186,14 +187,15 @@ export default function AppMainLayout({ children, initialFontSize }: AppMainLayo
|
||||
<KriMainLayout
|
||||
fullHeight={false}
|
||||
className={cn("bg-gray-50", "h-screen overflow-hidden")}
|
||||
bodyClassName={cn(!isMain && "min-h-0")}
|
||||
bodyClassName={cn(!isMain && isContactPage && "min-h-0")}
|
||||
mainClassName={cn("p-4", "min-h-0")}
|
||||
mainStyle={{ fontSize: `var(--content-font-size, ${initialFontSize}px)` }}
|
||||
sidebarOpen={!isMain && menuOpen}
|
||||
sidebarOpen={!isMain && isContactPage && menuOpen}
|
||||
onSidebarOpenChange={setMenuOpen}
|
||||
header={
|
||||
<AppHeader
|
||||
isMain={isMain}
|
||||
isContactPage={isContactPage}
|
||||
menuOpen={menuOpen}
|
||||
activeTopId={activeTop.id}
|
||||
topMenus={visibleTopMenus}
|
||||
@@ -208,7 +210,7 @@ export default function AppMainLayout({ children, initialFontSize }: AppMainLayo
|
||||
/>
|
||||
}
|
||||
sidebar={
|
||||
!isMain ? (
|
||||
!isMain && !isContactPage ? (
|
||||
<AppSidebar
|
||||
isProjectMenu={isProjectMenu}
|
||||
sideMenus={sideMenus}
|
||||
|
||||
@@ -113,18 +113,6 @@ const ListContactInfoPanel = ({
|
||||
const isDialing = ctiCallPhase === 'dialing'
|
||||
const isOnCall = ctiCallPhase === 'active'
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOnCall) return
|
||||
|
||||
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
||||
event.preventDefault()
|
||||
event.returnValue = true
|
||||
}
|
||||
|
||||
window.addEventListener('beforeunload', handleBeforeUnload)
|
||||
return () => window.removeEventListener('beforeunload', handleBeforeUnload)
|
||||
}, [isOnCall])
|
||||
|
||||
const visibleHeaders = listHeaders
|
||||
.filter((header) => isListFieldVisibleForContact(header))
|
||||
.sort((a, b) => {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import type {CtiCallPhase} from "@/lib/cti/ctiClient";
|
||||
|
||||
export const CTI_AGENT_GROUP = "KRI_CONTACT";
|
||||
|
||||
export const CTI_AGENT_STATUS = {
|
||||
READY: "1",
|
||||
BREAK: "11",
|
||||
} as const;
|
||||
export const CTI_CALL_PHASE: CtiCallPhase[] = [
|
||||
'dialing',
|
||||
'active'
|
||||
] as const;
|
||||
|
||||
// WS 서버가 보내는 CTIAgentStatus 값 중 통화 중 또는 통화 중 재로그인 대기로 간주할 값들
|
||||
export const CTI_ON_CALL_STATUSES = ["0", "2", "3"] as const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user