"use client" import * as React from "react" import { type Table } from "@tanstack/react-table" import { Plus, Check, MessageSquare, X, Download, Upload, RefreshCw, Settings } from "lucide-react" import { toast } from "sonner" import { useRouter } from "next/navigation" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { ManualCreateEvaluationTargetDialog } from "./manual-create-evaluation-target-dialog" import { ConfirmTargetsDialog, ExcludeTargetsDialog, RequestReviewDialog } from "./evaluation-target-action-dialogs" import { EvaluationTargetWithDepartments } from "@/db/schema" import { exportTableToExcel } from "@/lib/export" interface EvaluationTargetsTableToolbarActionsProps { table: Table onRefresh?: () => void } export function EvaluationTargetsTableToolbarActions({ table, onRefresh }: EvaluationTargetsTableToolbarActionsProps) { const [isLoading, setIsLoading] = React.useState(false) const [manualCreateDialogOpen, setManualCreateDialogOpen] = React.useState(false) const [confirmDialogOpen, setConfirmDialogOpen] = React.useState(false) const [excludeDialogOpen, setExcludeDialogOpen] = React.useState(false) const [reviewDialogOpen, setReviewDialogOpen] = React.useState(false) const router = useRouter() // 선택된 행들 const selectedRows = table.getFilteredSelectedRowModel().rows const hasSelection = selectedRows.length > 0 const selectedTargets = selectedRows.map(row => row.original) // 선택된 항목들의 상태 분석 const selectedStats = React.useMemo(() => { const pending = selectedTargets.filter(t => t.status === "PENDING").length const confirmed = selectedTargets.filter(t => t.status === "CONFIRMED").length const excluded = selectedTargets.filter(t => t.status === "EXCLUDED").length const consensusTrue = selectedTargets.filter(t => t.consensusStatus === true).length const consensusFalse = selectedTargets.filter(t => t.consensusStatus === false).length const consensusNull = selectedTargets.filter(t => t.consensusStatus === null).length return { pending, confirmed, excluded, consensusTrue, consensusFalse, consensusNull, canConfirm: pending > 0 && consensusTrue > 0, canExclude: pending > 0, canRequestReview: pending > 0 } }, [selectedTargets]) // ---------------------------------------------------------------- // 신규 평가 대상 생성 (자동) // ---------------------------------------------------------------- const handleAutoGenerate = async () => { setIsLoading(true) try { // TODO: 발주실적에서 자동 추출 API 호출 toast.success("평가 대상이 자동으로 생성되었습니다.") router.refresh() } catch (error) { console.error('Error auto generating targets:', error) toast.error("자동 생성 중 오류가 발생했습니다.") } finally { setIsLoading(false) } } // ---------------------------------------------------------------- // 신규 평가 대상 생성 (수동) // ---------------------------------------------------------------- const handleManualCreate = () => { setManualCreateDialogOpen(true) } // ---------------------------------------------------------------- // 다이얼로그 성공 핸들러 // ---------------------------------------------------------------- const handleActionSuccess = () => { table.resetRowSelection() onRefresh?.() router.refresh() } return ( <>
{/* 신규 생성 드롭다운 */} 자동 생성 (발주실적 기반) 수동 생성 {/* 유틸리티 버튼들 */}
{/* 선택된 항목 액션 버튼들 */} {hasSelection && (
{/* 확정 버튼 */} {selectedStats.canConfirm && ( )} {/* 제외 버튼 */} {selectedStats.canExclude && ( )} {/* 의견 요청 버튼 */} {selectedStats.canRequestReview && ( )}
)}
{/* 수동 생성 다이얼로그 */} {/* 확정 컨펌 다이얼로그 */} {/* 제외 컨펌 다이얼로그 */} {/* 의견 요청 다이얼로그 */} {/* 선택 정보 표시 */} {/* {hasSelection && (
선택된 {selectedRows.length}개 항목: 대기중 {selectedStats.pending}개, 확정 {selectedStats.confirmed}개, 제외 {selectedStats.excluded}개 {selectedStats.consensusTrue > 0 && ` | 의견일치 ${selectedStats.consensusTrue}개`} {selectedStats.consensusFalse > 0 && ` | 의견불일치 ${selectedStats.consensusFalse}개`}
)} */} ) }