refactor: useDataTable 적용
This commit is contained in:
@@ -3,14 +3,11 @@
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
||||
import {
|
||||
getCoreRowModel,
|
||||
useReactTable,
|
||||
type PaginationState,
|
||||
} from "@tanstack/react-table";
|
||||
import { Button, DataTable, Input, Label } from "@common/components";
|
||||
import { getCoreRowModel, type PaginationState } from "@tanstack/react-table";
|
||||
import { Button, Input, Label } from "@common/components";
|
||||
import { CodeSelect } from "@/entities/code";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import { useDataTable } from "@/shared/lib";
|
||||
import { TemplateApi } from "../api/template-service";
|
||||
import { columns } from "../model/template-table-columns";
|
||||
import type { Template, TemplateParams } from "../model/template-interface";
|
||||
@@ -27,7 +24,7 @@ function TemplatePage() {
|
||||
pageSize: 5,
|
||||
});
|
||||
|
||||
const { data: templateList, refetch } = useQuery({
|
||||
const query = useQuery({
|
||||
queryKey: [ENDPOINT.CMS_SERVICE.TEMPLATE],
|
||||
queryFn: () =>
|
||||
TemplateApi.getTemplateList({
|
||||
@@ -41,27 +38,32 @@ function TemplatePage() {
|
||||
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
refetch();
|
||||
query.refetch();
|
||||
};
|
||||
|
||||
const handleRowClick = (row: Template) => {
|
||||
router.push(`/template/register/${row.tmpltSn}`);
|
||||
};
|
||||
|
||||
const table = useReactTable({
|
||||
data: templateList?.content ?? [],
|
||||
columns,
|
||||
rowCount: templateList?.totalElements ?? 0,
|
||||
state: {
|
||||
pagination,
|
||||
const { tableComponent } = useDataTable({
|
||||
query,
|
||||
tableOptions: {
|
||||
columns,
|
||||
state: {
|
||||
pagination,
|
||||
},
|
||||
onPaginationChange: setPagination,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
manualPagination: true,
|
||||
},
|
||||
dataTableOptions: {
|
||||
onRowClick: handleRowClick,
|
||||
viewPagination: true,
|
||||
},
|
||||
onPaginationChange: setPagination,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
manualPagination: true,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
refetch();
|
||||
query.refetch();
|
||||
}, [pagination]);
|
||||
|
||||
return (
|
||||
@@ -109,9 +111,7 @@ function TemplatePage() {
|
||||
등록
|
||||
</Button>
|
||||
</div>
|
||||
<div className="card !m-[1.2rem] !p-0">
|
||||
<DataTable table={table} onRowClick={handleRowClick} viewPagination />
|
||||
</div>
|
||||
<div className="card !m-[1.2rem] !p-0">{tableComponent}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user