diff options
Diffstat (limited to 'lib/evaluation-target-list/table/evaluation-targets-toolbar-actions.tsx')
| -rw-r--r-- | lib/evaluation-target-list/table/evaluation-targets-toolbar-actions.tsx | 138 |
1 files changed, 47 insertions, 91 deletions
diff --git a/lib/evaluation-target-list/table/evaluation-targets-toolbar-actions.tsx b/lib/evaluation-target-list/table/evaluation-targets-toolbar-actions.tsx index 3fb47771..9043c588 100644 --- a/lib/evaluation-target-list/table/evaluation-targets-toolbar-actions.tsx +++ b/lib/evaluation-target-list/table/evaluation-targets-toolbar-actions.tsx @@ -24,7 +24,13 @@ import { 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<EvaluationTargetWithDepartments> @@ -37,6 +43,9 @@ export function EvaluationTargetsTableToolbarActions({ }: 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() // 선택된 행들 @@ -91,84 +100,12 @@ export function EvaluationTargetsTableToolbarActions({ } // ---------------------------------------------------------------- - // 선택된 항목들 확정 + // 다이얼로그 성공 핸들러 // ---------------------------------------------------------------- - const handleConfirmSelected = async () => { - if (!hasSelection || !selectedStats.canConfirm) return - - setIsLoading(true) - try { - // TODO: 확정 API 호출 - const confirmableTargets = selectedTargets.filter( - t => t.status === "PENDING" && t.consensusStatus === true - ) - - toast.success(`${confirmableTargets.length}개 항목이 확정되었습니다.`) - table.resetRowSelection() - router.refresh() - } catch (error) { - console.error('Error confirming targets:', error) - toast.error("확정 처리 중 오류가 발생했습니다.") - } finally { - setIsLoading(false) - } - } - - // ---------------------------------------------------------------- - // 선택된 항목들 제외 - // ---------------------------------------------------------------- - const handleExcludeSelected = async () => { - if (!hasSelection || !selectedStats.canExclude) return - - setIsLoading(true) - try { - // TODO: 제외 API 호출 - const excludableTargets = selectedTargets.filter(t => t.status === "PENDING") - - toast.success(`${excludableTargets.length}개 항목이 제외되었습니다.`) - table.resetRowSelection() - router.refresh() - } catch (error) { - console.error('Error excluding targets:', error) - toast.error("제외 처리 중 오류가 발생했습니다.") - } finally { - setIsLoading(false) - } - } - - // ---------------------------------------------------------------- - // 선택된 항목들 의견 요청 - // ---------------------------------------------------------------- - const handleRequestReview = async () => { - if (!hasSelection || !selectedStats.canRequestReview) return - - // TODO: 의견 요청 다이얼로그 열기 - toast.info("의견 요청 다이얼로그를 구현해주세요.") - } - - // ---------------------------------------------------------------- - // Excel 내보내기 - // ---------------------------------------------------------------- - const handleExport = () => { - try { - // TODO: Excel 내보내기 구현 - toast.success("Excel 파일이 다운로드되었습니다.") - } catch (error) { - console.error('Error exporting to Excel:', error) - toast.error("Excel 내보내기 중 오류가 발생했습니다.") - } - } - - // ---------------------------------------------------------------- - // 새로고침 - // ---------------------------------------------------------------- - const handleRefresh = () => { - if (onRefresh) { - onRefresh() - } else { - router.refresh() - } - toast.success("데이터가 새로고침되었습니다.") + const handleActionSuccess = () => { + table.resetRowSelection() + onRefresh?.() + router.refresh() } return ( @@ -204,22 +141,17 @@ export function EvaluationTargetsTableToolbarActions({ <Button variant="outline" size="sm" - onClick={handleExport} + onClick={() => + exportTableToExcel(table, { + filename: "vendor-target-list", + excludeColumns: ["select", "actions"], + }) + } className="gap-2" > <Download className="size-4" aria-hidden="true" /> <span className="hidden sm:inline">내보내기</span> </Button> - - <Button - variant="outline" - size="sm" - onClick={handleRefresh} - className="gap-2" - > - <RefreshCw className="size-4" aria-hidden="true" /> - <span className="hidden sm:inline">새로고침</span> - </Button> </div> {/* 선택된 항목 액션 버튼들 */} @@ -231,7 +163,7 @@ export function EvaluationTargetsTableToolbarActions({ variant="default" size="sm" className="gap-2 bg-green-600 hover:bg-green-700" - onClick={handleConfirmSelected} + onClick={() => setConfirmDialogOpen(true)} disabled={isLoading} > <Check className="size-4" aria-hidden="true" /> @@ -247,7 +179,7 @@ export function EvaluationTargetsTableToolbarActions({ variant="destructive" size="sm" className="gap-2" - onClick={handleExcludeSelected} + onClick={() => setExcludeDialogOpen(true)} disabled={isLoading} > <X className="size-4" aria-hidden="true" /> @@ -263,7 +195,7 @@ export function EvaluationTargetsTableToolbarActions({ variant="outline" size="sm" className="gap-2" - onClick={handleRequestReview} + onClick={() => setReviewDialogOpen(true)} disabled={isLoading} > <MessageSquare className="size-4" aria-hidden="true" /> @@ -282,6 +214,30 @@ export function EvaluationTargetsTableToolbarActions({ onOpenChange={setManualCreateDialogOpen} /> + {/* 확정 컨펌 다이얼로그 */} + <ConfirmTargetsDialog + open={confirmDialogOpen} + onOpenChange={setConfirmDialogOpen} + targets={selectedTargets} + onSuccess={handleActionSuccess} + /> + + {/* 제외 컨펌 다이얼로그 */} + <ExcludeTargetsDialog + open={excludeDialogOpen} + onOpenChange={setExcludeDialogOpen} + targets={selectedTargets} + onSuccess={handleActionSuccess} + /> + + {/* 의견 요청 다이얼로그 */} + <RequestReviewDialog + open={reviewDialogOpen} + onOpenChange={setReviewDialogOpen} + targets={selectedTargets} + onSuccess={handleActionSuccess} + /> + {/* 선택 정보 표시 */} {hasSelection && ( <div className="text-xs text-muted-foreground"> |
