import { PencilSquareIcon, PlusIcon, TrashIcon, } from '@heroicons/react/24/solid' import DT, { type Config, type ConfigColumns } from 'datatables.net-dt' import DataTable, { type DataTableSlots } from 'datatables.net-react' import { useState } from 'react' import { Link, useRouteLoaderData } from 'react-router' import type { TCategoryResponse } from '~/apis/common/get-categories' import type { TAuthorResponse, TNewsResponse } from '~/apis/common/get-news' import type { TTagResponse } from '~/apis/common/get-tags' import { DialogDelete } from '~/components/dialog/delete' 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, formatNumberWithPeriods } from '~/utils/formatter' export const ContentsPage = () => { const loaderData = useRouteLoaderData( 'routes/_admin.lg-admin._dashboard.contents._index', ) const [selectedContent, setSelectedContent] = useState() 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: 'Mulai Tayang', data: 'live_at', }, { title: 'Penulis', data: 'author', }, { title: 'Judul', data: 'title' }, { title: 'Kategori', data: 'categories', }, { title: 'Tag', data: 'tags' }, { title: 'Tipe Langganan', data: 'is_premium', }, { title: 'Jumlah Penayangan', data: 'views', }, { title: 'Tindakan', data: 'id', }, ] const dataSlot: DataTableSlots = { 1: (value: string) => formatDate(value), 2: (value: TAuthorResponse) => ( <>
{value.name}
ID: {value.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
) : (
Biasa
), 7: (value: number) => formatNumberWithPeriods(value), 8: (value: string, _type: unknown, data: TNewsResponse) => (
), } const dataOptions: Config = { paging: true, searching: true, ordering: true, info: true, } return (
{/* TODO: Filter */}
setSelectedContent(undefined)} title="Artikel" fetcherAction={`/actions/admin/contents/delete/${selectedContent?.id}`} >

{selectedContent?.title}

) }