260714_01_ENH: 테스트 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
285
src/components/list-contact/ListContactInfoPanel.tsx
Normal file
285
src/components/list-contact/ListContactInfoPanel.tsx
Normal file
@@ -0,0 +1,285 @@
|
||||
'use client'
|
||||
|
||||
import { useRef, useState, type ReactNode } from 'react'
|
||||
import { Mail, MessageSquare, Paperclip, Phone, QrCode } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { KriSingleSelect } from '@/components/common/KriAutoComplete'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import { useUploadListItemFileMutation } from '@/query/list'
|
||||
import { ListHeaderConst } from '@/const/listConst'
|
||||
import type { listHeader, ListSearchWithFullResult } from '@/types/list'
|
||||
import type { MessageSendChannel } from '@/types/message'
|
||||
import { isListFieldEditableForContact, isListFieldVisibleForContact } from '@/utils/listAccess'
|
||||
import { substituteSurveyUrl } from '@/lib/surveyUrl'
|
||||
import SurveyQrDialog from '@/components/dialog/SurveyQrDialog'
|
||||
import SingleMessageSendDialog from '@/components/dialog/SingleMessageSendDialog'
|
||||
import { ctiClient } from '@/lib/cti/ctiClient'
|
||||
import { useCtiConnectionStatus } from '@/hooks/useCtiConnectionStatus'
|
||||
import { useCtiAgentStatus } from '@/hooks/useCtiAgentStatus'
|
||||
import { CTI_ON_CALL_STATUSES } from '@/const/ctiConst'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export type ListContactInfoPanelProps = {
|
||||
prjctIdx: number
|
||||
sid: string
|
||||
itrntPrjctCd: string
|
||||
userRole: number
|
||||
isEditing: boolean
|
||||
listHeaders: listHeader[]
|
||||
detail?: ListSearchWithFullResult
|
||||
surveyUrl?: string
|
||||
formValues: Record<number, string>
|
||||
onFieldChange: (listHderId: number, value: string) => void
|
||||
onSaved?: () => void
|
||||
}
|
||||
|
||||
export const buildInitialValues = (listHeaders: listHeader[], detail?: ListSearchWithFullResult) => {
|
||||
const values: Record<number, string> = {}
|
||||
|
||||
for (const header of listHeaders) {
|
||||
if (header.listHderTy === ListHeaderConst.SID) continue
|
||||
if (!isListFieldVisibleForContact(header)) continue
|
||||
if (header.listHderTy === ListHeaderConst.MEMO) {
|
||||
values[header.listHderId] = detail?.memo ?? ''
|
||||
continue
|
||||
}
|
||||
values[header.listHderId] = detail?.itemList?.[header.listHderId] ?? ''
|
||||
}
|
||||
|
||||
return values
|
||||
}
|
||||
|
||||
const disabledContrastClass = 'disabled:opacity-100 disabled:text-foreground disabled:bg-muted/60'
|
||||
|
||||
const FieldRow = ({ label, children }: { label: string; children: ReactNode }) => (
|
||||
<div className="flex items-center gap-3">
|
||||
<Label className="w-24 shrink-0 text-sm font-bold text-foreground">{label}</Label>
|
||||
<div className="min-w-0 flex-1">{children}</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
const ListContactInfoPanel = ({
|
||||
prjctIdx,
|
||||
sid,
|
||||
itrntPrjctCd,
|
||||
userRole,
|
||||
isEditing,
|
||||
listHeaders,
|
||||
detail,
|
||||
surveyUrl,
|
||||
formValues,
|
||||
onFieldChange,
|
||||
onSaved,
|
||||
}: ListContactInfoPanelProps) => {
|
||||
const { showDialog } = useDialog()
|
||||
const uploadItemFileMutation = useUploadListItemFileMutation(prjctIdx, sid)
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null)
|
||||
const [uploadingHeaderId, setUploadingHeaderId] = useState<number | null>(null)
|
||||
const [sendTarget, setSendTarget] = useState<{ channel: MessageSendChannel; headerId: number } | null>(null)
|
||||
const ctiConnectionStatus = useCtiConnectionStatus()
|
||||
const isCtiReady = ctiConnectionStatus === 'open'
|
||||
const ctiAgentStatus = useCtiAgentStatus()
|
||||
const isOnCall = ctiAgentStatus !== null && (CTI_ON_CALL_STATUSES as readonly string[]).includes(ctiAgentStatus)
|
||||
|
||||
const visibleHeaders = listHeaders
|
||||
.filter((header) => isListFieldVisibleForContact(header))
|
||||
.sort((a, b) => a.listHderOrder - b.listHderOrder)
|
||||
|
||||
const substitutedSurveyUrl = surveyUrl ? substituteSurveyUrl(surveyUrl, sid) : ''
|
||||
const hasSurveyResponse = detail?.surveyResult?.lastResultCd !== undefined
|
||||
|
||||
const handleStartSurvey = () => {
|
||||
if (!substitutedSurveyUrl) return
|
||||
window.open(substitutedSurveyUrl, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
|
||||
const handleSend = (channel: MessageSendChannel, headerId: number) => {
|
||||
setSendTarget({ channel, headerId })
|
||||
showDialog('singleMessageSendDialog')
|
||||
}
|
||||
|
||||
const handleCall = (telNum: string, listHderId: number) => {
|
||||
if (!telNum || !isCtiReady || isOnCall) return
|
||||
ctiClient.makeCall({ dialNumber: telNum, prjctIdx, sid: Number(sid), listHderId })
|
||||
}
|
||||
|
||||
const handlePickFile = (listHderId: number) => {
|
||||
setUploadingHeaderId(listHderId)
|
||||
fileInputRef.current?.click()
|
||||
}
|
||||
|
||||
const handleFileSelected = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0]
|
||||
e.target.value = ''
|
||||
if (!file || uploadingHeaderId === null) return
|
||||
|
||||
await uploadItemFileMutation.mutateAsync({ listHderId: uploadingHeaderId, file })
|
||||
setUploadingHeaderId(null)
|
||||
alert('파일이 업로드되었습니다.')
|
||||
onSaved?.()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4 rounded-lg border bg-white p-4">
|
||||
<h2 className="text-lg font-bold">리스트 정보</h2>
|
||||
<input type="file" ref={fileInputRef} className="hidden" onChange={handleFileSelected} />
|
||||
|
||||
{visibleHeaders.map((header) => {
|
||||
if (header.listHderTy === ListHeaderConst.SID) return null
|
||||
|
||||
const editable = isEditing && isListFieldEditableForContact(header, userRole)
|
||||
const value = formValues[header.listHderId] ?? ''
|
||||
const onChange = (next: string) => onFieldChange(header.listHderId, next)
|
||||
|
||||
if (header.listHderTy === ListHeaderConst.MEMO) {
|
||||
return (
|
||||
<FieldRow key={header.listHderId} label={header.listHderNm}>
|
||||
<textarea
|
||||
className={`flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed ${disabledContrastClass}`}
|
||||
value={value}
|
||||
disabled={!editable}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
</FieldRow>
|
||||
)
|
||||
}
|
||||
|
||||
if (header.listHderTy === ListHeaderConst.TEL_NUM) {
|
||||
return (
|
||||
<FieldRow key={header.listHderId} label={header.listHderNm}>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={value}
|
||||
disabled={!editable}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className={disabledContrastClass}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className={cn('shrink-0 gap-2', isOnCall && 'bg-accent text-accent-foreground')}
|
||||
disabled={!isCtiReady || isOnCall}
|
||||
title={!isCtiReady ? '전화 시스템에 연결되어 있지 않습니다.' : undefined}
|
||||
onClick={() => handleCall(value, header.listHderId)}
|
||||
>
|
||||
<Phone className="h-4 w-4" />
|
||||
{isOnCall ? '통화중' : '전화'}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="shrink-0 gap-2"
|
||||
onClick={() => handleSend('sms', header.listHderId)}
|
||||
>
|
||||
<MessageSquare className="h-4 w-4" />
|
||||
발송
|
||||
</Button>
|
||||
</div>
|
||||
</FieldRow>
|
||||
)
|
||||
}
|
||||
|
||||
if (header.listHderTy === ListHeaderConst.EMAIL) {
|
||||
return (
|
||||
<FieldRow key={header.listHderId} label={header.listHderNm}>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={value}
|
||||
disabled={!editable}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className={disabledContrastClass}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="shrink-0 gap-2"
|
||||
onClick={() => handleSend('email', header.listHderId)}
|
||||
>
|
||||
<Mail className="h-4 w-4" />
|
||||
발송
|
||||
</Button>
|
||||
</div>
|
||||
</FieldRow>
|
||||
)
|
||||
}
|
||||
|
||||
if (header.listHderTy === ListHeaderConst.FILE) {
|
||||
return (
|
||||
<FieldRow key={header.listHderId} label={header.listHderNm}>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 flex-1 truncate text-sm">{value || '업로드된 파일 없음'}</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="shrink-0 gap-2"
|
||||
disabled={!editable || uploadItemFileMutation.isPending}
|
||||
onClick={() => handlePickFile(header.listHderId)}
|
||||
>
|
||||
<Paperclip className="h-4 w-4" />
|
||||
업로드
|
||||
</Button>
|
||||
</div>
|
||||
</FieldRow>
|
||||
)
|
||||
}
|
||||
|
||||
if (header.listHderTy === ListHeaderConst.CONTENT_ITEM && (header.filterContents?.length ?? 0) > 0) {
|
||||
return (
|
||||
<FieldRow key={header.listHderId} label={header.listHderNm}>
|
||||
<KriSingleSelect
|
||||
items={header.filterContents ?? []}
|
||||
value={value}
|
||||
disabled={!editable}
|
||||
onChange={onChange}
|
||||
getValue={(item) => item}
|
||||
getLabel={(item) => item}
|
||||
widthClassName="w-full"
|
||||
heightClassName="h-9"
|
||||
className={disabledContrastClass}
|
||||
/>
|
||||
</FieldRow>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<FieldRow key={header.listHderId} label={header.listHderNm}>
|
||||
<Input
|
||||
value={value}
|
||||
disabled={!editable}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className={disabledContrastClass}
|
||||
/>
|
||||
</FieldRow>
|
||||
)
|
||||
})}
|
||||
|
||||
{surveyUrl ? (
|
||||
<FieldRow label="Web">
|
||||
<div className="flex items-center gap-2">
|
||||
<Button type="button" className="gap-2" onClick={handleStartSurvey}>
|
||||
조사 시작
|
||||
</Button>
|
||||
<Button type="button" variant="outline" className="gap-2" onClick={() => showDialog('surveyQrDialog')}>
|
||||
<QrCode className="h-4 w-4" />
|
||||
QR
|
||||
</Button>
|
||||
{!hasSurveyResponse && <span className="text-sm text-muted-foreground">[응답없음]</span>}
|
||||
</div>
|
||||
</FieldRow>
|
||||
) : null}
|
||||
|
||||
<SurveyQrDialog url={substitutedSurveyUrl} />
|
||||
<SingleMessageSendDialog
|
||||
channel={sendTarget?.channel ?? 'sms'}
|
||||
prjctIdx={prjctIdx}
|
||||
itrntPrjctCd={itrntPrjctCd}
|
||||
sid={sid}
|
||||
destHeaderId={sendTarget?.headerId ?? 0}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ListContactInfoPanel
|
||||
Reference in New Issue
Block a user