251210_01_ENH : 프로젝트 수정, 에디터 구현중
This commit is contained in:
325
src/components/dialog/ResultCodeDialog.tsx
Normal file
325
src/components/dialog/ResultCodeDialog.tsx
Normal file
@@ -0,0 +1,325 @@
|
||||
'use client'
|
||||
|
||||
import { useMemo, useState } from 'react'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import {Trash2, Plus, Download, Search, XIcon} from 'lucide-react'
|
||||
|
||||
export type ResultCode = {
|
||||
code: string
|
||||
label: string
|
||||
}
|
||||
|
||||
type Project = {
|
||||
prjctCd: string
|
||||
prjctName: string
|
||||
resultCodes: ResultCode[]
|
||||
}
|
||||
|
||||
type ResultCodeDialogProps = {
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
onSave?: (codes: ResultCode[]) => void
|
||||
}
|
||||
|
||||
const ResultCodeDialog = ({ open, onOpenChange, onSave }: ResultCodeDialogProps) => {
|
||||
const [importMode, setImportMode] = useState(false)
|
||||
const [selectedProject, setSelectedProject] = useState<string>('')
|
||||
|
||||
const [resultCodes, setResultCodes] = useState<ResultCode[]>([
|
||||
{ code: '0', label: '컨택 성공' },
|
||||
{ code: '1', label: '통화 예약' },
|
||||
{ code: '2', label: '비수신' },
|
||||
{ code: '3', label: '부재' },
|
||||
{ code: '4', label: '휴가' },
|
||||
{ code: '5', label: '출장' },
|
||||
{ code: '6', label: '단순 거절' },
|
||||
{ code: '7', label: '강력 거절' },
|
||||
{ code: '8', label: '그런 사람 아님' },
|
||||
{ code: '9', label: '메일 발송' },
|
||||
{ code: '10', label: '독려' },
|
||||
{ code: '11', label: '퇴사' },
|
||||
{ code: '12', label: '기타' },
|
||||
{ code: '13', label: '조사 대상 아님' },
|
||||
{ code: '14', label: '수신 거부' },
|
||||
])
|
||||
|
||||
// 샘플 프로젝트 목록 (실제로는 API에서 가져옴)
|
||||
const projects: Project[] = [
|
||||
{
|
||||
prjctCd: '250701yd',
|
||||
prjctName: '250701yd',
|
||||
resultCodes: [
|
||||
{ code: '0', label: '완료' },
|
||||
{ code: '1', label: '거절' },
|
||||
{ code: '2', label: '진행중' },
|
||||
],
|
||||
},
|
||||
{
|
||||
prjctCd: '1509013',
|
||||
prjctName: '1509013_J2307KJC_KFB_저기 1차 카카오톡 AUTOAGI_#01250Group',
|
||||
resultCodes: [
|
||||
{ code: '0', label: '성공' },
|
||||
{ code: '1', label: '실패' },
|
||||
{ code: '2', label: '보류' },
|
||||
],
|
||||
},
|
||||
{
|
||||
prjctCd: '1503013',
|
||||
prjctName: '1503013_J2307KJC_KFB_저기 1차 카카오톡 AUTOAGI_그룹01테스트0',
|
||||
resultCodes: [
|
||||
{ code: '0', label: '승인' },
|
||||
{ code: '1', label: '반려' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const [projectSearch, setProjectSearch] = useState('')
|
||||
const filteredProjects = useMemo(() => {
|
||||
const q = projectSearch.trim().toLowerCase()
|
||||
if (!q) return projects
|
||||
return projects.filter(p =>
|
||||
`${p.prjctCd} ${p.prjctName}`.toLowerCase().includes(q)
|
||||
)
|
||||
}, [projectSearch])
|
||||
|
||||
const selectedProjectData = useMemo(
|
||||
() => projects.find(p => p.prjctCd === selectedProject),
|
||||
[selectedProject]
|
||||
)
|
||||
|
||||
const handleAddCode = () => {
|
||||
setResultCodes(prev => [...prev, { code: String(prev.length), label: '' }])
|
||||
}
|
||||
|
||||
const handleDeleteCode = (index: number) => {
|
||||
setResultCodes(prev => prev.filter((_, i) => i !== index))
|
||||
}
|
||||
|
||||
const handleCodeChange = (index: number, field: keyof ResultCode, value: string) => {
|
||||
setResultCodes(prev => {
|
||||
const next = [...prev]
|
||||
next[index] = { ...next[index], [field]: value }
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
const handleImportClick = () => {
|
||||
setImportMode(true)
|
||||
}
|
||||
|
||||
const handleImportApply = () => {
|
||||
if (selectedProjectData) {
|
||||
setResultCodes(selectedProjectData.resultCodes)
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
}
|
||||
|
||||
const handleImportCancel = () => {
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
|
||||
const handleSave = () => {
|
||||
onSave?.(resultCodes)
|
||||
onOpenChange?.(false)
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
onOpenChange?.(false)
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
{/* ✅ importMode일 때 더 넓게(그리고 애니메이션으로 부드럽게) */}
|
||||
<DialogContent
|
||||
className={[
|
||||
'p-0 overflow-hidden',
|
||||
'transition-all duration-200',
|
||||
importMode ? 'sm:max-w-6xl' : 'sm:max-w-3xl',
|
||||
'w-[calc(100vw-2rem)]',
|
||||
'max-h-[85vh]',
|
||||
'gap-2',
|
||||
].join(' ')}
|
||||
>
|
||||
<DialogHeader className="px-6 pt-6 pb-4 border-b">
|
||||
<DialogTitle className="flex items-center justify-between gap-3">
|
||||
<span>결과 코드 설정</span>
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{/* 상단 버튼 영역 */}
|
||||
<div className="px-6 pt-1 pb-3 border-b bg-white flex justify-end">
|
||||
{!importMode ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleImportClick}
|
||||
className="h-9 px-3 gap-2"
|
||||
>
|
||||
<Download className="w-4 h-4" />
|
||||
가져오기
|
||||
</Button>
|
||||
) : (
|
||||
<div className="flex items-center gap-2 w-130">
|
||||
<div className="relative flex-1">
|
||||
<Search className="w-4 h-4 text-gray-400 absolute left-3 top-1/2 -translate-y-1/2" />
|
||||
<Input
|
||||
value={projectSearch}
|
||||
onChange={(e) => setProjectSearch(e.target.value)}
|
||||
placeholder="프로젝트 코드/이름 검색..."
|
||||
className="h-9 pl-9"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 본문 */}
|
||||
<div className={importMode ? 'grid grid-cols-1 lg:grid-cols-2' : 'block'}>
|
||||
{/* 왼쪽: 결과 코드 */}
|
||||
<div className="p-6">
|
||||
<div className="rounded-lg border bg-white overflow-hidden">
|
||||
<div className="px-4 py-3 border-b bg-gray-50 flex items-center justify-between">
|
||||
<div className="font-semibold text-sm text-gray-900">결과 코드 목록</div>
|
||||
{!importMode && (
|
||||
<Button onClick={handleAddCode} variant="outline" size="sm" className="gap-2">
|
||||
<Plus className="w-4 h-4" />
|
||||
추가
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="max-h-[420px] overflow-y-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white border-b">
|
||||
<tr className="text-gray-600">
|
||||
<th className="px-4 py-2 text-left w-36">코드</th>
|
||||
<th className="px-4 py-2 text-left">레이블</th>
|
||||
<th className="px-2 py-2 w-12" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y">
|
||||
{resultCodes.map((code, index) => (
|
||||
<tr key={index} className="hover:bg-gray-50">
|
||||
<td className="px-4 py-2 align-middle">
|
||||
<Input
|
||||
value={code.code}
|
||||
onChange={(e) => handleCodeChange(index, 'code', e.target.value)}
|
||||
className="h-9"
|
||||
disabled={importMode}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-4 py-2 align-middle">
|
||||
<Input
|
||||
value={code.label}
|
||||
onChange={(e) => handleCodeChange(index, 'label', e.target.value)}
|
||||
className="h-9"
|
||||
disabled={importMode}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-2 py-2 align-middle">
|
||||
{!importMode && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => handleDeleteCode(index)}
|
||||
aria-label="delete"
|
||||
>
|
||||
<Trash2 className="w-4 h-4 text-red-600" />
|
||||
</Button>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{!importMode && (
|
||||
<div className="px-4 py-3 border-t bg-gray-50 text-xs text-gray-500">
|
||||
Tip: 코드 값은 중복되지 않게 유지해주세요.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 오른쪽: importMode일 때만 */}
|
||||
{importMode && (
|
||||
<div className="p-6 border-t lg:border-t-0 lg:border-l bg-white">
|
||||
{/* 미리보기 */}
|
||||
<div className="rounded-lg border bg-white overflow-hidden">
|
||||
<div className="px-4 py-3 border-b bg-gray-50 flex items-center justify-between">
|
||||
<div className="font-semibold text-sm text-gray-900">미리보기</div>
|
||||
</div>
|
||||
|
||||
<div className="max-h-[180px] overflow-y-auto">
|
||||
{selectedProjectData ? (
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white border-b">
|
||||
<tr className="text-gray-600">
|
||||
<th className="px-4 py-2 text-left w-32">코드</th>
|
||||
<th className="px-4 py-2 text-left">레이블</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y">
|
||||
{selectedProjectData.resultCodes.map((code, idx) => (
|
||||
<tr key={idx}>
|
||||
<td className="px-4 py-2">{code.code}</td>
|
||||
<td className="px-4 py-2">{code.label}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
) : (
|
||||
<div className="p-4 text-sm text-gray-500">프로젝트를 선택하세요.</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<DialogFooter className="px-6 py-4 border-t bg-white">
|
||||
{importMode ? (
|
||||
<>
|
||||
<Button variant="outline" onClick={handleImportCancel}>
|
||||
취소
|
||||
</Button>
|
||||
<Button onClick={handleImportApply} disabled={!selectedProject} className="gap-2">
|
||||
<Download className="w-4 h-4" />
|
||||
가져오기 적용
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Button variant="outline" onClick={handleClose}>
|
||||
취소
|
||||
</Button>
|
||||
<Button onClick={handleSave}>
|
||||
저장
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default ResultCodeDialog
|
||||
Reference in New Issue
Block a user