From 825cf5f35f7eb0616bbfe5093e952f8bb1b05da6 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Thu, 1 Oct 2026 16:35:55 +0900 Subject: [PATCH] =?UTF-8?q?261001=5F02=5FENH:=20=EB=B0=9C=EC=86=A1=20?= =?UTF-8?q?=EB=8B=A4=EC=9D=B4=EC=96=BC=EB=A1=9C=EA=B7=B8=20=EB=AF=B8?= =?UTF-8?q?=EB=A6=AC=EB=B3=B4=EA=B8=B0=20=ED=86=B5=ED=95=A9=20=EB=B0=8F=20?= =?UTF-8?q?QR=C2=B7=EB=A0=88=EC=9D=B4=EC=95=84=EC=9B=83=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/dialog/MessageSendDialog.tsx | 64 +---------- .../dialog/SingleMessageSendDialog.tsx | 76 +------------ src/components/kri-editor/KriEditorSms.tsx | 3 +- src/components/kri-editor/types.ts | 2 + .../message-template/MessageSendPreview.tsx | 105 ++++++++++++++++++ 5 files changed, 118 insertions(+), 132 deletions(-) create mode 100644 src/components/message-template/MessageSendPreview.tsx diff --git a/src/components/dialog/MessageSendDialog.tsx b/src/components/dialog/MessageSendDialog.tsx index 4f59fbc..bcbaa98 100644 --- a/src/components/dialog/MessageSendDialog.tsx +++ b/src/components/dialog/MessageSendDialog.tsx @@ -12,24 +12,18 @@ import { useSelectedProject } from '@/hooks/useSelectedProject' import { useMainTemplateIdxQuery, useSendBulkMessageMutation, - useTemplateAttachmentImagesQuery, useTemplateListQuery, useTemplateQuery, } from '@/query/message' -import { ChannelType, TemplateSms } from '@kri/common/noti-hub' -import { cn } from '@/lib/utils' +import { ChannelType } from '@kri/common/noti-hub' import { getNearestFutureDateTime } from '@/lib/datetime' import type { DialogId } from '@/store/jotai/dialog' import { createEmptyListFilter, type ListFilter, type ListFilterTarget, type listHeader } from '@/types/list' import { ListHeaderConst } from '@/const/listConst' import type { ListTableRow } from '@/components/table-column/ListTableColumn' import ApplyFilterOption, { validateApplyFilterTarget } from './ListDialogOption/ApplyFilterOption' -import { KriEditor } from '@/components/kri-editor' -import { normalizeQrCodeForEditor, renderQrCodePreviewHtml } from '@/components/message-template/qrcode' -import { sanitizeEmailHtml } from '@/components/message-template/emailHtmlPolicy' -import { applyLinkPreviewClass } from '@/components/kri-editor/utils/linkPreview' -import TemplateAttachmentList from '@/components/message-template/TemplateAttachmentList' -import type { TemplateEmailWithAttachments, TemplateSmsWithAttachments, TemplateSummaryWithPurpose } from '@/types/message' +import MessageSendPreview from '@/components/message-template/MessageSendPreview' +import type { TemplateSummaryWithPurpose } from '@/types/message' import { TEMPLATE_PURPOSE } from '@/const/messageTemplateConst' export type MessageSendMode = 'email' | 'sms' @@ -87,11 +81,6 @@ const MessageSendDialog = ({ ) const templateDetailQuery = useTemplateQuery(templateIdx ?? 0, enabled && !!templateIdx) const selectedTemplate = templateDetailQuery.data ?? null - const smsAttachmentNames = - chnnlTy === ChannelType.SMS - ? ((selectedTemplate as TemplateSmsWithAttachments | null)?.atchFl?.split('|').filter(Boolean) ?? []) - : [] - const smsAttachmentImages = useTemplateAttachmentImagesQuery(selectedTemplate?.tmplatIdx ?? 0, smsAttachmentNames, enabled) const mainTemplateQuery = useMainTemplateIdxQuery(prjctIdx, chnnlTy, enabled) const mainTemplateIdx = mainTemplateQuery.data ?? null const selectedSids = useMemo( @@ -329,52 +318,7 @@ const MessageSendDialog = ({ -
-

미리보기

- {!selectedTemplate &&

선택된 템플릿이 없습니다.

} - {selectedTemplate && ( - <> - {chnnlTy !== ChannelType.SMS && ( -
{`제목: ${selectedTemplate.tmplatTitle}` || '(제목 없음)'}
- )} - {chnnlTy === ChannelType.SMS ? ( -
- {}} - isSmsReadOnly - placeholder="문자 내용을 입력해 주세요" - className="max-w-80 mx-0" - debounceMs={600} - smsTitle={(selectedTemplate as TemplateSms).tmplatTitle} - smsHasAttachment={smsAttachmentNames.length > 0} - smsImages={smsAttachmentImages} - /> -
- ) : ( - <> -
- - - )} - - )} -
+ ) } diff --git a/src/components/dialog/SingleMessageSendDialog.tsx b/src/components/dialog/SingleMessageSendDialog.tsx index 58a72a0..306da7f 100644 --- a/src/components/dialog/SingleMessageSendDialog.tsx +++ b/src/components/dialog/SingleMessageSendDialog.tsx @@ -11,24 +11,15 @@ import { useDialog } from '@/hooks/useDialog' import { useMainTemplateIdxQuery, useSendSingleMessageMutation, - useTemplateAttachmentImagesQuery, useTemplateListQuery, useTemplateQuery, } from '@/query/message' -import { ChannelType, type TemplateSms, type TemplateSummary } from '@kri/common/noti-hub' -import { KriEditor } from '@/components/kri-editor' -import { sanitizeEmailHtml } from '@/components/message-template/emailHtmlPolicy' +import { ChannelType, type TemplateSummary } from '@kri/common/noti-hub' import { getNearestFutureDateTime } from '@/lib/datetime' -import { escapeHtml, substituteVariables } from '@/lib/variableSubstitution' import type { DialogId } from '@/store/jotai/dialog' -import type { - MessageSendChannel, - PhoneVerificationSendData, - TemplateEmailWithAttachments, - TemplateSmsWithAttachments, -} from '@/types/message' -import TemplateAttachmentList from '@/components/message-template/TemplateAttachmentList' -import {PHONE_VERIFICATION_PREVIEW_SUFFIX, TEMPLATE_PURPOSE} from '@/const/messageTemplateConst' +import type { MessageSendChannel, PhoneVerificationSendData } from '@/types/message' +import MessageSendPreview from '@/components/message-template/MessageSendPreview' +import { TEMPLATE_PURPOSE } from '@/const/messageTemplateConst' const titleMap: Record = { email: '메일 발송', @@ -75,17 +66,9 @@ const SingleMessageSendDialog = ({ const templateList: TemplateSummary[] = templateListQuery.data ?? [] const templateDetailQuery = useTemplateQuery(templateIdx ?? 0, enabled && !!templateIdx) const selectedTemplate = templateDetailQuery.data ?? null - const smsAttachmentNames = - chnnlTy === ChannelType.SMS - ? ((selectedTemplate as TemplateSmsWithAttachments | null)?.atchFl?.split('|').filter(Boolean) ?? []) - : [] - const smsAttachmentImages = useTemplateAttachmentImagesQuery(selectedTemplate?.tmplatIdx ?? 0, smsAttachmentNames, enabled) const mainTemplateQuery = useMainTemplateIdxQuery(prjctIdx, chnnlTy, enabled) const mainTemplateIdx = mainTemplateQuery.data ?? null - const previewValues = variableValues ?? {} - const resolvedTitle = selectedTemplate ? substituteVariables(selectedTemplate.tmplatTitle ?? '', previewValues) : '' - // tmplatPurpose === 1(휴대전화번호 인증) 템플릿은 SMS/LMS 단건 즉시 발송만 허용한다. const isPhoneVerificationTemplate = selectedTemplate?.tmplatPurpose === TEMPLATE_PURPOSE.PHONE_VERIFICATION @@ -235,56 +218,7 @@ const SingleMessageSendDialog = ({ )}
-
-

미리보기

- {!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} - smsHasAttachment={smsAttachmentNames.length > 0} - smsImages={smsAttachmentImages} - /> -
- ) : ( - <> -
[key, escapeHtml(val)])), - ), - ), - }} - /> - - - )} - - )} -
+ ) } diff --git a/src/components/kri-editor/KriEditorSms.tsx b/src/components/kri-editor/KriEditorSms.tsx index 0b40870..048ffb9 100644 --- a/src/components/kri-editor/KriEditorSms.tsx +++ b/src/components/kri-editor/KriEditorSms.tsx @@ -29,6 +29,7 @@ export function KriEditorSms({ smsPreviewSuffix = '', smsHasAttachment = false, smsImages = [], + smsFrameClassName, }: SmsEditorProps) { const [text, setText] = React.useState(value || '') const textareaRef = React.useRef(null) @@ -84,7 +85,7 @@ export function KriEditorSms({ return (
{label ?
{label}
: null} -
+
diff --git a/src/components/kri-editor/types.ts b/src/components/kri-editor/types.ts index 6429fa1..02607c8 100644 --- a/src/components/kri-editor/types.ts +++ b/src/components/kri-editor/types.ts @@ -89,6 +89,8 @@ export type KriEditorProps = { smsHasAttachment?: boolean /** 문자 미리보기의 제목과 본문 사이에 표시할 첨부 이미지 */ smsImages?: KriEditorSmsImage[] + /** 휴대폰 프레임 class (기본 높이 h-[600px] 조정 등) */ + smsFrameClassName?: string toolbar?: KriEditorToolbarConfig | false fontFamilyOptions?: KriEditorFontFamilyOption[] renderToolbarEnd?: (context: KriEditorToolbarContext) => ReactNode diff --git a/src/components/message-template/MessageSendPreview.tsx b/src/components/message-template/MessageSendPreview.tsx new file mode 100644 index 0000000..e67af94 --- /dev/null +++ b/src/components/message-template/MessageSendPreview.tsx @@ -0,0 +1,105 @@ +'use client' + +import { ChannelType, type TemplateSms } from '@kri/common/noti-hub' +import { KriEditor } from '@/components/kri-editor' +import { applyLinkPreviewClass } from '@/components/kri-editor/utils/linkPreview' +import { sanitizeEmailHtml } from '@/components/message-template/emailHtmlPolicy' +import { normalizeQrCodeForEditor, renderQrCodePreviewHtml } from '@/components/message-template/qrcode' +import TemplateAttachmentList from '@/components/message-template/TemplateAttachmentList' +import { PHONE_VERIFICATION_PREVIEW_SUFFIX, TEMPLATE_PURPOSE } from '@/const/messageTemplateConst' +import { escapeHtml, substituteVariables } from '@/lib/variableSubstitution' +import { cn } from '@/lib/utils' +import { useTemplateAttachmentImagesQuery } from '@/query/message' +import type { TemplateEmailWithAttachments, TemplateSmsWithAttachments, TemplateWithPurpose } from '@/types/message' + +// 다이얼로그(max-h 90vh)의 헤더·푸터·미리보기 제목을 뺀 높이에 맞추되, +// 본문 입력칸 최소 높이(360px)가 잘리지 않도록 480px 아래로는 줄이지 않는다. +const SMS_PREVIEW_FRAME_CLASS_NAME = 'h-[clamp(480px,calc(90vh-240px),600px)]' + +export type MessageSendPreviewProps = { + chnnlTy: ChannelType + template: TemplateWithPurpose | null + /** 지정하면 [$변수] 토큰을 값으로 치환한다(없는 값은 빈 문자열). 생략하면 토큰을 그대로 보여준다. */ + variableValues?: Record +} + +/** + * 문자/메일 발송 다이얼로그 공용 미리보기. + * 이메일 본문은 템플릿 관리 미리보기(KriEditor)와 같은 순서로 sanitize → 링크 스타일 → QR 예시 이미지 변환을 거친다. + */ +const MessageSendPreview = ({ chnnlTy, template, variableValues }: MessageSendPreviewProps) => { + const isSms = chnnlTy === ChannelType.SMS + const attachmentNames = template + ? ((template as TemplateEmailWithAttachments | TemplateSmsWithAttachments).atchFl?.split('|').filter(Boolean) ?? []) + : [] + const smsAttachmentImages = useTemplateAttachmentImagesQuery( + template?.tmplatIdx ?? 0, + isSms ? attachmentNames : [], + !!template, + ) + + const substitute = (contents: string, escape = false) => { + if (!variableValues) return contents + const values = escape + ? Object.fromEntries(Object.entries(variableValues).map(([key, val]) => [key, escapeHtml(val)])) + : variableValues + return substituteVariables(contents, values) + } + + const resolvedTitle = template ? substitute(template.tmplatTitle ?? '') : '' + + return ( + // min-w-0: 다이얼로그 grid 칸 너비를 넘지 않도록 한다. +
+

미리보기

+ {!template &&

선택된 템플릿이 없습니다.

} + {template && ( + <> + {!isSms && ( +
{resolvedTitle ? `제목: ${resolvedTitle}` : '(제목 없음)'}
+ )} + {/* 본문이 길어도 다이얼로그가 아닌 미리보기 영역에서만 스크롤되도록 한다. + 문자는 휴대폰 프레임 내부에 자체 스크롤이 있으므로 프레임 높이만 줄이고 바깥 스크롤은 두지 않는다. */} +
+ {isSms ? ( +
+ {}} + isSmsReadOnly + smsPreviewSuffix={ + template.tmplatPurpose === TEMPLATE_PURPOSE.PHONE_VERIFICATION ? PHONE_VERIFICATION_PREVIEW_SUFFIX : undefined + } + placeholder="문자 내용을 입력해 주세요" + className="max-w-80 mx-0" + smsFrameClassName={SMS_PREVIEW_FRAME_CLASS_NAME} + debounceMs={600} + smsTitle={resolvedTitle} + smsHasAttachment={attachmentNames.length > 0} + smsImages={smsAttachmentImages} + /> +
+ ) : ( + <> +
+ + + )} +
+ + )} +
+ ) +} + +export default MessageSendPreview