-
미리보기
- {!selectedTemplate &&
선택된 템플릿이 없습니다.
}
- {selectedTemplate && (
- <>
- {chnnlTy !== ChannelType.SMS && (
-
{resolvedTitle ? `제목: ${resolvedTitle}` : '(제목 없음)'}
- )}
- {chnnlTy === ChannelType.SMS ? (
-
- {}}
- isSmsReadOnly
- smsPreviewSuffix={
- selectedTemplate.tmplatPurpose === TEMPLATE_PURPOSE.PHONE_VERIFICATION
- ? PHONE_VERIFICATION_PREVIEW_SUFFIX
- : undefined
- }
- placeholder="문자 내용을 입력해 주세요"
- className="max-w-80 mx-0"
- debounceMs={600}
- smsTitle={resolvedTitle}
- />
-
- ) : (
- <>
-
[key, escapeHtml(val)])),
- ),
- ),
- }}
- />
-
- >
- )}
- >
- )}
-
+
)
}
diff --git a/src/components/kri-editor/KriEditorSms.tsx b/src/components/kri-editor/KriEditorSms.tsx
index ad913af..048ffb9 100644
--- a/src/components/kri-editor/KriEditorSms.tsx
+++ b/src/components/kri-editor/KriEditorSms.tsx
@@ -27,6 +27,9 @@ export function KriEditorSms({
smsMaxBytes = 90,
lmsMaxBytes = 2000,
smsPreviewSuffix = '',
+ smsHasAttachment = false,
+ smsImages = [],
+ smsFrameClassName,
}: SmsEditorProps) {
const [text, setText] = React.useState(value || '')
const textareaRef = React.useRef
(null)
@@ -36,7 +39,7 @@ export function KriEditorSms({
const textareaInsert = useTextareaInsert(textareaRef)
const previewText = smsPreviewSuffix ? `${text}\n${smsPreviewSuffix}` : text
const byteSize = React.useMemo(() => calculateBytes(previewText), [previewText])
- const messageType: 'SMS' | 'LMS' = byteSize > smsMaxBytes || Boolean(smsTitle) ? 'LMS' : 'SMS'
+ const messageType: 'SMS' | 'LMS' = byteSize > smsMaxBytes || Boolean(smsTitle) || smsHasAttachment ? 'LMS' : 'SMS'
const maxBytes = messageType === 'SMS' ? smsMaxBytes : lmsMaxBytes
const commitText = React.useCallback((next: string, immediate = false) => {
@@ -82,17 +85,25 @@ export function KriEditorSms({
return (
{label ?
{label}
: null}
-
+
{byteSize}/{maxBytes}byte
- {messageType}
+ {messageType === 'LMS' ? 'LMS/MMS' : 'SMS'}
-
+
0 ? 'overflow-y-auto' : 'overflow-hidden')}>
{smsTitle ?
{smsTitle}
: null}
+ {smsImages.length > 0 ? (
+
+ {smsImages.map((image) => (
+ // eslint-disable-next-line @next/next/no-img-element -- data/Object URL 미리보기라 next/image 최적화 대상이 아님
+

+ ))}
+
+ ) : null}
@@ -619,12 +659,13 @@ const MessageTemplate = ({ pageTitle, defaultTemplate }: MessageTemplateProps) =
⚠️ <map>, <area> 가 사용된 경우 해당 영역이 반투명하게 보여집니다.
)}
-
+ >
+ )}
- >
- )}
{isSms && (
@@ -716,7 +767,7 @@ const MessageTemplate = ({ pageTitle, defaultTemplate }: MessageTemplateProps) =
setTemplateBody(html)}
placeholder="문자 내용을 입력해 주세요"
@@ -732,6 +783,8 @@ const MessageTemplate = ({ pageTitle, defaultTemplate }: MessageTemplateProps) =
: undefined
}
changeSmsType={(smsTypeString) => setSmsType(smsTypeString)}
+ smsHasAttachment={attachmentCount > 0}
+ smsImages={[...keptAttachmentImages, ...newAttachmentImages]}
/>
)}
diff --git a/src/const/messageTemplateConst.ts b/src/const/messageTemplateConst.ts
index 847c295..8825636 100644
--- a/src/const/messageTemplateConst.ts
+++ b/src/const/messageTemplateConst.ts
@@ -7,7 +7,7 @@ export const SMS_TYPE_ORDER = [
export const SMS_TYPE_LABEL = {
[MessageType.SMS]: "SMS",
- [MessageType.LMS_MMS]: "LMS",
+ [MessageType.LMS_MMS]: "LMS/MMS",
} as const satisfies Record
;
export const SMS_TYPE_OPTIONS = [
@@ -27,6 +27,12 @@ export const TEMPLATE_PURPOSE_OPTIONS = [
export const PHONE_VERIFICATION_PREVIEW_SUFFIX = "인증번호는 [######] 입니다.";
-// 이메일 템플릿 첨부파일 제한 (첨부파일은 이메일 템플릿만 지원)
-export const TEMPLATE_ATTACHMENT_MAX_COUNT = 5;
-export const TEMPLATE_ATTACHMENT_MAX_BYTES = 1_000_000;
+// 이메일 템플릿 첨부파일 제한 (파일당 이하 기준)
+export const EMAIL_TEMPLATE_ATTACHMENT_MAX_COUNT = 5;
+export const EMAIL_TEMPLATE_ATTACHMENT_MAX_BYTES = 1_000_000;
+
+// 문자 템플릿 첨부파일 제한 (JPG만 허용, 파일당 이하 기준, 첨부 시 LMS/MMS로 저장됨)
+export const SMS_TEMPLATE_ATTACHMENT_MAX_COUNT = 3;
+export const SMS_TEMPLATE_ATTACHMENT_MAX_BYTES = 61_440;
+export const SMS_TEMPLATE_ATTACHMENT_EXTENSION = ".jpg";
+export const SMS_TEMPLATE_ATTACHMENT_MIME_TYPE = "image/jpeg";
diff --git a/src/hooks/useCtiConnection.ts b/src/hooks/useCtiConnection.ts
index 7002f97..73be72e 100644
--- a/src/hooks/useCtiConnection.ts
+++ b/src/hooks/useCtiConnection.ts
@@ -39,4 +39,22 @@ export function useCtiConnection() {
agentName,
});
}, [hasUser, clientId, internalNo, externalNo, agentName]);
+
+ // 뒤로/앞으로 가기로 bfcache에 들어갔다가 돌아오면 React 상태가 그대로 복원되어 위 effect가 다시 실행되지 않는다.
+ // 떠날 때 CTI 서버에 Logout, 돌아올 때 다시 Login 하여 새로고침 없이 전화걸기를 쓸 수 있게 한다.
+ useEffect(() => {
+ const handlePageHide = (event: PageTransitionEvent) => {
+ if (event.persisted) ctiClient.suspendForPageHide();
+ };
+ const handlePageShow = (event: PageTransitionEvent) => {
+ if (event.persisted) ctiClient.resumeFromPageShow();
+ };
+
+ window.addEventListener("pagehide", handlePageHide);
+ window.addEventListener("pageshow", handlePageShow);
+ return () => {
+ window.removeEventListener("pagehide", handlePageHide);
+ window.removeEventListener("pageshow", handlePageShow);
+ };
+ }, []);
}
diff --git a/src/lib/cti/ctiClient.ts b/src/lib/cti/ctiClient.ts
index 6737d20..085eb3a 100644
--- a/src/lib/cti/ctiClient.ts
+++ b/src/lib/cti/ctiClient.ts
@@ -688,9 +688,36 @@ const connectAndLogin = (params: CtiLoginParams) => {
openSocketAndLogin(params);
};
+// bfcache 진입 직전(pagehide, persisted): 열려 있는 소켓으로 Logout을 보내고 소켓만 정리한다.
+// 로그인 정보는 복귀(pageshow) 시 다시 로그인하기 위해 유지한다.
+// 통화 중이면 통화 처리가 꼬이지 않도록 Logout은 생략한다.
+const suspendForPageHide = () => {
+ if (!currentLoginParams) return;
+ stopReconnectLoop();
+ if (currentAgentLoginId && connectionState === "open") {
+ if (isCallInProgress()) {
+ console.log("[CTI][TEMP_LOG] pagehide logout skipped, call is in progress"); // TEMP_CTI_LOG
+ } else {
+ send({ ZCommand: "Logout", AgentLoginID: currentAgentLoginId });
+ }
+ }
+ teardownSocket();
+};
+
+// bfcache 복귀(pageshow, persisted): 유지해 둔 로그인 정보로 다시 연결해 로그인한다.
+const resumeFromPageShow = () => {
+ const params = currentLoginParams;
+ if (!params) return;
+ if (connectionState === "open" || connectionState === "connecting") return;
+ console.log("[CTI][TEMP_LOG] pageshow resume, reconnecting"); // TEMP_CTI_LOG
+ connectAndLogin(params);
+};
+
export const ctiClient = {
connectAndLogin,
logout,
+ suspendForPageHide,
+ resumeFromPageShow,
subscribe: (listener: () => void) => {
listeners.add(listener);
return () => listeners.delete(listener);
diff --git a/src/query/key/keys.ts b/src/query/key/keys.ts
index 5dd854c..dffa4ec 100644
--- a/src/query/key/keys.ts
+++ b/src/query/key/keys.ts
@@ -74,6 +74,9 @@ export const qk = {
templateList: (chnnlTy: ChannelType, itrntPrjctCd: string) =>
["message-template", "list", chnnlTy, itrntPrjctCd] as const,
template: (tmplatIdx: number) => ["message-template", "detail", tmplatIdx] as const,
+ templateAttachments: (tmplatIdx: number) => ["message-template", "attachment", tmplatIdx] as const,
+ templateAttachment: (tmplatIdx: number, fileName: string) =>
+ ["message-template", "attachment", tmplatIdx, fileName] as const,
bulkSendList: (sendTy: number, reqstSvc: string, prjctCd: string) =>
["message-report", "bulk-list", sendTy, reqstSvc, prjctCd] as const,
diff --git a/src/query/message.ts b/src/query/message.ts
index 34cfa2c..28f732c 100644
--- a/src/query/message.ts
+++ b/src/query/message.ts
@@ -1,6 +1,6 @@
"use client";
-import { keepPreviousData, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
+import { keepPreviousData, useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
import { nextApi } from "@/lib/http-client";
import { qk } from "@/query/key/keys";
import type {
@@ -19,7 +19,7 @@ import type {
SendResultInfo,
SendSingleResponse,
} from "@/types/message";
-import type { TemplateSummaryWithPurpose, TemplateWithPurpose } from "@/types/message";
+import type { TemplateAttachmentImage, TemplateSummaryWithPurpose, TemplateWithPurpose } from "@/types/message";
export function useTemplateListQuery(chnnlTy: ChannelType, itrntPrjctCd: string, enabled: boolean) {
return useQuery({
@@ -79,6 +79,8 @@ export function useSaveTemplateMutation(chnnlTy: ChannelType, itrntPrjctCd: stri
onSuccess: (res) => {
if (res.tmplatIdx) {
qc.setQueryData(qk.template(res.tmplatIdx), res);
+ // 같은 파일명으로 교체될 수 있으므로 첨부 이미지 미리보기 캐시를 비운다.
+ qc.removeQueries({ queryKey: qk.templateAttachments(res.tmplatIdx) });
}
qc.invalidateQueries({ queryKey: qk.templateList(chnnlTy, itrntPrjctCd) });
},
@@ -97,6 +99,38 @@ export function useDownloadTemplateAttachmentMutation(tmplatIdx: number) {
});
}
+const readBlobAsDataUrl = (blob: Blob) =>
+ new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onload = () => resolve(reader.result as string);
+ reader.onerror = () => reject(reader.error);
+ reader.readAsDataURL(blob);
+ });
+
+/**
+ * 문자 템플릿 첨부 JPG 미리보기 (파일별 캐시, 불러온 이미지만 fileNames 순서대로 반환)
+ * data URL로 캐시하므로 Object URL 해제가 필요 없다.
+ */
+export function useTemplateAttachmentImagesQuery(tmplatIdx: number, fileNames: string[], enabled: boolean) {
+ return useQueries({
+ queries: fileNames.map((fileName) => ({
+ queryKey: qk.templateAttachment(tmplatIdx, fileName),
+ queryFn: async () => {
+ const buffer = await nextApi.get(
+ `/message-template/${tmplatIdx}/attachment?fileName=${encodeURIComponent(fileName)}`,
+ { expectBinary: true },
+ );
+ return readBlobAsDataUrl(new Blob([buffer], { type: "image/jpeg" }));
+ },
+ enabled: enabled && tmplatIdx > 0,
+ staleTime: 60_000,
+ retry: 1,
+ })),
+ combine: (results): TemplateAttachmentImage[] =>
+ results.flatMap((result, i) => (result.data ? [{ fileName: fileNames[i], src: result.data }] : [])),
+ });
+}
+
export function useUpdateMainTemplateMutation(prjctIdx: number, chnnlTy: ChannelType) {
const qc = useQueryClient();
const key = qk.mainTemplate(prjctIdx, chnnlTy);
diff --git a/src/types/message.ts b/src/types/message.ts
index 504e3d0..ddcf8ca 100644
--- a/src/types/message.ts
+++ b/src/types/message.ts
@@ -1,4 +1,4 @@
-import type { Template, TemplateEmail, TemplateSummary } from '@kri/common/noti-hub';
+import type { Template, TemplateEmail, TemplateSms, TemplateSummary } from '@kri/common/noti-hub';
import type { ListFilter } from './list';
export type TemplatePurpose = 0 | 1;
@@ -22,6 +22,21 @@ export type TemplateEmailWithAttachments = TemplateEmail & {
atchFl?: string;
};
+/**
+ * 문자 템플릿 JPG 첨부파일명 목록 (TemplateEmailWithAttachments와 동일하게 조회 응답 전용).
+ * 첨부가 하나라도 있으면 서버가 LMS_MMS로 저장한다.
+ */
+export type TemplateSmsWithAttachments = TemplateSms & {
+ tmplatPurpose: TemplatePurpose;
+ atchFl?: string;
+};
+
+/** 문자 미리보기에 표시할 첨부 이미지 (src는 data URL 또는 Object URL) */
+export type TemplateAttachmentImage = {
+ fileName: string;
+ src: string;
+};
+
export type PhoneVerificationSendData = {
verificationId: string;
expireDt: string;