update(front): front 폴더명 frontend로 변경
This commit is contained in:
1 parent
698d4e72d4
commit
16848e9f63
85 files changed
No files matched your search
@@ -0,0 +1,45 @@
|
||||
const digits = ['', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구']
|
||||
const units = ['', '십', '백', '천']
|
||||
const higherUnits = ['', '만', '억', '조', '경', '해']
|
||||
|
||||
// 숫자를 한글 표기로 (예: 12000 → 일만이천)
|
||||
export function numberToKorean(num: number): string {
|
||||
if (num === 0) return '영'
|
||||
|
||||
const groups: number[] = []
|
||||
let numStr = num.toString()
|
||||
while (numStr.length > 0) {
|
||||
groups.unshift(parseInt(numStr.slice(-4)))
|
||||
numStr = numStr.slice(0, -4)
|
||||
}
|
||||
|
||||
let result = ''
|
||||
const groupLen = groups.length
|
||||
for (let idx = 0; idx < groupLen; idx++) {
|
||||
const group = groups[idx]
|
||||
if (group === 0) continue
|
||||
const groupStr = processGroup(group, idx === 0)
|
||||
result += groupStr + higherUnits[groupLen - idx - 1]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function processGroup(num: number, isFirstGroup = false): string {
|
||||
const numStr = num.toString().padStart(4, '0')
|
||||
let result = ''
|
||||
for (let idx = 0; idx < numStr.length; idx++) {
|
||||
const digit = parseInt(numStr[idx])
|
||||
const unit = units[3 - idx]
|
||||
if (digit === 0) continue
|
||||
if (digit === 1) {
|
||||
if (unit !== '') {
|
||||
result += isFirstGroup && unit === '천' ? digits[digit] + unit : unit
|
||||
} else {
|
||||
result += '일'
|
||||
}
|
||||
} else {
|
||||
result += digits[digit] + unit
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { ChatMessage } from '@/features/chat/types'
|
||||
|
||||
// reject 폼 직전 사용자 답변(script)을 찾아 복원용으로 반환
|
||||
export function findRestoreScript(messages: ChatMessage[], type: 'rejectCM' | 'rejectRSP'): string | null {
|
||||
const reversed = [...messages].reverse()
|
||||
const idx = reversed.findIndex((m) => m.bot_chat_type === type)
|
||||
if (idx > 0 && reversed[idx - 1]?.sender === 'user') return reversed[idx - 1].script
|
||||
return null
|
||||
}
|
||||
|
||||
export function extractPart(script: string | null, prefix: string): string {
|
||||
return script?.split(', ').find((p) => p.startsWith(prefix))?.replace(prefix, '') ?? ''
|
||||
}
|
||||
|
||||
// 재협상(RSP) 폼 복원: 가격 + 사유(기타-내용 포함)
|
||||
export function restoreRejectRSP(script: string | null) {
|
||||
const empty = { price: '', selectedReason: '', reason: '' }
|
||||
if (!script) return empty
|
||||
const parts = script.split(', ')
|
||||
const price = parts.find((p) => p.startsWith('공급희망가격-'))?.replace('공급희망가격-', '') ?? ''
|
||||
const reasonRaw = parts.find((p) => p.startsWith('합의불가사유-'))?.replace('합의불가사유-', '') ?? ''
|
||||
if (reasonRaw.startsWith('기타-')) return { price, selectedReason: '기타', reason: reasonRaw.replace('기타-', '') }
|
||||
return { price, selectedReason: reasonRaw, reason: '' }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// 마감까지 남은 시간 'HH시간 MM분 SS초'. 지났으면 종료 문구, 잘못된 값은 '-'.
|
||||
export function getTimeRemaining(targetDateTime: string | Date): string {
|
||||
const now = Date.now()
|
||||
const target = new Date(targetDateTime).getTime()
|
||||
if (Number.isNaN(target)) return '-'
|
||||
|
||||
const diff = target - now
|
||||
if (diff <= 0) return '종료되었습니다.'
|
||||
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60))
|
||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
|
||||
const seconds = Math.floor((diff % (1000 * 60)) / 1000)
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${pad(hours)}시간 ${pad(minutes)}분 ${pad(seconds)}초`
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { ChatMessage, UserButtonConfig } from '@/features/chat/types'
|
||||
|
||||
export const GO_TO_LIST_TEXT = '상품 목록으로 가기'
|
||||
|
||||
// 마지막 봇 메시지의 next_input_mode 로 하단 입력 UI 구성을 결정한다.
|
||||
export function deriveUserButtonConfig(
|
||||
messages: ChatMessage[],
|
||||
isLoading: boolean,
|
||||
priceErrorMessage: string,
|
||||
): UserButtonConfig {
|
||||
if (isLoading) return { type: 'loading' }
|
||||
if (!messages || messages.length === 0) return { type: '', text: '' }
|
||||
|
||||
const last = messages[messages.length - 1]
|
||||
const mode = last.next_input_mode
|
||||
const options = last.next_input_type
|
||||
|
||||
if (last.chat_end) return { type: 'one-black', text: GO_TO_LIST_TEXT }
|
||||
if (mode === 'confirm') return { type: 'one-black', text: options?.[0] || '' }
|
||||
if (mode === 'yes_no') return { type: 'black-white', textList: options || [] }
|
||||
if (mode === 'percent') return { type: 'percent' }
|
||||
if (mode === 'price') return { type: 'price', priceErrorMessage: priceErrorMessage || undefined }
|
||||
if (mode === 'delivery_type') return { type: 'three-black', textList: options || [] }
|
||||
return { type: '', text: '' }
|
||||
}
|
||||
Reference in new issue
Block a user