'use client' import { useState } from 'react' import { RefreshCw, Trash2 } 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, useDeleteListEventMutation, useListEventHistoryQuery, useReserveMutation } from '@/query/list' import { useSendResultBySidQuery } from '@/query/message' import { useInternalInfoQuery } from '@/query/internal' import { clientEnv } from '@/lib/env.client' import { ChannelType, isSendCancelable } from '@kri/common/noti-hub' import { MESSAGE_TYPE_LABEL } from '@/const/messageTemplateConst' import type { SendResultInfo } from '@kri/common/noti-hub' import { useSendCancel } from '@/hooks/useSendCancel' 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 { escapeHtml, substituteVariables } from '@/lib/variableSubstitution' import { sanitizeHtml } from '@/components/kri-editor/utils/sanitizeHtml' import { isInternalManager } from '@/utils/userRole' 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 canDelete: boolean } const EventHistoryList = ({ isLoading, history, resultCodeType, resultCodes, canDelete = false, onDelete, isDeleting = false, }: { isLoading: boolean history: ReturnType['data'] resultCodeType: ResultCodeType resultCodes: ResultCode[] canDelete?: boolean onDelete?: (listEventHistIdx: number) => void isDeleting?: boolean }) => { 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) const handleDelete = (listEventHistIdx: number) => { if (!confirm('이력을 삭제하시겠습니까?')) return onDelete?.(listEventHistIdx) } if (isLoading) { return
불러오는 중...
} if (filteredHistory.length === 0) { return
이력이 없습니다.
} return (
{canDelete ? : null} {filteredHistory.map((item) => ( {canDelete ? ( ) : null} ))}
결과 메모 등록자 일시삭제
{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, canDelete, }: 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 deleteEventMutation = useDeleteListEventMutation(prjctIdx, sid) 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) => ( ))}