From bcd462d6e60871b86008e072f4b914138fc5c328 Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Mon, 11 Aug 2025 09:34:40 +0000
Subject: (김준회) 리치텍스트에디터 (결재템플릿을 위한 공통컴포넌트),
 command-menu 에러 수정, 결재 템플릿 관리, 결재선 관리, ECC RFQ+PR Item 수신시
 비즈니스테이블(ProcurementRFQ) 데이터 적재, WSDL 오류 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../table/approval-template-table.tsx              | 135 +++++++++++++++++++++
 1 file changed, 135 insertions(+)
 create mode 100644 lib/approval-template/table/approval-template-table.tsx

(limited to 'lib/approval-template/table/approval-template-table.tsx')

diff --git a/lib/approval-template/table/approval-template-table.tsx b/lib/approval-template/table/approval-template-table.tsx
new file mode 100644
index 00000000..d7f0e478
--- /dev/null
+++ b/lib/approval-template/table/approval-template-table.tsx
@@ -0,0 +1,135 @@
+"use client";
+
+import * as React from 'react';
+import { useDataTable } from '@/hooks/use-data-table';
+import { DataTable } from '@/components/data-table/data-table';
+import { DataTableAdvancedToolbar } from '@/components/data-table/data-table-advanced-toolbar';
+import type {
+  DataTableAdvancedFilterField,
+  DataTableFilterField,
+  DataTableRowAction,
+} from '@/types/table';
+
+import { getColumns } from './approval-template-table-columns';
+import { getApprovalTemplateList } from '../service';
+import { type ApprovalTemplate } from '../service';
+import { ApprovalTemplateTableToolbarActions } from './approval-template-table-toolbar-actions';
+import { CreateApprovalTemplateSheet } from './create-approval-template-sheet';
+import { UpdateApprovalTemplateSheet } from './update-approval-template-sheet';
+import { DuplicateApprovalTemplateSheet } from './duplicate-approval-template-sheet';
+import { DeleteApprovalTemplateDialog } from './delete-approval-template-dialog';
+
+interface ApprovalTemplateTableProps {
+  promises: Promise<[
+    Awaited<ReturnType<typeof getApprovalTemplateList>>,
+  ]>;
+}
+
+export function ApprovalTemplateTable({ promises }: ApprovalTemplateTableProps) {
+  const [{ data, pageCount }] = React.use(promises);
+
+  const [rowAction, setRowAction] = 
+    React.useState<DataTableRowAction<ApprovalTemplate> | null>(null);
+
+  const [showCreateSheet, setShowCreateSheet] = React.useState(false);
+
+  const columns = React.useMemo(
+    () => getColumns({ setRowAction }),
+    [setRowAction]
+  );
+
+  // 기본 & 고급 필터 필드 (추후 확장 가능)
+  const filterFields: DataTableFilterField<ApprovalTemplate>[] = [];
+  const advancedFilterFields: DataTableAdvancedFilterField<ApprovalTemplate>[] = [
+    {
+      id: 'name',
+      label: '템플릿 이름',
+      type: 'text',
+    },
+    {
+      id: 'subject',
+      label: '제목',
+      type: 'text',
+    },
+    {
+      id: 'category',
+      label: '카테고리',
+      type: 'text',
+    },
+    {
+      id: 'createdAt',
+      label: '생성일',
+      type: 'date',
+    },
+    {
+      id: 'updatedAt',
+      label: '수정일',
+      type: 'date',
+    },
+  ];
+
+  const { table } = useDataTable({
+    data,
+    columns,
+    pageCount,
+    filterFields,
+    enablePinning: true,
+    enableAdvancedFilter: true,
+    initialState: {
+      sorting: [{ id: 'updatedAt', desc: true }],
+      columnPinning: { right: ['actions'] },
+    },
+    getRowId: (row) => String(row.id),
+    shallow: false,
+    clearOnDefault: true,
+  });
+
+  return (
+    <>
+      <DataTable table={table}>
+        <DataTableAdvancedToolbar
+          table={table}
+          filterFields={advancedFilterFields}
+          shallow={false}
+        >
+          <ApprovalTemplateTableToolbarActions
+            table={table}
+            onCreateTemplate={() => setShowCreateSheet(true)}
+          />
+        </DataTableAdvancedToolbar>
+      </DataTable>
+
+      {/* 새 템플릿 생성 Sheet */}
+      <CreateApprovalTemplateSheet
+        open={showCreateSheet}
+        onOpenChange={setShowCreateSheet}
+      />
+
+      {/* 템플릿 수정 Sheet */}
+      <UpdateApprovalTemplateSheet
+        open={rowAction?.type === "update"}
+        onOpenChange={() => setRowAction(null)}
+        template={rowAction?.type === "update" ? rowAction.row.original : null}
+      />
+
+      {/* 템플릿 복제 Sheet */}
+      <DuplicateApprovalTemplateSheet
+        open={rowAction?.type === "duplicate"}
+        onOpenChange={() => setRowAction(null)}
+        template={rowAction?.type === "duplicate" ? rowAction.row.original : null}
+      />
+
+      {/* 템플릿 삭제 Dialog */}
+      <DeleteApprovalTemplateDialog
+        open={rowAction?.type === "delete"}
+        onOpenChange={() => setRowAction(null)}
+        templates={rowAction?.type === "delete" ? [rowAction.row.original] : []}
+        showTrigger={false}
+        onSuccess={() => {
+          setRowAction(null)
+          // 테이블 새로고침은 server action에서 자동으로 처리됨
+        }}
+      />
+    </>
+  );
+} 
\ No newline at end of file
-- 
cgit v1.2.3

