260727_02_ENH: 통화중 이동 최대한 막기 #12
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { Suspense, useEffect, useMemo, useState } from "react";
|
import { Suspense, useEffect, useMemo, useRef, 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";
|
||||||
@@ -18,6 +18,10 @@ import ReservationListDialog from "@/components/dialog/ReservationListDialog";
|
|||||||
import { createEmptyListFilter, type listHeader } from "@/types/list";
|
import { createEmptyListFilter, type listHeader } from "@/types/list";
|
||||||
import type { ResultCode } from "@/types/project";
|
import type { ResultCode } from "@/types/project";
|
||||||
import { isManager } from "@/utils/userRole";
|
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 ListContactPageContent = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -34,28 +38,67 @@ const ListContactPageContent = () => {
|
|||||||
const itrntPrjctCd = selectedProject?.itrntPrjctCd ?? "";
|
const itrntPrjctCd = selectedProject?.itrntPrjctCd ?? "";
|
||||||
const userId = auth?.user?.userId ?? "";
|
const userId = auth?.user?.userId ?? "";
|
||||||
const userRole = auth?.user?.userRole ?? 0;
|
const userRole = auth?.user?.userRole ?? 0;
|
||||||
|
const ctiCallPhase = useCtiCallPhase();
|
||||||
|
const shouldBlockNavigation = CTI_CALL_PHASE.includes(ctiCallPhase);
|
||||||
|
const allowPageExitRef = useRef(false);
|
||||||
|
|
||||||
// 이 페이지 진입 시의 prjctIdx를 기준으로 기록해두고, 이후 외부(프로젝트 선택기 등)에서
|
const queriesEnabled = mounted && prjctIdx > 0;
|
||||||
// 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 enabled = queriesEnabled && !!sid;
|
const enabled = queriesEnabled && !!sid;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!mounted || prjctIdx <= 0) return;
|
if (!shouldBlockNavigation) return;
|
||||||
|
|
||||||
if (baselinePrjctIdx === null) {
|
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
||||||
setBaselinePrjctIdx(prjctIdx);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baselinePrjctIdx !== prjctIdx) {
|
let isRestoringHistory = false;
|
||||||
router.replace('/list/manage');
|
|
||||||
|
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 projectInfoQuery = useProjectInfoQuery(prjctIdx, queriesEnabled);
|
||||||
const listHeaderQuery = useListHeaderQuery(prjctIdx, queriesEnabled);
|
const listHeaderQuery = useListHeaderQuery(prjctIdx, queriesEnabled);
|
||||||
@@ -87,10 +130,18 @@ const ListContactPageContent = () => {
|
|||||||
}, [sid, router]);
|
}, [sid, router]);
|
||||||
|
|
||||||
const handleNavigateToSid = (nextSid: string) => {
|
const handleNavigateToSid = (nextSid: string) => {
|
||||||
|
if(shouldBlockNavigation){
|
||||||
|
alert("통화 중에는 이동할 수 없습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
router.push(`/list/contact?sid=${encodeURIComponent(nextSid)}`);
|
router.push(`/list/contact?sid=${encodeURIComponent(nextSid)}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleGoToListManage = () => {
|
const handleGoToListManage = () => {
|
||||||
|
if(shouldBlockNavigation){
|
||||||
|
alert("통화 중에는 이동할 수 없습니다.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
router.push("/list/manage");
|
router.push("/list/manage");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,7 +170,6 @@ const ListContactPageContent = () => {
|
|||||||
|
|
||||||
if (!sid) return null;
|
if (!sid) return null;
|
||||||
if (!mounted || !selectedProject) return <LoadingOverlayAdapter force />;
|
if (!mounted || !selectedProject) return <LoadingOverlayAdapter force />;
|
||||||
if (isStaleProject) return <LoadingOverlayAdapter force />;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 text-sm">
|
<div className="space-y-6 text-sm">
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import type { LoginUser } from "@kri/common";
|
|||||||
|
|
||||||
interface AppHeaderProps {
|
interface AppHeaderProps {
|
||||||
isMain: boolean;
|
isMain: boolean;
|
||||||
|
isContactPage: boolean;
|
||||||
menuOpen: boolean;
|
menuOpen: boolean;
|
||||||
activeTopId: string;
|
activeTopId: string;
|
||||||
topMenus: TopMenuItem[];
|
topMenus: TopMenuItem[];
|
||||||
@@ -24,6 +25,7 @@ interface AppHeaderProps {
|
|||||||
|
|
||||||
export function AppHeader({
|
export function AppHeader({
|
||||||
isMain,
|
isMain,
|
||||||
|
isContactPage,
|
||||||
menuOpen,
|
menuOpen,
|
||||||
activeTopId,
|
activeTopId,
|
||||||
topMenus,
|
topMenus,
|
||||||
@@ -51,12 +53,12 @@ export function AppHeader({
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
homePath="/"
|
homePath="/"
|
||||||
menus={topMenus}
|
menus={isContactPage? []:topMenus}
|
||||||
activeMenuId={activeTopId}
|
activeMenuId={activeTopId}
|
||||||
menuOpen={menuOpen}
|
menuOpen={menuOpen}
|
||||||
showMenuButton={!isMain}
|
showMenuButton={!isMain && !isContactPage}
|
||||||
onToggleMenu={onToggleMenu}
|
onToggleMenu={onToggleMenu}
|
||||||
onNavigate={(path) => onNavigate(path)}
|
onNavigate={(path) => {if(!isContactPage) onNavigate(path)}}
|
||||||
className="border-gray-200 bg-white"
|
className="border-gray-200 bg-white"
|
||||||
innerClassName="h-16 px-4"
|
innerClassName="h-16 px-4"
|
||||||
center={
|
center={
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ export default function AppMainLayout({ children, initialFontSize }: AppMainLayo
|
|||||||
const userRole = auth.user?.userRole;
|
const userRole = auth.user?.userRole;
|
||||||
|
|
||||||
const isMain = pathname === "/";
|
const isMain = pathname === "/";
|
||||||
|
const isContactPage = pathname.startsWith("/list/contact");
|
||||||
const isProjectMenu = !pathname.startsWith("/manage");
|
const isProjectMenu = !pathname.startsWith("/manage");
|
||||||
const isViewProjectTitle = !isMain && isProjectMenu && !pathname.startsWith("/project/info");
|
const isViewProjectTitle = !isMain && isProjectMenu && !pathname.startsWith("/project/info");
|
||||||
const visibleTopMenus = useMemo(() => filterTopMenusByRole(topMenus, userRole), [userRole]);
|
const visibleTopMenus = useMemo(() => filterTopMenusByRole(topMenus, userRole), [userRole]);
|
||||||
@@ -186,14 +187,15 @@ export default function AppMainLayout({ children, initialFontSize }: AppMainLayo
|
|||||||
<KriMainLayout
|
<KriMainLayout
|
||||||
fullHeight={false}
|
fullHeight={false}
|
||||||
className={cn("bg-gray-50", "h-screen overflow-hidden")}
|
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")}
|
mainClassName={cn("p-4", "min-h-0")}
|
||||||
mainStyle={{ fontSize: `var(--content-font-size, ${initialFontSize}px)` }}
|
mainStyle={{ fontSize: `var(--content-font-size, ${initialFontSize}px)` }}
|
||||||
sidebarOpen={!isMain && menuOpen}
|
sidebarOpen={!isMain && isContactPage && menuOpen}
|
||||||
onSidebarOpenChange={setMenuOpen}
|
onSidebarOpenChange={setMenuOpen}
|
||||||
header={
|
header={
|
||||||
<AppHeader
|
<AppHeader
|
||||||
isMain={isMain}
|
isMain={isMain}
|
||||||
|
isContactPage={isContactPage}
|
||||||
menuOpen={menuOpen}
|
menuOpen={menuOpen}
|
||||||
activeTopId={activeTop.id}
|
activeTopId={activeTop.id}
|
||||||
topMenus={visibleTopMenus}
|
topMenus={visibleTopMenus}
|
||||||
@@ -208,7 +210,7 @@ export default function AppMainLayout({ children, initialFontSize }: AppMainLayo
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
sidebar={
|
sidebar={
|
||||||
!isMain ? (
|
!isMain && !isContactPage ? (
|
||||||
<AppSidebar
|
<AppSidebar
|
||||||
isProjectMenu={isProjectMenu}
|
isProjectMenu={isProjectMenu}
|
||||||
sideMenus={sideMenus}
|
sideMenus={sideMenus}
|
||||||
|
|||||||
@@ -113,18 +113,6 @@ const ListContactInfoPanel = ({
|
|||||||
const isDialing = ctiCallPhase === 'dialing'
|
const isDialing = ctiCallPhase === 'dialing'
|
||||||
const isOnCall = ctiCallPhase === 'active'
|
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
|
const visibleHeaders = listHeaders
|
||||||
.filter((header) => isListFieldVisibleForContact(header))
|
.filter((header) => isListFieldVisibleForContact(header))
|
||||||
.sort((a, b) => {
|
.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_GROUP = "KRI_CONTACT";
|
||||||
|
|
||||||
export const CTI_AGENT_STATUS = {
|
export const CTI_CALL_PHASE: CtiCallPhase[] = [
|
||||||
READY: "1",
|
'dialing',
|
||||||
BREAK: "11",
|
'active'
|
||||||
} as const;
|
] as const;
|
||||||
|
|
||||||
// WS 서버가 보내는 CTIAgentStatus 값 중 통화 중 또는 통화 중 재로그인 대기로 간주할 값들
|
// WS 서버가 보내는 CTIAgentStatus 값 중 통화 중 또는 통화 중 재로그인 대기로 간주할 값들
|
||||||
export const CTI_ON_CALL_STATUSES = ["0", "2", "3"] as const;
|
export const CTI_ON_CALL_STATUSES = ["0", "2", "3"] as const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user