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' import type { TNewsResponse } from '~/apis/common/get-news' import type { TTagResponse } from '~/apis/common/get-tags' import { Button } from '~/components/ui/button' import { UiTable } from '~/components/ui/table' import { TitleDashboard } from '~/components/ui/title-dashboard' import type { loader } from '~/routes/_admin.lg-admin._dashboard.contents._index' import { formatDate } from '~/utils/formatter' export const ContentsPage = () => { const loaderData = useRouteLoaderData( 'routes/_admin.lg-admin._dashboard.contents._index', ) DataTable.use(DT) const dataTable = loaderData?.newsData?.sort( (a, b) => new Date(b.live_at).getTime() - new Date(a.live_at).getTime(), ) || [] const dataColumns: ConfigColumns[] = [ { title: 'No', render: ( _data: unknown, _type: unknown, _row: unknown, meta: { row: number }, ) => { return meta.row + 1 }, }, { title: 'Tanggal Live', data: 'live_at', }, { title: 'Penulis', }, { title: 'Judul', data: 'title' }, { title: 'Kategori', data: 'categories', }, { title: 'Tag', data: 'tags' }, { title: 'Subscription', data: 'is_premium', }, { title: 'Action', data: 'slug', }, ] const dataSlot: DataTableSlots = { 1: (value: string) => formatDate(value), 2: (_value: unknown, _type: unknown, data: TNewsResponse) => (
{data.author.name}
ID: {data.id.slice(0, 8)}
), 3: (value: string) => {value}, 4: (value: TCategoryResponse[]) => (
{value.map((item) => item.name).join(', ')}
), 5: (value: TTagResponse[]) => (
{value.map((item) => item.name).join(', ')}
), 6: (value: string) => value ? (
Premium
) : (
Normal
), 7: (value: string) => ( ), } const dataOptions: Config = { paging: true, searching: true, ordering: true, info: true, } return (
{/* TODO: Filter */}
) }