261001_02_ENH: 발송 다이얼로그 미리보기 통합 및 QR·레이아웃 오류 수정

This commit is contained in:
2026-10-01 16:35:55 +09:00
parent 11f7ec1719
commit 825cf5f35f
5 changed files with 118 additions and 132 deletions

View File

@@ -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>
)
}