refactor: update table component types and enhance admin menu with category and tag
This commit is contained in:
parent
422c9cbfe2
commit
64bb369c59
@ -1,11 +1,11 @@
|
|||||||
import DT, { type Config, type ConfigColumns } from 'datatables.net-dt'
|
import DT, { type Config, type ConfigColumns } from 'datatables.net-dt'
|
||||||
import DataTable from 'datatables.net-react'
|
import DataTable, { type DataTableSlots } from 'datatables.net-react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
type UiTableProperties = {
|
type UiTableProperties = {
|
||||||
data: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
data: any[] // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||||
columns: ConfigColumns[]
|
columns: ConfigColumns[]
|
||||||
slots?: any // eslint-disable-line @typescript-eslint/no-explicit-any
|
slots?: DataTableSlots
|
||||||
options?: Config
|
options?: Config
|
||||||
title: string
|
title: string
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,4 +72,20 @@ export const SUB_MENU = [
|
|||||||
title: 'Update Artikel',
|
title: 'Update Artikel',
|
||||||
path: '/lg-admin/contents/update',
|
path: '/lg-admin/contents/update',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'Buat Kategori',
|
||||||
|
path: '/lg-admin/categories/create',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Update Kategori',
|
||||||
|
path: '/lg-admin/categories/update',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Buat Tag',
|
||||||
|
path: '/lg-admin/tags/create',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Update Tag',
|
||||||
|
path: '/lg-admin/tags/update',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import { Field, Input, Label, Select } from '@headlessui/react'
|
import { Field, Input, Label, Select } from '@headlessui/react'
|
||||||
import { MagnifyingGlassIcon } from '@heroicons/react/20/solid'
|
import { MagnifyingGlassIcon } from '@heroicons/react/20/solid'
|
||||||
|
import type { ConfigColumns } from 'datatables.net-dt'
|
||||||
|
import type { DataTableSlots } from 'datatables.net-react'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
|
|
||||||
@ -36,14 +38,14 @@ export const AdvertisementsPage = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dataBanner = BANNER
|
const dataBanner = BANNER
|
||||||
const dataColumns = [
|
const dataColumns: ConfigColumns[] = [
|
||||||
{ title: 'No', data: 'id' },
|
{ title: 'No', data: 'id' },
|
||||||
{ title: 'Banner', data: 'urlImage' },
|
{ title: 'Banner', data: 'urlImage' },
|
||||||
{ title: 'Link', data: 'link' },
|
{ title: 'Link', data: 'link' },
|
||||||
{ title: 'Tgl Create', data: 'createdAt' },
|
{ title: 'Tgl Create', data: 'createdAt' },
|
||||||
{ title: 'Status', data: 'status' },
|
{ title: 'Status', data: 'status' },
|
||||||
]
|
]
|
||||||
const dataSlot = {
|
const dataSlot: DataTableSlots = {
|
||||||
1: (value: string) => {
|
1: (value: string) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import DT from 'datatables.net-dt'
|
import DT, { type Config, type ConfigColumns } from 'datatables.net-dt'
|
||||||
import DataTable from 'datatables.net-react'
|
import DataTable, { type DataTableSlots } from 'datatables.net-react'
|
||||||
import { Link, useRouteLoaderData } from 'react-router'
|
import { Link, useRouteLoaderData } from 'react-router'
|
||||||
|
|
||||||
import type { TCategoryResponse } from '~/apis/common/get-categories'
|
import type { TCategoryResponse } from '~/apis/common/get-categories'
|
||||||
@ -13,12 +13,13 @@ export const CategoriesPage = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
DataTable.use(DT)
|
DataTable.use(DT)
|
||||||
const dataTable = loaderData?.categoriesData?.sort((a, b) => {
|
const dataTable =
|
||||||
|
loaderData?.categoriesData?.sort((a, b) => {
|
||||||
if (a.sequence === null) return 1
|
if (a.sequence === null) return 1
|
||||||
if (b.sequence === null) return -1
|
if (b.sequence === null) return -1
|
||||||
return a.sequence - b.sequence
|
return a.sequence - b.sequence
|
||||||
})
|
}) || []
|
||||||
const dataColumns = [
|
const dataColumns: ConfigColumns[] = [
|
||||||
{
|
{
|
||||||
title: 'No',
|
title: 'No',
|
||||||
render: (
|
render: (
|
||||||
@ -46,7 +47,7 @@ export const CategoriesPage = () => {
|
|||||||
data: 'id',
|
data: 'id',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
const dataSlot = {
|
const dataSlot: DataTableSlots = {
|
||||||
1: (_value: unknown, _type: unknown, data: TCategoryResponse) => (
|
1: (_value: unknown, _type: unknown, data: TCategoryResponse) => (
|
||||||
<div>
|
<div>
|
||||||
<div>{data.name}</div>
|
<div>{data.name}</div>
|
||||||
@ -64,7 +65,7 @@ export const CategoriesPage = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
const dataOptions = {
|
const dataOptions: Config = {
|
||||||
paging: true,
|
paging: true,
|
||||||
searching: true,
|
searching: true,
|
||||||
ordering: true,
|
ordering: true,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import DT from 'datatables.net-dt'
|
import DT, { type Config, type ConfigColumns } from 'datatables.net-dt'
|
||||||
import DataTable from 'datatables.net-react'
|
import DataTable, { type DataTableSlots } from 'datatables.net-react'
|
||||||
import { Link, useRouteLoaderData } from 'react-router'
|
import { Link, useRouteLoaderData } from 'react-router'
|
||||||
|
|
||||||
import type { TCategoryResponse } from '~/apis/common/get-categories'
|
import type { TCategoryResponse } from '~/apis/common/get-categories'
|
||||||
@ -17,16 +17,17 @@ export const ContentsPage = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
DataTable.use(DT)
|
DataTable.use(DT)
|
||||||
const dataTable = loaderData?.newsData?.sort(
|
const dataTable =
|
||||||
|
loaderData?.newsData?.sort(
|
||||||
(a, b) => new Date(b.live_at).getTime() - new Date(a.live_at).getTime(),
|
(a, b) => new Date(b.live_at).getTime() - new Date(a.live_at).getTime(),
|
||||||
)
|
) || []
|
||||||
const dataColumns = [
|
const dataColumns: ConfigColumns[] = [
|
||||||
{
|
{
|
||||||
title: 'No',
|
title: 'No',
|
||||||
render: (
|
render: (
|
||||||
data: unknown,
|
_data: unknown,
|
||||||
type: unknown,
|
_type: unknown,
|
||||||
row: unknown,
|
_row: unknown,
|
||||||
meta: { row: number },
|
meta: { row: number },
|
||||||
) => {
|
) => {
|
||||||
return meta.row + 1
|
return meta.row + 1
|
||||||
@ -54,7 +55,7 @@ export const ContentsPage = () => {
|
|||||||
data: 'slug',
|
data: 'slug',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
const dataSlot = {
|
const dataSlot: DataTableSlots = {
|
||||||
1: (value: string) => formatDate(value),
|
1: (value: string) => formatDate(value),
|
||||||
2: (_value: unknown, _type: unknown, data: TNewsResponse) => (
|
2: (_value: unknown, _type: unknown, data: TNewsResponse) => (
|
||||||
<div>
|
<div>
|
||||||
@ -62,6 +63,7 @@ export const ContentsPage = () => {
|
|||||||
<div className="text-sm text-[#7C7C7C]">ID: {data.id.slice(0, 8)}</div>
|
<div className="text-sm text-[#7C7C7C]">ID: {data.id.slice(0, 8)}</div>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
|
3: (value: string) => <span className="text-sm">{value}</span>,
|
||||||
4: (value: TCategoryResponse[]) => (
|
4: (value: TCategoryResponse[]) => (
|
||||||
<div className="text-xs">{value.map((item) => item.name).join(', ')}</div>
|
<div className="text-xs">{value.map((item) => item.name).join(', ')}</div>
|
||||||
),
|
),
|
||||||
@ -89,7 +91,7 @@ export const ContentsPage = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
const dataOptions = {
|
const dataOptions: Config = {
|
||||||
paging: true,
|
paging: true,
|
||||||
searching: true,
|
searching: true,
|
||||||
ordering: true,
|
ordering: true,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import DT from 'datatables.net-dt'
|
import DT, { type Config, type ConfigColumns } from 'datatables.net-dt'
|
||||||
import DataTable from 'datatables.net-react'
|
import DataTable, { type DataTableSlots } from 'datatables.net-react'
|
||||||
import { Link, useRouteLoaderData } from 'react-router'
|
import { Link, useRouteLoaderData } from 'react-router'
|
||||||
|
|
||||||
import { Button } from '~/components/ui/button'
|
import { Button } from '~/components/ui/button'
|
||||||
@ -14,13 +14,13 @@ export const TagsPage = () => {
|
|||||||
const { tagsData: dataTable } = loaderData || {}
|
const { tagsData: dataTable } = loaderData || {}
|
||||||
|
|
||||||
DataTable.use(DT)
|
DataTable.use(DT)
|
||||||
const dataColumns = [
|
const dataColumns: ConfigColumns[] = [
|
||||||
{
|
{
|
||||||
title: 'No',
|
title: 'No',
|
||||||
render: (
|
render: (
|
||||||
data: unknown,
|
_data: unknown,
|
||||||
type: unknown,
|
_type: unknown,
|
||||||
row: unknown,
|
_row: unknown,
|
||||||
meta: { row: number },
|
meta: { row: number },
|
||||||
) => {
|
) => {
|
||||||
return meta.row + 1
|
return meta.row + 1
|
||||||
@ -39,15 +39,7 @@ export const TagsPage = () => {
|
|||||||
data: 'id',
|
data: 'id',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
const dataSlot: DataTableSlots = {
|
||||||
const dataOptions = {
|
|
||||||
paging: true,
|
|
||||||
searching: true,
|
|
||||||
ordering: true,
|
|
||||||
info: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
const dataSlot = {
|
|
||||||
3: (value: string) => (
|
3: (value: string) => (
|
||||||
<Button
|
<Button
|
||||||
as="a"
|
as="a"
|
||||||
@ -59,6 +51,13 @@ export const TagsPage = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
const dataOptions: Config = {
|
||||||
|
paging: true,
|
||||||
|
searching: true,
|
||||||
|
ordering: true,
|
||||||
|
info: true,
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<TitleDashboard title="Tags" />
|
<TitleDashboard title="Tags" />
|
||||||
@ -75,7 +74,7 @@ export const TagsPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<UiTable
|
<UiTable
|
||||||
data={dataTable}
|
data={dataTable || []}
|
||||||
columns={dataColumns}
|
columns={dataColumns}
|
||||||
options={dataOptions}
|
options={dataOptions}
|
||||||
slots={dataSlot}
|
slots={dataSlot}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user