import { useState } from 'react' import { X } from 'lucide-react' import { Modal } from '@/components' import { useMeQuery } from '@/apis' import type { SessionField } from '@/apis/auth/auth.type' import type { ListItem } from '../types' export interface ExtraInfoPopupProps { target: ListItem onClose: () => void /** 부가정보 저장 (custom = {key: value}) */ onSubmit: (custom: Record) => void } // 협상완료 부가정보 입력 팝업. 필드 정의(session_fields)는 회사 설정(/me)에서 오고, 기존 입력값(target.custom)으로 프리필. export function ExtraInfoPopup({ target, onClose, onSubmit }: ExtraInfoPopupProps) { const { data: user } = useMeQuery() const fields: SessionField[] = user?.sessionFields ?? [] const [values, setValues] = useState>(() => { const init: Record = {} for (const f of fields) init[f.key] = target.custom?.[f.key] ?? (f.type === 'boolean' ? false : '') return init }) const [opinion, setOpinion] = useState(() => String(target.custom?.opinion ?? '')) const set = (key: string, value: unknown) => setValues((v) => ({ ...v, [key]: value })) const handleSubmit = () => { // 빈 값은 제외하고 저장(부분 입력 허용) const out: Record = {} for (const f of fields) { const v = values[f.key] if (f.type === 'boolean') out[f.key] = !!v else if (v !== '' && v != null) out[f.key] = f.type === 'number' ? Number(v) : v } if (opinion.trim()) out.opinion = opinion.trim() onSubmit(out) onClose() } return (

협상완료 부가정보

{target.qt_number} · {target.item_name}

{fields.map((f) => (
{f.type === 'boolean' ? ( ) : f.type === 'select' ? ( ) : ( set(f.key, e.target.value)} className="h-11 w-full rounded-xl border border-border bg-white px-3 text-sm outline-none focus:border-brand-600 focus:ring-1 focus:ring-brand-600" placeholder={f.label} /> )}
))}