diff --git a/src/components/assign/AssignTargetList.tsx b/src/components/assign/AssignTargetList.tsx index 160f6d8..e02aee3 100644 --- a/src/components/assign/AssignTargetList.tsx +++ b/src/components/assign/AssignTargetList.tsx @@ -124,6 +124,12 @@ export function AssignTargetList({ return (
+ {summary ? ( +
+ 전체 {summary.totalCount}건 · 미배정 {summary.unassignedCount}건 +
+ ) : null} + {canFilterByCmpn ? (
) : null} - {summary ? ( -
- 전체 {summary.totalCount}건 · 미배정 {summary.unassignedCount}건 -
- ) : null} -
diff --git a/src/lib/cti/ctiClient.ts b/src/lib/cti/ctiClient.ts index a71321b..6737d20 100644 --- a/src/lib/cti/ctiClient.ts +++ b/src/lib/cti/ctiClient.ts @@ -1,5 +1,6 @@ import { clientEnv } from "@/lib/env.client"; import { nextApi } from "@/lib/http-client"; +import { HttpError } from "@kri/common/http"; import { CTI_AGENT_GROUP, CTI_ON_CALL_STATUSES } from "@/const/ctiConst"; import type { ListCallCloseRequest, @@ -250,6 +251,9 @@ const restoreCtiState = (agentLoginId: string) => { return true; }; +const fetchCallHistBySession = (agentSessionId: string) => + nextApi.get(`/list-call-hist/session/${encodeURIComponent(agentSessionId)}`); + const recoverLastCallHistId = async (agentLoginId: string) => { const targetCall = activeCall?.agentSessionId ? activeCall : @@ -259,11 +263,40 @@ const recoverLastCallHistId = async (agentLoginId: string) => { const agentSessionId = targetCall.agentSessionId; const callContext = targetCall.context; + let result: ListCallHist; try { - const result = await nextApi.get( - `/list-call-hist/session/${encodeURIComponent(agentSessionId)}`, - ); + result = await fetchCallHistBySession(agentSessionId); + } catch (firstError) { + // call-start 저장(PUT)이 아직 커밋되기 전에 재연결 복구용 조회가 먼저 도착하는 레이스가 있을 수 있어, + // 바로 포기하지 않고 짧게 대기 후 한 번 더 시도한다. + await new Promise((resolve) => setTimeout(resolve, 1000)); + try { + result = await fetchCallHistBySession(agentSessionId); + } catch (secondError) { + console.warn("[CTI][TEMP_LOG] failed to recover call history after retry", { + agentSessionId, + firstError, + secondError, + }); // TEMP_CTI_LOG + // 재시도까지 404(진짜로 존재하지 않는 세션)로 확인된 경우에만 phantom 상태를 정리한다. + // 다른 오류(네트워크 문제 등)는 통화가 실제로 살아있을 수 있으니 그대로 둔다. + const isConfirmedNotFound = secondError instanceof HttpError && secondError.status === 404; + if (isConfirmedNotFound && currentAgentLoginId === agentLoginId) { + if (closingCall?.agentSessionId === agentSessionId) { + closingCall = null; + } else if (activeCall?.agentSessionId === agentSessionId) { + activeCall = null; + agentStatus = null; + } + persistCtiState(); + notify(); + } + return; + } + } + + try { const isSameCall = currentAgentLoginId === agentLoginId && (activeCall?.agentSessionId === agentSessionId || @@ -484,11 +517,21 @@ const handleIncomingMessage = (raw: unknown) => { const eventAgentSessionId = String(parsed.AgntSessionID ?? ""); const isClosingCall = eventAgentSessionId !== "" && eventAgentSessionId === closingCall?.agentSessionId; + // saveCallHistory가 activeCall/closingCall에서 컨텍스트를 동기적으로 먼저 읽어가므로, + // 아래에서 activeCall을 비우기 전에 반드시 먼저 호출해야 한다(순서 변경 금지). + saveCallHistory(parsed, "close"); if (!isClosingCall) { callClosedReceived = true; setAgentStatus(null); + // CallClosed는 통화가 끝났다는 CTI 서버의 확정 신호이므로, 이력 저장(백엔드 API) 성공 여부와 + // 무관하게 로컬 상태는 즉시 비운다. 저장이 실패해도 이 처리를 기다리다 UI가 "통화 중"에 + // 멈춰있으면 안 된다. 세션ID가 일치할 때만 비워서, 그 사이 새 통화가 시작된 경우를 보호한다. + if (eventAgentSessionId !== "" && activeCall?.agentSessionId === eventAgentSessionId) { + activeCall = null; + persistCtiState(); + notify(); + } } - saveCallHistory(parsed, "close"); break; } default: