25 lines
1.3 KiB
TypeScript
25 lines
1.3 KiB
TypeScript
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: '' }
|
|
}
|