From ce5a402253a29bc86a7db0fa363187ef587785ff Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Mon, 27 Jul 2026 17:13:58 +0900 Subject: [PATCH] =?UTF-8?q?260727=5F02=5FENH:=20=ED=86=B5=ED=99=94?= =?UTF-8?q?=EC=A4=91=20=EC=9D=B4=EB=8F=99=20=EC=B5=9C=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EB=A7=89=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(pages)/(main)/list/contact/page.tsx | 80 +++++++++++++++---- src/components/app-shell/AppHeader.tsx | 8 +- src/components/app-shell/AppMainLayout.tsx | 8 +- .../list-contact/ListContactInfoPanel.tsx | 12 --- src/const/ctiConst.ts | 11 ++- 5 files changed, 82 insertions(+), 37 deletions(-) diff --git a/src/app/(pages)/(main)/list/contact/page.tsx b/src/app/(pages)/(main)/list/contact/page.tsx index b0f16d1..b5b29c1 100644 --- a/src/app/(pages)/(main)/list/contact/page.tsx +++ b/src/app/(pages)/(main)/list/contact/page.tsx @@ -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(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 ; - if (isStaleProject) return ; return (
diff --git a/src/components/app-shell/AppHeader.tsx b/src/components/app-shell/AppHeader.tsx index 61d45bb..047e7f0 100644 --- a/src/components/app-shell/AppHeader.tsx +++ b/src/components/app-shell/AppHeader.tsx @@ -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({
} 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={ diff --git a/src/components/app-shell/AppMainLayout.tsx b/src/components/app-shell/AppMainLayout.tsx index d89904f..bdd9118 100644 --- a/src/components/app-shell/AppMainLayout.tsx +++ b/src/components/app-shell/AppMainLayout.tsx @@ -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 } sidebar={ - !isMain ? ( + !isMain && !isContactPage ? ( { - 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) => { diff --git a/src/const/ctiConst.ts b/src/const/ctiConst.ts index 92a3fd6..7d5abac 100644 --- a/src/const/ctiConst.ts +++ b/src/const/ctiConst.ts @@ -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; + -- 2.49.0.windows.1