develop #15

Merged
gitadmin merged 4 commits from develop into master 2026-07-28 15:16:16 +09:00
18 changed files with 151 additions and 54 deletions
Showing only changes of commit d9f53c0c3d - Show all commits

View File

@@ -33,11 +33,14 @@ const toRequiredNumber = (value: string): number | null => {
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
};
const toRequiredSid = (value: string): string | null =>
value.length > 0 ? value : null;
const buildExternalEventBody = (
req: NextRequest,
action: ExternalAction,
prjctSurveyIdx: number,
sid: number,
sid: string,
): ExternalEventBody => {
const pathname = req.nextUrl.pathname;
const h = req.headers;
@@ -51,7 +54,7 @@ const buildExternalEventBody = (
entryType: getEntryTypeCode(h),
action: actionCode,
psidx: String(prjctSurveyIdx),
sid: String(sid),
sid,
remoteAddr: getHeader(h, "x-orig-ip") || getClientIp(req),
uri: getHeader(h, "x-orig-uri") || pathname,
url: getHeader(h, "x-orig-url") || req.url,
@@ -75,7 +78,7 @@ const handleExternalEvent = async (req: NextRequest, context: RouteContext) => {
}
const prjctSurveyIdx = toRequiredNumber((searchParams.get("psidx") ?? "").trim());
const sid = toRequiredNumber((searchParams.get("sid") ?? "").trim());
const sid = toRequiredSid((searchParams.get("sid") ?? "").trim());
if (!prjctSurveyIdx || !sid) {
return NextResponse.json({ message: "psidx, sid는 필수입니다." }, { status: 400 });

View File

@@ -37,7 +37,7 @@ export const PUT = async (req: NextRequest, context: RouteContext) => {
const contactApi = await createContactApi();
const result = await contactApi.put<ListCallHist>(
`/list-call-hist/${prjctIdx}/${sid}/${action}`,
`/list-call-hist/${prjctIdx}/${encodeURIComponent(sid)}/${action}`,
body,
);
return NextResponse.json(result, { status: 200 });

View File

@@ -11,12 +11,16 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
const contactApi = await createContactApi();
if (action === "event" && slug.length === 3) {
const result = await contactApi.get<ListEventHistory[]>(`/list-hist/event/${slug[1]}/${slug[2]}`);
const result = await contactApi.get<ListEventHistory[]>(
`/list-hist/event/${slug[1]}/${encodeURIComponent(slug[2])}`,
);
return NextResponse.json(result, { status: 200 });
}
if (action === "update" && slug.length === 3) {
const result = await contactApi.get<ListUpdateHistory[]>(`/list-hist/update/${slug[1]}/${slug[2]}`);
const result = await contactApi.get<ListUpdateHistory[]>(
`/list-hist/update/${slug[1]}/${encodeURIComponent(slug[2])}`,
);
return NextResponse.json(result, { status: 200 });
}

View File

@@ -28,13 +28,15 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
}
if (action === "search-sid" && slug.length === 3) {
const result = await contactApi.get<ListSearchWithFullResult>(`/list/search-sid/${slug[1]}/${slug[2]}`);
const result = await contactApi.get<ListSearchWithFullResult>(
`/list/search-sid/${slug[1]}/${encodeURIComponent(slug[2])}`,
);
return NextResponse.json(result, { status: 200 });
}
if (action === "item-file-download" && slug.length === 4) {
const result = await contactApi.get<ArrayBuffer>(
`/list/item-file/download/${slug[1]}/${slug[2]}/${slug[3]}`,
`/list/item-file/download/${slug[1]}/${encodeURIComponent(slug[2])}/${slug[3]}`,
{ expectBinary: true },
);
return new NextResponse(result, {
@@ -94,7 +96,7 @@ export const POST = async (req: NextRequest, context: RouteContext) => {
if (action === "item-file-upload" && slug.length === 3) {
const form = await req.formData();
await contactApi.postForm(`/list/item-file/upload/${slug[1]}/${slug[2]}`, form);
await contactApi.postForm(`/list/item-file/upload/${slug[1]}/${encodeURIComponent(slug[2])}`, form);
return new NextResponse(null, { status: 204 });
}

View File

@@ -24,7 +24,7 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
const channelTy = req.nextUrl.searchParams.get("channelTy");
const query = channelTy ? `?channelTy=${channelTy}` : "";
const result = await notihubApi.get<SendResultInfo[]>(
`/report/send-result/${sid}/${prjctCdParam}/${reqstSvcParam}${query}`,
`/report/send-result/${encodeURIComponent(sid)}/${prjctCdParam}/${reqstSvcParam}${query}`,
);
return NextResponse.json(result, {status: 200});
}

View File

@@ -11,7 +11,9 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
const contactApi = await createContactApi();
if (action === "sid" && slug.length === 3) {
const result = await contactApi.get<ListReserve[]>(`/reserve/${slug[1]}/sid/${slug[2]}`);
const result = await contactApi.get<ListReserve[]>(
`/reserve/${slug[1]}/sid/${encodeURIComponent(slug[2])}`,
);
return NextResponse.json(result, { status: 200 });
}

View File

@@ -15,7 +15,7 @@ export function usePagination({ currentPage, totalPages, paginationItemsToDispla
const visibleCount = Math.max(1, paginationItemsToDisplay)
const half = Math.floor(visibleCount / 2)
let startPage = Math.max(1, currentPage - half)
let endPage = Math.min(totalPages, startPage + visibleCount - 1)
const endPage = Math.min(totalPages, startPage + visibleCount - 1)
if (endPage - startPage + 1 < visibleCount) {
startPage = Math.max(1, endPage - visibleCount + 1)

View File

@@ -15,7 +15,7 @@ export type ReservationListDialogProps = {
}
// 오늘과 가장 가까운(과거/미래 무관) 예약의 sid를 찾는다.
export const findClosestReservationSid = (reservations: ListReserve[], now: Date = new Date()): number | null => {
export const findClosestReservationSid = (reservations: ListReserve[], now: Date = new Date()): string | null => {
if (reservations.length === 0) return null
return reservations.reduce((closest, current) => {
@@ -45,8 +45,8 @@ const ReservationListDialog = ({
hideDialog(dialogId)
}
const handleSelect = (sid: number) => {
onSelectReservation(String(sid))
const handleSelect = (sid: string) => {
onSelectReservation(sid)
handleOpenChange(false)
}

View File

@@ -123,7 +123,7 @@ const SingleMessageSendDialog = ({
tmplatIdx: templateIdx,
resve: scheduleType === 'reserve',
sendDt: scheduleType === 'reserve' ? new Date(reserveAt).toISOString() : undefined,
sid: Number(sid),
sid,
destHeaderIds: [destHeaderId],
})

View File

@@ -124,7 +124,7 @@ const ContactEventSection = ({
const isContactType = resultCodeType === ResultCodeType.CONTACT
const historyQuery = useListEventHistoryQuery(prjctIdx, sid, true)
const ctiLastCallHistId = useCtiLastCallHistId(prjctIdx, Number(sid))
const ctiLastCallHistId = useCtiLastCallHistId(prjctIdx, sid)
const listCallHistIdx = isContactType ? ctiLastCallHistId : null
const handleResultCdChange = (next: string) => {
@@ -309,7 +309,7 @@ const ListContactEventPanel = ({
await addListEventMutation.mutateAsync({
prjctIdx,
sid: Number(sid),
sid,
resultCodeType,
resultCd,
listCallHistIdx,
@@ -321,7 +321,7 @@ const ListContactEventPanel = ({
})
if (resveDt) {
await reserveMutation.mutateAsync({ prjctIdx, sid: Number(sid), userId, resveDt })
await reserveMutation.mutateAsync({ prjctIdx, sid, userId, resveDt })
}
alert('등록되었습니다.')

View File

@@ -156,7 +156,7 @@ const ListContactInfoPanel = ({
}
if (!telNum) return
ctiClient.makeCall({ dialNumber: telNum, prjctIdx, sid: Number(sid), listHderId, aniNumber: callerTelNum ?? '' })
ctiClient.makeCall({ dialNumber: telNum, prjctIdx, sid, listHderId, aniNumber: callerTelNum ?? '' })
}
const handlePickFile = (listHderId: number) => {

View File

@@ -3,7 +3,7 @@
import { useCallback, useSyncExternalStore } from "react";
import { ctiClient } from "@/lib/cti/ctiClient";
export function useCtiLastCallHistId(prjctIdx: number, sid: number) {
export function useCtiLastCallHistId(prjctIdx: number, sid: string) {
const getSnapshot = useCallback(
() => ctiClient.getLastCallHistIdFor(prjctIdx, sid),
[prjctIdx, sid],

View File

@@ -22,7 +22,7 @@ type CtiLoginParams = {
type CtiMakeCallParams = {
dialNumber: string;
prjctIdx: number;
sid: number;
sid: string;
listHderId: number;
aniNumber: string;
};
@@ -32,7 +32,7 @@ export type CtiCallPhase = "idle" | "dialing" | "active";
type CtiCallContext = {
prjctIdx: number;
sid: number;
sid: string;
listHderId: number;
};
@@ -42,7 +42,7 @@ type CtiCall = {
};
type PersistedCtiState = {
version: 2;
version: 3;
agentLoginId: string;
agentStatus: string | null;
activeCall: CtiCall | null;
@@ -54,7 +54,25 @@ type PersistedCtiState = {
updatedAt: number;
};
const CTI_STATE_VERSION = 2;
type LegacyCtiCallContext = Omit<CtiCallContext, "sid"> & {
sid: number;
};
type LegacyCtiCall = Omit<CtiCall, "context"> & {
context: LegacyCtiCallContext;
};
type LegacyPersistedCtiState = Omit<
PersistedCtiState,
"version" | "activeCall" | "closingCall" | "lastCallContext"
> & {
version: 2;
activeCall: LegacyCtiCall | null;
closingCall: LegacyCtiCall | null;
lastCallContext: LegacyCtiCallContext | null;
};
const CTI_STATE_VERSION = 3;
const CTI_STATE_TTL_MS = 24 * 60 * 60 * 1000;
let socket: WebSocket | null = null;
@@ -92,6 +110,19 @@ const isCallInProgress = () =>
const isCallContext = (value: unknown): value is CtiCallContext => {
if (typeof value !== "object" || value === null) return false;
const context = value as Partial<CtiCallContext>;
return (
typeof context.prjctIdx === "number" &&
Number.isFinite(context.prjctIdx) &&
typeof context.sid === "string" &&
context.sid.length > 0 &&
typeof context.listHderId === "number" &&
Number.isFinite(context.listHderId)
);
};
const isLegacyCallContext = (value: unknown): value is LegacyCtiCallContext => {
if (typeof value !== "object" || value === null) return false;
const context = value as Partial<LegacyCtiCallContext>;
return (
typeof context.prjctIdx === "number" &&
Number.isFinite(context.prjctIdx) &&
@@ -111,6 +142,15 @@ const isCtiCall = (value: unknown): value is CtiCall => {
);
};
const isLegacyCtiCall = (value: unknown): value is LegacyCtiCall => {
if (typeof value !== "object" || value === null) return false;
const call = value as Partial<LegacyCtiCall>;
return (
isLegacyCallContext(call.context) &&
(call.agentSessionId === null || typeof call.agentSessionId === "string")
);
};
const isPersistedCtiState = (value: unknown): value is PersistedCtiState => {
if (typeof value !== "object" || value === null) return false;
const state = value as Partial<PersistedCtiState>;
@@ -128,6 +168,48 @@ const isPersistedCtiState = (value: unknown): value is PersistedCtiState => {
);
};
const isLegacyPersistedCtiState = (value: unknown): value is LegacyPersistedCtiState => {
if (typeof value !== "object" || value === null) return false;
const state = value as Partial<LegacyPersistedCtiState>;
return (
state.version === 2 &&
typeof state.agentLoginId === "string" &&
(state.agentStatus === null || typeof state.agentStatus === "string") &&
(state.activeCall === null || isLegacyCtiCall(state.activeCall)) &&
(state.closingCall === null || isLegacyCtiCall(state.closingCall)) &&
(state.lastCallContext === null || isLegacyCallContext(state.lastCallContext)) &&
(state.lastCallHistId === null || typeof state.lastCallHistId === "number") &&
typeof state.hangupRequested === "boolean" &&
typeof state.callClosedReceived === "boolean" &&
typeof state.updatedAt === "number"
);
};
const migrateLegacyCallContext = (context: LegacyCtiCallContext): CtiCallContext => ({
...context,
sid: String(context.sid),
});
const migrateLegacyCall = (call: LegacyCtiCall | null): CtiCall | null =>
call
? {
...call,
context: migrateLegacyCallContext(call.context),
}
: null;
const toPersistedCtiState = (value: unknown): PersistedCtiState | null => {
if (isPersistedCtiState(value)) return value;
if (!isLegacyPersistedCtiState(value)) return null;
return {
...value,
version: CTI_STATE_VERSION,
activeCall: migrateLegacyCall(value.activeCall),
closingCall: migrateLegacyCall(value.closingCall),
lastCallContext: value.lastCallContext ? migrateLegacyCallContext(value.lastCallContext) : null,
};
};
const persistCtiState = () => {
if (!currentAgentLoginId) return;
setLocalStorage(StorageKeys.CtiState, {
@@ -146,22 +228,24 @@ const persistCtiState = () => {
const restoreCtiState = (agentLoginId: string) => {
const stored = getLocalStorage(StorageKeys.CtiState);
const persistedState = toPersistedCtiState(stored);
if (
!isPersistedCtiState(stored) ||
stored.agentLoginId !== agentLoginId ||
Date.now() - stored.updatedAt > CTI_STATE_TTL_MS
!persistedState ||
persistedState.agentLoginId !== agentLoginId ||
Date.now() - persistedState.updatedAt > CTI_STATE_TTL_MS
) {
if (stored !== null) removeLocalStorage(StorageKeys.CtiState);
return false;
}
agentStatus = stored.agentStatus;
activeCall = stored.activeCall;
closingCall = stored.closingCall;
lastCallContext = stored.lastCallContext;
lastCallHistId = stored.lastCallHistId;
hangupRequested = stored.hangupRequested;
callClosedReceived = stored.callClosedReceived;
agentStatus = persistedState.agentStatus;
activeCall = persistedState.activeCall;
closingCall = persistedState.closingCall;
lastCallContext = persistedState.lastCallContext;
lastCallHistId = persistedState.lastCallHistId;
hangupRequested = persistedState.hangupRequested;
callClosedReceived = persistedState.callClosedReceived;
if (persistedState !== stored) persistCtiState();
notify();
return true;
};
@@ -324,7 +408,7 @@ const saveCallHistory = (parsed: Record<string, unknown>, phase: "start" | "clos
const action = phase === "start" ? "call-start" : "call-close";
console.log(`[CTI][TEMP_LOG] saving ${action}`, { prjctIdx, sid, body }); // TEMP_CTI_LOG
nextApi
.put<ListCallHist>(`/list-call-hist/${prjctIdx}/${sid}/${action}`, body)
.put<ListCallHist>(`/list-call-hist/${prjctIdx}/${encodeURIComponent(sid)}/${action}`, body)
.then((result) => {
console.log(`[CTI][TEMP_LOG] ${action} saved, listCallHistIdx =`, result?.listCallHistIdx); // TEMP_CTI_LOG
lastCallContext = callContext;
@@ -570,7 +654,7 @@ export const ctiClient = {
},
getConnectionState: () => connectionState,
getCallPhase,
getLastCallHistIdFor: (prjctIdx: number, sid: number) =>
getLastCallHistIdFor: (prjctIdx: number, sid: string) =>
lastCallContext?.prjctIdx === prjctIdx && lastCallContext.sid === sid ? lastCallHistId : null,
makeCall: (params: CtiMakeCallParams) => {
if (!currentAgentLoginId) return;

View File

@@ -79,7 +79,7 @@ export function useListSearchQuery(prjctIdx: number, request: ListSearchRequest,
export function useListDetailQuery(prjctIdx: number, sid: string, enabled: boolean) {
return useQuery({
queryKey: qk.listDetail(prjctIdx, sid),
queryFn: () => nextApi.get<ListSearchWithFullResult>(`/list/search-sid/${prjctIdx}/${sid}`),
queryFn: () => nextApi.get<ListSearchWithFullResult>(`/list/search-sid/${prjctIdx}/${encodeURIComponent(sid)}`),
enabled,
staleTime: 0,
refetchOnMount: "always",
@@ -92,7 +92,7 @@ export function useListDetailQuery(prjctIdx: number, sid: string, enabled: boole
export function useListEventHistoryQuery(prjctIdx: number, sid: string, enabled: boolean) {
return useQuery({
queryKey: qk.listEventHistory(prjctIdx, sid),
queryFn: () => nextApi.get<ListEventHistory[]>(`/list-hist/event/${prjctIdx}/${sid}`),
queryFn: () => nextApi.get<ListEventHistory[]>(`/list-hist/event/${prjctIdx}/${encodeURIComponent(sid)}`),
enabled,
staleTime: 0,
refetchOnMount: "always",
@@ -103,7 +103,7 @@ export function useListEventHistoryQuery(prjctIdx: number, sid: string, enabled:
export function useListUpdateHistoryQuery(prjctIdx: number, sid: string, enabled: boolean) {
return useQuery({
queryKey: qk.listUpdateHistory(prjctIdx, sid),
queryFn: () => nextApi.get<ListUpdateHistory[]>(`/list-hist/update/${prjctIdx}/${sid}`),
queryFn: () => nextApi.get<ListUpdateHistory[]>(`/list-hist/update/${prjctIdx}/${encodeURIComponent(sid)}`),
enabled,
staleTime: 0,
refetchOnMount: "always",
@@ -114,7 +114,7 @@ export function useListUpdateHistoryQuery(prjctIdx: number, sid: string, enabled
export function useListReserveBySidQuery(prjctIdx: number, sid: string, enabled: boolean) {
return useQuery({
queryKey: qk.listReserveBySid(prjctIdx, sid),
queryFn: () => nextApi.get<ListReserve[]>(`/reserve/sid/${prjctIdx}/${sid}`),
queryFn: () => nextApi.get<ListReserve[]>(`/reserve/sid/${prjctIdx}/${encodeURIComponent(sid)}`),
enabled,
staleTime: 0,
refetchOnMount: "always",
@@ -154,7 +154,7 @@ export function useUploadListItemFileMutation(prjctIdx: number, sid: string) {
mutationFn: ({ listHderId, file }: { listHderId: number; file: File }) => {
const formData = new FormData();
formData.append(String(listHderId), file);
return nextApi.postForm<void>(`/list/item-file-upload/${prjctIdx}/${sid}`, formData);
return nextApi.postForm<void>(`/list/item-file-upload/${prjctIdx}/${encodeURIComponent(sid)}`, formData);
},
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: qk.listDetail(prjctIdx, sid) });
@@ -165,7 +165,7 @@ export function useUploadListItemFileMutation(prjctIdx: number, sid: string) {
export function useDownloadListItemFileByHeaderMutation(prjctIdx: number, sid: string) {
return useMutation({
mutationFn: (listHderId: number) =>
nextApi.get<ArrayBuffer>(`/list/item-file-download/${prjctIdx}/${sid}/${listHderId}`, {
nextApi.get<ArrayBuffer>(`/list/item-file-download/${prjctIdx}/${encodeURIComponent(sid)}/${listHderId}`, {
expectBinary: true,
}),
});

View File

@@ -194,7 +194,9 @@ export function useSendResultBySidQuery(
queryKey: qk.sendResultBySid(sid, prjctCd, reqstSvc, channelTy),
queryFn: () => {
const query = channelTy !== undefined ? `?channelTy=${channelTy}` : "";
return nextApi.get<SendResultInfo[]>(`/message-report/send-result/${sid}/${prjctCd}/${reqstSvc}${query}`);
return nextApi.get<SendResultInfo[]>(
`/message-report/send-result/${encodeURIComponent(sid)}/${prjctCd}/${reqstSvc}${query}`,
);
},
enabled: enabled && !!sid && !!prjctCd && !!reqstSvc,
staleTime: 0,

View File

@@ -35,6 +35,6 @@ export type ExternalEventMeta = {
export type ExternalEventBody = {
action: ExternalActionCode;
prjctSurveyIdx: number;
sid: number;
sid: string;
meta: ExternalEventMeta;
};

View File

@@ -216,7 +216,7 @@ export type ListEventInsertMeta = {
export type ListEventInsertRequest = {
prjctIdx: number;
sid: number;
sid: string;
resultCodeType: ResultCodeType;
resultCd: number;
listCallHistIdx?: number | null;
@@ -228,7 +228,7 @@ export type ListEventHistory = {
listEventHistIdx: number;
eventTy: ResultCodeType;
prjctIdx: number;
sid: number;
sid: string;
resultCd: number;
metaData?: string;
listCallHistIdx?: number;
@@ -240,7 +240,7 @@ export type ListEventHistory = {
export type ListUpdateHistory = {
listUpdateHistIdx: number;
prjctIdx: number;
sid: number;
sid: string;
listHderId: number;
beforeVal?: string;
afterVal?: string;
@@ -251,7 +251,7 @@ export type ListUpdateHistory = {
export type ListReserve = {
listResveIdx: number;
prjctIdx: number;
sid: number;
sid: string;
memo?: string;
cnfirm: boolean;
resveDt: string;
@@ -282,7 +282,7 @@ export type ListCallCloseRequest = ListCallStartRequest & {
export type ListCallHist = ListCallCloseRequest & {
listCallHistIdx: number;
prjctIdx: number;
sid: number;
sid: string;
callStatus: 2 | 4 | 9;
endDt?: string;
regUser: string;
@@ -293,7 +293,7 @@ export type ListCallHistSession = ListCallHist;
export type ListReserveRequest = {
prjctIdx: number;
sid: number;
sid: string;
userId: string;
resveDt: string;
};
@@ -349,7 +349,7 @@ export type SurveyResult = {
export type ListSearchBase = {
prjctIdx: number;
sid: number;
sid: string;
use: ListIsUse;
assignList: Record<ListHeaderAssignType, string>;
memo: string;

View File

@@ -6,7 +6,7 @@ export type MessageSendSingleRequest = {
tmplatIdx: number;
resve: boolean;
sendDt?: string;
sid: number;
sid: string;
destHeaderIds: number[];
destNameHeaderId?: number;
};
@@ -21,7 +21,7 @@ export type MessageSendBulkRequest = {
};
export type MessageFailedChunk = {
sidList?: number[];
sidList?: string[];
reason?: string;
};