import { PencilSquareIcon, PlusIcon, TrashIcon, } from '@heroicons/react/20/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 { 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' export const CategoriesPage = () => { const loaderData = useRouteLoaderData( 'routes/_admin.lg-admin._dashboard', ) const [selectedCategory, setSelectedCategory] = useState() 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: ConfigColumns[] = [ { title: 'No', render: ( _data: unknown, _type: unknown, row: TCategoryResponse, meta: { row: number }, ) => { return `
${meta.row + 1}
${ row.sequence === null ? '' : `
Urutan: ${row.sequence}
` }` }, }, { title: 'Kategori', }, { title: 'Deskripsi', data: 'description', }, { title: 'Action', data: 'id', }, ] const dataSlot: DataTableSlots = { 1: (_value: unknown, _type: unknown, data: TCategoryResponse) => (
{data.name}
Kode: {data.code}
), 3: (value: string, _type: unknown, data: TCategoryResponse) => (
{data.code === 'spotlight' ? ( '' ) : ( )}
), } const dataOptions: Config = { paging: true, searching: true, ordering: true, info: true, } return (
{/* TODO: Filter */}
setSelectedCategory(undefined)} title="Kategori" fetcherAction={`/actions/admin/categories/delete/${selectedCategory?.id}`} >

{selectedCategory?.name}

) }