260427_01_ENH: 리스트 다이얼로그 및 리스트 작업 시작
This commit is contained in:
96
src/components/dialog/ListDownloadDialog.tsx
Normal file
96
src/components/dialog/ListDownloadDialog.tsx
Normal file
@@ -0,0 +1,96 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { Download } from 'lucide-react'
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import type { DialogId } from '@/store/jotai/dialog'
|
||||
|
||||
export type ListDownloadMode = 'list' | 'contact-history' | 'list-change-history' | 'upload-file'
|
||||
|
||||
export type ListDownloadDialogProps = {
|
||||
dialogId?: DialogId
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
mode: ListDownloadMode
|
||||
onDownload: (payload: { mode: ListDownloadMode; onlyFiltered: boolean }) => void | Promise<void>
|
||||
}
|
||||
|
||||
const titleMap: Record<ListDownloadMode, string> = {
|
||||
list: '리스트 다운로드',
|
||||
'contact-history': '컨택 이력 다운로드',
|
||||
'list-change-history': '리스트 수정 이력 다운로드',
|
||||
'upload-file': '업로드 파일 다운로드',
|
||||
}
|
||||
|
||||
const ListDownloadDialog = ({
|
||||
dialogId = 'listDownloadDialog',
|
||||
open,
|
||||
onOpenChange,
|
||||
mode,
|
||||
onDownload,
|
||||
}: ListDownloadDialogProps) => {
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog()
|
||||
const [scope, setScope] = useState<'filtered' | 'all'>('filtered')
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId)
|
||||
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
onOpenChange?.(nextOpen)
|
||||
if (nextOpen) {
|
||||
showDialog(dialogId)
|
||||
return
|
||||
}
|
||||
hideDialog(dialogId)
|
||||
}
|
||||
|
||||
const handleDownload = async () => {
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await onDownload({ mode, onlyFiltered: scope === 'filtered' })
|
||||
handleOpenChange(false)
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={resolvedOpen} onOpenChange={handleOpenChange}>
|
||||
<DialogContent className="sm:max-w-[560px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="content-text-2xl font-bold">{titleMap[mode]}</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="rounded-md border p-4 space-y-4">
|
||||
<p className="content-text-lg font-semibold">다운로드 범위</p>
|
||||
<RadioGroup value={scope} onValueChange={(v) => setScope(v as 'filtered' | 'all')} className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<RadioGroupItem value="filtered" id="download-scope-filtered" />
|
||||
<Label htmlFor="download-scope-filtered">필터 적용 대상만</Label>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<RadioGroupItem value="all" id="download-scope-all" />
|
||||
<Label htmlFor="download-scope-all">전체 대상</Label>
|
||||
</div>
|
||||
</RadioGroup>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" onClick={() => handleOpenChange(false)} disabled={submitting}>
|
||||
취소
|
||||
</Button>
|
||||
<Button type="button" onClick={handleDownload} disabled={submitting} className="gap-2">
|
||||
<Download className="w-4 h-4" />
|
||||
다운로드
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default ListDownloadDialog
|
||||
Reference in New Issue
Block a user