refactor: update table component types and enhance admin menu with category and tag

This commit is contained in:
Ardeman
2025-03-09 15:31:10 +08:00
parent 422c9cbfe2
commit 64bb369c59
6 changed files with 62 additions and 42 deletions
+11 -10
View File
@@ -1,5 +1,5 @@
import DT from 'datatables.net-dt'
import DataTable from 'datatables.net-react'
import DT, { type Config, type ConfigColumns } from 'datatables.net-dt'
import DataTable, { type DataTableSlots } from 'datatables.net-react'
import { Link, useRouteLoaderData } from 'react-router'
import type { TCategoryResponse } from '~/apis/common/get-categories'
@@ -13,12 +13,13 @@ export const CategoriesPage = () => {
)
DataTable.use(DT)
const dataTable = loaderData?.categoriesData?.sort((a, b) => {
if (a.sequence === null) return 1
if (b.sequence === null) return -1
return a.sequence - b.sequence
})
const dataColumns = [
const dataTable =
loaderData?.categoriesData?.sort((a, b) => {
if (a.sequence === null) return 1
if (b.sequence === null) return -1
return a.sequence - b.sequence
}) || []
const dataColumns: ConfigColumns[] = [
{
title: 'No',
render: (
@@ -46,7 +47,7 @@ export const CategoriesPage = () => {
data: 'id',
},
]
const dataSlot = {
const dataSlot: DataTableSlots = {
1: (_value: unknown, _type: unknown, data: TCategoryResponse) => (
<div>
<div>{data.name}</div>
@@ -64,7 +65,7 @@ export const CategoriesPage = () => {
</Button>
),
}
const dataOptions = {
const dataOptions: Config = {
paging: true,
searching: true,
ordering: true,