From b84621f9b2b7161a5ad4f0b194264e9df3e65dbf Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 8 Jul 2025 11:23:40 +0000
Subject: (대표님) 20250708 미반영분 커밋
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../table/periodic-evaluations-toolbar-actions.tsx | 96 +++++++++++++++-------
 1 file changed, 67 insertions(+), 29 deletions(-)

(limited to 'lib/evaluation/table/periodic-evaluations-toolbar-actions.tsx')

diff --git a/lib/evaluation/table/periodic-evaluations-toolbar-actions.tsx b/lib/evaluation/table/periodic-evaluations-toolbar-actions.tsx
index bb63a1fd..39a95cc7 100644
--- a/lib/evaluation/table/periodic-evaluations-toolbar-actions.tsx
+++ b/lib/evaluation/table/periodic-evaluations-toolbar-actions.tsx
@@ -29,6 +29,8 @@ import { PeriodicEvaluationView } from "@/db/schema"
 import { exportTableToExcel } from "@/lib/export"
 import { FinalizeEvaluationDialog } from "./periodic-evaluation-finalize-dialogs"
 
+import { useAuthRole } from "@/hooks/use-auth-role"
+
 interface PeriodicEvaluationsTableToolbarActionsProps {
   table: Table<PeriodicEvaluationView>
   onRefresh?: () => void
@@ -45,16 +47,20 @@ export function PeriodicEvaluationsTableToolbarActions({
   const [finalizeEvaluationDialogOpen, setFinalizeEvaluationDialogOpen] = React.useState(false)
   const router = useRouter()
 
+  // 권한 체크 (방법 1 또는 방법 2 중 선택)
+  const { hasRole, isLoading: roleLoading } = useAuthRole()
+  const canManageEvaluations = hasRole('정기평가')
+
   // 선택된 행들
   const selectedRows = table.getFilteredSelectedRowModel().rows
   const hasSelection = selectedRows.length > 0
 
-  // ✅ selectedEvaluations를 useMemo로 안정화 (VendorsTable 방식과 동일)
+  // ✅ selectedEvaluations를 useMemo로 안정화
   const selectedEvaluations = React.useMemo(() => {
     return selectedRows.map(row => row.original)
   }, [selectedRows])
 
-  // ✅ 각 상태별 평가들을 개별적으로 메모이제이션 (VendorsTable 방식과 동일)
+  // ✅ 각 상태별 평가들을 개별적으로 메모이제이션
   const pendingSubmissionEvaluations = React.useMemo(() => {
     return table
       .getFilteredSelectedRowModel()
@@ -132,7 +138,6 @@ export function PeriodicEvaluationsTableToolbarActions({
     selectedEvaluations.length
   ])
 
- 
   // ----------------------------------------------------------------
   // 다이얼로그 성공 핸들러
   // ----------------------------------------------------------------
@@ -152,6 +157,25 @@ export function PeriodicEvaluationsTableToolbarActions({
     })
   }, [table])
 
+  // 권한이 없거나 로딩 중인 경우 내보내기 버튼만 표시
+  if (roleLoading) {
+    return (
+      <div className="flex items-center gap-2">
+        <div className="flex items-center gap-1 border-l pl-2 ml-2">
+          <Button
+            variant="outline"
+            size="sm"
+            disabled
+            className="gap-2"
+          >
+            <Download className="size-4 animate-spin" aria-hidden="true" />
+            <span className="hidden sm:inline">로딩중...</span>
+          </Button>
+        </div>
+      </div>
+    )
+  }
+
   return (
     <>
       <div className="flex items-center gap-2">
@@ -169,8 +193,8 @@ export function PeriodicEvaluationsTableToolbarActions({
           </Button>
         </div>
 
-        {/* 선택된 항목 액션 버튼들 */}
-        {hasSelection && (
+        {/* 선택된 항목 액션 버튼들 - 정기평가 권한이 있는 경우만 표시 */}
+        {canManageEvaluations && hasSelection && (
           <div className="flex items-center gap-1 border-l pl-2 ml-2">
             {/* 협력업체 자료 요청 버튼 */}
             {selectedStats.canRequestDocuments && (
@@ -221,31 +245,45 @@ export function PeriodicEvaluationsTableToolbarActions({
             )}
           </div>
         )}
+
+        {/* 권한이 없는 경우 안내 메시지 (선택사항) */}
+        {!canManageEvaluations && hasSelection && (
+          <div className="flex items-center gap-1 border-l pl-2 ml-2">
+            <div className="text-xs text-muted-foreground px-2 py-1">
+              평가 관리 권한이 필요합니다
+            </div>
+          </div>
+        )}
       </div>
 
-      {/* 협력업체 자료 요청 다이얼로그 */}
-      <RequestDocumentsDialog
-        open={requestDocumentsDialogOpen}
-        onOpenChange={setRequestDocumentsDialogOpen}
-        evaluations={selectedEvaluations}
-        onSuccess={handleActionSuccess}
-      />
-
-      {/* 평가자 평가 요청 다이얼로그 */}
-      <RequestEvaluationDialog
-        open={requestEvaluationDialogOpen}
-        onOpenChange={setRequestEvaluationDialogOpen}
-        evaluations={selectedEvaluations}
-        onSuccess={handleActionSuccess}
-      />
-
-      {/* 평가 확정 다이얼로그 */}
-      <FinalizeEvaluationDialog
-        open={finalizeEvaluationDialogOpen}
-        onOpenChange={setFinalizeEvaluationDialogOpen}
-        evaluations={reviewCompletedEvaluations}
-        onSuccess={handleActionSuccess}
-      />
+      {/* 다이얼로그들 - 권한이 있는 경우만 렌더링 */}
+      {canManageEvaluations && (
+        <>
+          {/* 협력업체 자료 요청 다이얼로그 */}
+          <RequestDocumentsDialog
+            open={requestDocumentsDialogOpen}
+            onOpenChange={setRequestDocumentsDialogOpen}
+            evaluations={selectedEvaluations}
+            onSuccess={handleActionSuccess}
+          />
+
+          {/* 평가자 평가 요청 다이얼로그 */}
+          <RequestEvaluationDialog
+            open={requestEvaluationDialogOpen}
+            onOpenChange={setRequestEvaluationDialogOpen}
+            evaluations={selectedEvaluations}
+            onSuccess={handleActionSuccess}
+          />
+
+          {/* 평가 확정 다이얼로그 */}
+          <FinalizeEvaluationDialog
+            open={finalizeEvaluationDialogOpen}
+            onOpenChange={setFinalizeEvaluationDialogOpen}
+            evaluations={reviewCompletedEvaluations}
+            onSuccess={handleActionSuccess}
+          />
+        </>
+      )}
     </>
   )
-}
+}
\ No newline at end of file
-- 
cgit v1.2.3

