refactor: useDataTable 적용

This commit is contained in:
2025-06-18 17:00:18 +09:00
parent 6d6892973f
commit 3b7f8bcca7
34 changed files with 718 additions and 709 deletions
@@ -1,13 +1,8 @@
import { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import {
getCoreRowModel,
useReactTable,
type RowSelectionState,
} from "@tanstack/react-table";
import { getCoreRowModel, type RowSelectionState } from "@tanstack/react-table";
import {
Button,
DataTable,
Dialog,
DialogTrigger,
DialogContent,
@@ -16,6 +11,7 @@ import {
Input,
} from "@common/components";
import { ENDPOINT } from "@/shared/config";
import { useDataTable } from "@/shared/lib";
import { BoardApi, type BoardPopup } from "@/entities/board";
import { columns } from "../model/board-table-columns";
@@ -30,21 +26,23 @@ function BoardSearchDialog({
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
const [bbsNm, setBbsNm] = useState("");
const { data: boardList, refetch } = useQuery({
const query = useQuery({
queryKey: [ENDPOINT.BOARD_SERVICE.BBS],
queryFn: () => BoardApi.getBoardPopupList({ bbsNm }),
enabled: false,
});
const table = useReactTable({
data: boardList?.content ?? [],
columns,
state: {
rowSelection,
const { tableComponent, tableInstance: table } = useDataTable({
query,
tableOptions: {
columns,
state: {
rowSelection,
},
enableMultiRowSelection: false,
getCoreRowModel: getCoreRowModel(),
onRowSelectionChange: setRowSelection,
},
enableMultiRowSelection: false,
getCoreRowModel: getCoreRowModel(),
onRowSelectionChange: setRowSelection,
});
useEffect(() => {
@@ -55,7 +53,7 @@ function BoardSearchDialog({
}, [table.getSelectedRowModel().rows]);
useEffect(() => {
refetch();
query.refetch();
}, []);
return (
@@ -78,13 +76,13 @@ function BoardSearchDialog({
value={bbsNm}
onChange={(e) => setBbsNm(e.target.value)}
/>
<Button onClick={() => refetch()}>
<Button onClick={() => query.refetch()}>
<i className="diveicon di-search" />
조회
</Button>
</div>
<div className="h-[40rem] w-full overflow-y-auto">
<DataTable table={table} />
{tableComponent}
</div>
</div>
</DialogContent>
@@ -1,13 +1,8 @@
import { useEffect, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import {
getCoreRowModel,
useReactTable,
type RowSelectionState,
} from "@tanstack/react-table";
import { getCoreRowModel, type RowSelectionState } from "@tanstack/react-table";
import {
Button,
DataTable,
Dialog,
DialogTrigger,
DialogContent,
@@ -16,6 +11,7 @@ import {
Input,
} from "@common/components";
import { ENDPOINT } from "@/shared/config";
import { useDataTable } from "@/shared/lib";
import { ContentsApi, type Contents } from "@/entities/content";
import { columns } from "../model/contents-table-colums";
@@ -30,21 +26,23 @@ function ContentSearchDialog({
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
const [contsTtl, setContsTtl] = useState("");
const { data: contentList, refetch } = useQuery({
const query = useQuery({
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS],
queryFn: () => ContentsApi.getContentsList({ contsTtl }),
enabled: false,
});
const table = useReactTable({
data: contentList?.content ?? [],
columns,
state: {
rowSelection,
const { tableComponent, tableInstance: table } = useDataTable({
query,
tableOptions: {
columns,
state: {
rowSelection,
},
enableMultiRowSelection: false,
getCoreRowModel: getCoreRowModel(),
onRowSelectionChange: setRowSelection,
},
enableMultiRowSelection: false,
getCoreRowModel: getCoreRowModel(),
onRowSelectionChange: setRowSelection,
});
useEffect(() => {
@@ -55,7 +53,7 @@ function ContentSearchDialog({
}, [table.getSelectedRowModel().rows]);
useEffect(() => {
refetch();
query.refetch();
}, []);
return (
@@ -78,13 +76,13 @@ function ContentSearchDialog({
value={contsTtl}
onChange={(e) => setContsTtl(e.target.value)}
/>
<Button onClick={() => refetch()}>
<Button onClick={() => query.refetch()}>
<i className="diveicon di-search" />
조회
</Button>
</div>
<div className="h-[40rem] w-full overflow-y-auto">
<DataTable table={table} />
{tableComponent}
</div>
</div>
</DialogContent>