'use client' import { useState } from 'react' import { RefreshCw } from 'lucide-react' import { Button } from '@/components/ui/button' import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group' import { KriDateTimePicker } from '@/components/common/KriDateTimePicker' import CollapsibleHistorySection from '@/components/list-contact/CollapsibleHistorySection' import { useAddListEventMutation, useListEventHistoryQuery, useReserveMutation } from '@/query/list' import { useSendResultBySidQuery } from '@/query/message' import { useInternalInfoQuery } from '@/query/internal' import { clientEnv } from '@/lib/env.client' import { ChannelType } from '@kri/common/noti-hub' import type { SendResultInfo } from '@/types/message' import { formatKst } from '@kri/common' import { type ResultCode, ResultCodeType } from '@/types/project' import { CONTACT_INTERVIEWER_ROLE, FIELD_INTERVIEWER_ROLE } from '@/const/userConst' import { RESULT_CODE_RESERVATION, RESULT_CODE_UNUSED } from '@/const/projectConst' import { cn } from '@/lib/utils' import { getNearestFutureDateTime } from '@/lib/datetime' import { useCtiLastCallHistId } from '@/hooks/useCtiLastCallHistId' import { getCurrentPositionMeta } from '@kri/common/browser' import type { listHeader, ListSearchWithFullResult } from '@/types/list' import { buildListContactVariableValues } from '@/components/list-contact/listContactVariables' import { substituteVariables } from '@/lib/surveyUrl' import { sanitizeHtml } from '@/components/kri-editor/utils/sanitizeHtml' const escapeHtml = (value: string) => value.replace( /[&<>"']/g, (character) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''', })[character] ?? character, ) const RefreshIconButton = ({ onRefresh, isFetching }: { onRefresh: () => void; isFetching: boolean }) => ( ) type ContactEventSectionProps = { title: string prjctIdx: number sid: string resultCodeType: ResultCodeType resultCodes: ResultCode[] showReservation?: boolean showInput?: boolean submitting: boolean onSubmit: (resultCd: number, memo: string, resveDt: string, listCallHistIdx: number | null) => Promise } const EventHistoryList = ({ isLoading, history, resultCodeType, resultCodes, }: { isLoading: boolean history: ReturnType['data'] resultCodeType: ResultCodeType resultCodes: ResultCode[] }) => { const filteredHistory = (history ?? []) .filter((item) => item.eventTy === resultCodeType) .sort((a, b) => new Date(b.regDt).getTime() - new Date(a.regDt).getTime()) const resolveLabel = (resultCd: number) => resultCodes.find((code) => code.resultCdTy === resultCodeType && code.resultCd === resultCd)?.resultCdLbl ?? String(resultCd) if (isLoading) { return
불러오는 중...
} if (filteredHistory.length === 0) { return
이력이 없습니다.
} return (
{filteredHistory.map((item) => ( ))}
결과 메모 등록자 일시
{item.resultCd}.{resolveLabel(item.resultCd)} {item.memo || '-'} {item.regUser} {formatKst(item.regDt, 'dateHourMin')}
) } const ContactEventSection = ({ title, prjctIdx, sid, resultCodeType, resultCodes, showReservation = false, showInput = true, submitting, onSubmit, }: ContactEventSectionProps) => { const [resultCd, setResultCd] = useState('') const [memo, setMemo] = useState('') const [resveDt, setResveDt] = useState('') const codes = resultCodes.filter((code) => code.resultCdTy === resultCodeType && code.resultCd !== RESULT_CODE_UNUSED) const isReservationSelected = resultCd === String(RESULT_CODE_RESERVATION) const isContactType = resultCodeType === ResultCodeType.CONTACT const historyQuery = useListEventHistoryQuery(prjctIdx, sid, true) const ctiLastCallHistId = useCtiLastCallHistId(prjctIdx, sid) const listCallHistIdx = isContactType ? ctiLastCallHistId : null const handleResultCdChange = (next: string) => { setResultCd(next) if (next === String(RESULT_CODE_RESERVATION) && !resveDt) { setResveDt(getNearestFutureDateTime()) } } const handleAdd = async () => { if (!resultCd) { alert('결과 코드를 선택해주세요.') return } if (isReservationSelected && !resveDt) { alert('예약 날짜/시간을 선택해주세요.') return } if (isContactType && !listCallHistIdx) { if (!confirm('통화 기록이 없습니다. 계속 진행하시겠습니까?')) return } await onSubmit(Number(resultCd), memo, isReservationSelected ? resveDt : '', listCallHistIdx) setMemo('') setResveDt('') } return (

{title}

{showInput ? ( <> {codes.map((code) => ( ))}