From 2acf5f8966a40c1c9a97680c8dc263ee3f1ad3d1 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 2 Jul 2025 00:45:49 +0000 Subject: (대표님/최겸) 20250702 변경사항 업데이트 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/qna/table/qna-table-toolbar-actions.tsx | 176 ++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 lib/qna/table/qna-table-toolbar-actions.tsx (limited to 'lib/qna/table/qna-table-toolbar-actions.tsx') diff --git a/lib/qna/table/qna-table-toolbar-actions.tsx b/lib/qna/table/qna-table-toolbar-actions.tsx new file mode 100644 index 00000000..d3e8623e --- /dev/null +++ b/lib/qna/table/qna-table-toolbar-actions.tsx @@ -0,0 +1,176 @@ +"use client" + +import * as React from "react" +import { type Table } from "@tanstack/react-table" +import { Download, Plus, RefreshCw, FileSpreadsheet, FileText, Users } from "lucide-react" +import { toast } from "sonner" + +import { Button } from "@/components/ui/button" +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu" +import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip" + +import { QnaViewSelect } from "@/db/schema" +import { exportQnaData } from "./qna-export-actions" + +interface QnaTableToolbarActionsProps { + table: Table + domain: string + onCreateClick: () => void +} + +export function QnaTableToolbarActions({ + table, + domain, + onCreateClick +}: QnaTableToolbarActionsProps) { + const [isExporting, setIsExporting] = React.useState(false) + const [isRefreshing, setIsRefreshing] = React.useState(false) + + // 선택된 행들 + const selectedRows = table.getFilteredSelectedRowModel().rows + const selectedCount = selectedRows.length + + // 새로고침 + const handleRefresh = async () => { + setIsRefreshing(true) + try { + // 페이지 새로고침 또는 데이터 재요청 + window.location.reload() + } catch (error) { + toast.error("새로고침 중 오류가 발생했습니다.") + } finally { + setIsRefreshing(false) + } + } + + // 데이터 내보내기 + const handleExport = async (format: "csv" | "excel") => { + setIsExporting(true) + try { + const selectedData = selectedCount > 0 + ? selectedRows.map(row => row.original) + : table.getFilteredRowModel().rows.map(row => row.original) + + const result = await exportQnaData({ + format, + data: selectedData, + fields: [ + "title", + "authorName", + "companyName", + "totalAnswers", + "totalComments", + "createdAt", + "lastActivityAt" + ] + }) + + if (result.success) { + toast.success(`${format.toUpperCase()} 파일이 다운로드되었습니다.`) + } else { + toast.error(result.error || "내보내기에 실패했습니다.") + } + } catch (error) { + toast.error("내보내기 중 오류가 발생했습니다.") + console.error("Export error:", error) + } finally { + setIsExporting(false) + } + } + + return ( +
+ {/* 선택된 항목 수 표시 */} + {selectedCount > 0 && ( +
+ + {selectedCount}개 선택됨 +
+ )} + + {/* 새 질문 작성 버튼 */} + {domain === "partners" && + + + + + 새로운 질문을 작성합니다 + +} + + {/* 내보내기 드롭다운 */} + + + + + + handleExport("csv")} + disabled={isExporting} + > + + CSV 파일로 내보내기 + + handleExport("excel")} + disabled={isExporting} + > + + Excel 파일로 내보내기 + + + { + const rowCount = selectedCount > 0 ? selectedCount : table.getFilteredRowModel().rows.length + toast.info(`${rowCount}개의 질문이 내보내집니다.`) + }} + disabled={isExporting} + className="text-xs text-muted-foreground" + > + {selectedCount > 0 + ? `선택된 ${selectedCount}개 항목` + : `전체 ${table.getFilteredRowModel().rows.length}개 항목` + } + + + + + {/* 새로고침 버튼 */} + + + + + 목록 새로고침 + +
+ ) +} \ No newline at end of file -- cgit v1.2.3