261001_02_ENH: 발송 다이얼로그 미리보기 통합 및 QR·레이아웃 오류 수정
This commit is contained in:
@@ -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 = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border p-4 space-y-2">
|
||||
<p className="text-lg font-semibold">미리보기</p>
|
||||
{!selectedTemplate && <p className="text-sm text-muted-foreground">선택된 템플릿이 없습니다.</p>}
|
||||
{selectedTemplate && (
|
||||
<>
|
||||
{chnnlTy !== ChannelType.SMS && (
|
||||
<div className="rounded border p-2 text-lg font-semibold">{`제목: ${selectedTemplate.tmplatTitle}` || '(제목 없음)'}</div>
|
||||
)}
|
||||
{chnnlTy === ChannelType.SMS ? (
|
||||
<div className="flex flex-col items-center">
|
||||
<KriEditor
|
||||
mode="sms"
|
||||
value={(selectedTemplate as TemplateSms).tmplatBody ?? ""}
|
||||
onChange={() => {}}
|
||||
isSmsReadOnly
|
||||
placeholder="문자 내용을 입력해 주세요"
|
||||
className="max-w-80 mx-0"
|
||||
debounceMs={600}
|
||||
smsTitle={(selectedTemplate as TemplateSms).tmplatTitle}
|
||||
smsHasAttachment={smsAttachmentNames.length > 0}
|
||||
smsImages={smsAttachmentImages}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div
|
||||
className={cn('kri-editor-preview rounded-md border bg-muted/30 p-3')}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: renderQrCodePreviewHtml(
|
||||
applyLinkPreviewClass(
|
||||
sanitizeEmailHtml(
|
||||
normalizeQrCodeForEditor(selectedTemplate.tmplatBody) || '(내용 없음)',
|
||||
),
|
||||
),
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<TemplateAttachmentList
|
||||
tmplatIdx={selectedTemplate.tmplatIdx}
|
||||
atchFl={(selectedTemplate as TemplateEmailWithAttachments).atchFl}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<MessageSendPreview chnnlTy={chnnlTy} template={selectedTemplate} />
|
||||
</KriDialog>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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<MessageSendChannel, string> = {
|
||||
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 = ({
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2 rounded-md border p-4">
|
||||
<p className="text-sm font-semibold">미리보기</p>
|
||||
{!selectedTemplate && <p className="text-sm text-muted-foreground">선택된 템플릿이 없습니다.</p>}
|
||||
{selectedTemplate && (
|
||||
<>
|
||||
{chnnlTy !== ChannelType.SMS && (
|
||||
<div className="rounded border p-2 text-sm font-semibold">{resolvedTitle ? `제목: ${resolvedTitle}` : '(제목 없음)'}</div>
|
||||
)}
|
||||
{chnnlTy === ChannelType.SMS ? (
|
||||
<div className="flex flex-col items-center">
|
||||
<KriEditor
|
||||
mode="sms"
|
||||
value={substituteVariables((selectedTemplate as TemplateSms).tmplatBody ?? '', previewValues)}
|
||||
onChange={() => {}}
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div
|
||||
className="rounded-md border bg-muted/30 p-3 text-sm"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: sanitizeEmailHtml(
|
||||
substituteVariables(
|
||||
selectedTemplate.tmplatBody || '(내용 없음)',
|
||||
Object.fromEntries(Object.entries(previewValues).map(([key, val]) => [key, escapeHtml(val)])),
|
||||
),
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<TemplateAttachmentList
|
||||
tmplatIdx={selectedTemplate.tmplatIdx}
|
||||
atchFl={(selectedTemplate as TemplateEmailWithAttachments).atchFl}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<MessageSendPreview chnnlTy={chnnlTy} template={selectedTemplate} variableValues={variableValues ?? {}} />
|
||||
</KriDialog>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ export function KriEditorSms({
|
||||
smsPreviewSuffix = '',
|
||||
smsHasAttachment = false,
|
||||
smsImages = [],
|
||||
smsFrameClassName,
|
||||
}: SmsEditorProps) {
|
||||
const [text, setText] = React.useState(value || '')
|
||||
const textareaRef = React.useRef<HTMLTextAreaElement | null>(null)
|
||||
@@ -84,7 +85,7 @@ export function KriEditorSms({
|
||||
return (
|
||||
<div className={cn('mx-auto w-full max-w-[320px]', className)}>
|
||||
{label ? <div className="mb-2 text-sm font-semibold">{label}</div> : null}
|
||||
<div className="relative h-[600px] w-full overflow-hidden rounded-[40px] border-8 border-gray-800 bg-white shadow-2xl">
|
||||
<div className={cn('relative h-[600px] w-full overflow-hidden rounded-[40px] border-8 border-gray-800 bg-white shadow-2xl', smsFrameClassName)}>
|
||||
<div className="absolute top-0 left-1/2 z-10 h-6 w-32 -translate-x-1/2 rounded-b-2xl bg-gray-800" />
|
||||
<div className="flex h-full flex-col bg-gray-50 px-4 pt-8 pb-4">
|
||||
<div className="mb-3 flex items-center justify-between px-2">
|
||||
|
||||
@@ -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
|
||||
|
||||
105
src/components/message-template/MessageSendPreview.tsx
Normal file
105
src/components/message-template/MessageSendPreview.tsx
Normal file
@@ -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<string, string>
|
||||
}
|
||||
|
||||
/**
|
||||
* 문자/메일 발송 다이얼로그 공용 미리보기.
|
||||
* 이메일 본문은 템플릿 관리 미리보기(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 칸 너비를 넘지 않도록 한다.
|
||||
<div className="min-w-0 space-y-2 rounded-md border p-4">
|
||||
<p className="text-lg font-semibold">미리보기</p>
|
||||
{!template && <p className="text-sm text-muted-foreground">선택된 템플릿이 없습니다.</p>}
|
||||
{template && (
|
||||
<>
|
||||
{!isSms && (
|
||||
<div className="rounded border p-2 text-lg font-semibold wrap-anywhere">{resolvedTitle ? `제목: ${resolvedTitle}` : '(제목 없음)'}</div>
|
||||
)}
|
||||
{/* 본문이 길어도 다이얼로그가 아닌 미리보기 영역에서만 스크롤되도록 한다.
|
||||
문자는 휴대폰 프레임 내부에 자체 스크롤이 있으므로 프레임 높이만 줄이고 바깥 스크롤은 두지 않는다. */}
|
||||
<div className={cn('space-y-2', !isSms && 'max-h-[60vh] overflow-y-auto')}>
|
||||
{isSms ? (
|
||||
<div className="flex flex-col items-center">
|
||||
<KriEditor
|
||||
mode="sms"
|
||||
value={substitute((template as TemplateSms).tmplatBody ?? '')}
|
||||
onChange={() => {}}
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div
|
||||
className="kri-editor-preview rounded-md border bg-muted/30 p-3 wrap-anywhere"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: renderQrCodePreviewHtml(
|
||||
applyLinkPreviewClass(
|
||||
sanitizeEmailHtml(normalizeQrCodeForEditor(substitute(template.tmplatBody ?? '', true)) || '(내용 없음)'),
|
||||
),
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<TemplateAttachmentList tmplatIdx={template.tmplatIdx} atchFl={attachmentNames.join('|')} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default MessageSendPreview
|
||||
Reference in New Issue
Block a user