261023_01_ENH: 문자 SMS·LMS·MMS 유형 분리 및 템플릿·발송 이력·통계 반영
This commit is contained in:
@@ -9,7 +9,7 @@ import { useTextareaInsert } from './hooks/useTextareaInsert'
|
||||
type SmsEditorProps = Omit<KriEditorProps, 'mode'> & { mode: 'sms' }
|
||||
|
||||
function calculateBytes(value: string): number {
|
||||
return Array.from(value).reduce((total, character) => total + (character.charCodeAt(0) > 127 ? 2 : 1), 0)
|
||||
return new TextEncoder().encode(value).byteLength
|
||||
}
|
||||
|
||||
export function KriEditorSms({
|
||||
@@ -34,14 +34,25 @@ export function KriEditorSms({
|
||||
const [text, setText] = React.useState(value || '')
|
||||
const textareaRef = React.useRef<HTMLTextAreaElement | null>(null)
|
||||
const latestTextRef = React.useRef(text)
|
||||
const lastTypeRef = React.useRef<'SMS' | 'LMS' | null>(null)
|
||||
const lastTypeRef = React.useRef<'SMS' | 'LMS' | 'MMS' | null>(null)
|
||||
const { scheduleChange, flushChange } = useDebouncedChange(onChange, debounceMs)
|
||||
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) || smsHasAttachment ? 'LMS' : 'SMS'
|
||||
const messageType: 'SMS' | 'LMS' | 'MMS' = smsHasAttachment ? 'MMS' : byteSize >= smsMaxBytes || Boolean(smsTitle) ? 'LMS' : 'SMS'
|
||||
const maxBytes = messageType === 'SMS' ? smsMaxBytes : lmsMaxBytes
|
||||
|
||||
function getBadgeColor(): string {
|
||||
switch (messageType) {
|
||||
case 'SMS':
|
||||
return 'bg-red-500'
|
||||
case 'LMS':
|
||||
return 'bg-blue-500'
|
||||
case 'MMS':
|
||||
return 'bg-green-500'
|
||||
}
|
||||
}
|
||||
|
||||
const commitText = React.useCallback((next: string, immediate = false) => {
|
||||
setText(next)
|
||||
latestTextRef.current = next
|
||||
@@ -90,8 +101,8 @@ export function KriEditorSms({
|
||||
<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">
|
||||
<span className="text-xs font-medium text-gray-600">{byteSize}/{maxBytes}byte</span>
|
||||
<span className={cn('rounded-md px-3 py-1 text-xs font-bold text-white', messageType === 'LMS' ? 'bg-blue-500' : 'bg-red-500')}>
|
||||
{messageType === 'LMS' ? 'LMS/MMS' : 'SMS'}
|
||||
<span className={cn('rounded-md px-3 py-1 text-xs font-bold text-white', getBadgeColor())}>
|
||||
{messageType}
|
||||
</span>
|
||||
</div>
|
||||
<div className={cn('flex flex-1 flex-col rounded-2xl bg-white shadow-sm', smsImages.length > 0 ? 'overflow-y-auto' : 'overflow-hidden')}>
|
||||
|
||||
@@ -80,12 +80,13 @@ export type KriEditorProps = {
|
||||
onImageUploadError?: (error: unknown) => void
|
||||
debounceMs?: number
|
||||
smsTitle?: string
|
||||
changeSmsType?: (type: 'SMS' | 'LMS') => void
|
||||
/** Preview only; consumers must handle MMS. Actual delivery type is determined by the server. */
|
||||
changeSmsType?: (type: 'SMS' | 'LMS' | 'MMS') => void
|
||||
isSmsReadOnly?: boolean
|
||||
smsMaxBytes?: number
|
||||
lmsMaxBytes?: number
|
||||
smsPreviewSuffix?: string
|
||||
/** 첨부파일이 있으면 길이·제목과 무관하게 LMS/MMS로 판정한다. */
|
||||
/** 첨부파일이 있으면 길이·제목과 무관하게 MMS로 판정한다. */
|
||||
smsHasAttachment?: boolean
|
||||
/** 문자 미리보기의 제목과 본문 사이에 표시할 첨부 이미지 */
|
||||
smsImages?: KriEditorSmsImage[]
|
||||
|
||||
Reference in New Issue
Block a user