2025-02-25 15:45:27 +07:00
|
|
|
import DT from 'datatables.net-dt'
|
|
|
|
|
import DataTable from 'datatables.net-react'
|
2025-03-06 09:30:53 +08:00
|
|
|
import { Link, useRouteLoaderData } from 'react-router'
|
2025-02-25 15:45:27 +07:00
|
|
|
|
2025-03-02 20:09:09 +07:00
|
|
|
import { Button } from '~/components/ui/button'
|
2025-03-04 00:21:14 +07:00
|
|
|
import { UiTable } from '~/components/ui/table'
|
2025-02-25 15:45:27 +07:00
|
|
|
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
2025-03-06 09:30:53 +08:00
|
|
|
import type { loader } from '~/routes/_admin.lg-admin._dashboard.contents'
|
2025-02-25 15:45:27 +07:00
|
|
|
|
|
|
|
|
export const ContentsPage = () => {
|
2025-03-06 09:30:53 +08:00
|
|
|
const loaderData = useRouteLoaderData<typeof loader>(
|
|
|
|
|
'routes/_admin.lg-admin._dashboard.contents',
|
|
|
|
|
)
|
|
|
|
|
const newsData = loaderData?.newsData
|
|
|
|
|
|
2025-02-25 15:45:27 +07:00
|
|
|
DataTable.use(DT)
|
2025-03-06 09:30:53 +08:00
|
|
|
const dataTable = newsData
|
2025-03-04 00:21:14 +07:00
|
|
|
const dataColumns = [
|
2025-02-25 15:45:27 +07:00
|
|
|
{ title: 'No', data: 'id' },
|
2025-03-06 09:30:53 +08:00
|
|
|
{ title: 'Tanggal Konten', data: 'created_at' },
|
|
|
|
|
{ title: 'Nama Penulis', data: 'author_id' },
|
2025-02-25 15:45:27 +07:00
|
|
|
{ title: 'Judul', data: 'title' },
|
2025-03-06 09:30:53 +08:00
|
|
|
// { title: 'Kategori', data: 'category' },
|
2025-02-26 23:26:46 +07:00
|
|
|
{
|
|
|
|
|
title: 'Tags',
|
2025-03-06 09:30:53 +08:00
|
|
|
data: 'is_premium',
|
2025-02-26 23:26:46 +07:00
|
|
|
render: (value: string) => {
|
2025-03-06 09:30:53 +08:00
|
|
|
return value
|
2025-03-06 09:39:40 +08:00
|
|
|
? `<span class="bg-[#FFFCAF] text-[#DBCA6E] px-4 py-2 rounded-full">Premium</span>`
|
|
|
|
|
: `<span class="bg-[#F5F5F5] text-[#4C5CA0] px-4 py-2 rounded-full">Normal</span>`
|
2025-02-26 23:26:46 +07:00
|
|
|
},
|
|
|
|
|
},
|
2025-03-06 09:30:53 +08:00
|
|
|
// {
|
|
|
|
|
// title: 'Action',
|
|
|
|
|
// data: 'id',
|
|
|
|
|
// },
|
2025-02-25 15:45:27 +07:00
|
|
|
]
|
2025-03-04 00:21:14 +07:00
|
|
|
const dataSlot = {
|
|
|
|
|
6: (value: string | number) => {
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
as="a"
|
|
|
|
|
href={`/lg-admin/contents/update/${value}`}
|
|
|
|
|
className="text-md rounded-md"
|
|
|
|
|
size="sm"
|
|
|
|
|
>
|
|
|
|
|
Lihat Detail
|
|
|
|
|
</Button>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
const dataOptions = {
|
|
|
|
|
paging: true,
|
|
|
|
|
searching: true,
|
|
|
|
|
ordering: true,
|
|
|
|
|
info: true,
|
|
|
|
|
}
|
2025-02-25 15:45:27 +07:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<TitleDashboard title="Konten" />
|
2025-03-06 08:45:24 +08:00
|
|
|
<div className="mb-8 flex items-end justify-between gap-5">
|
|
|
|
|
<div className="flex-1">{/* TODO: Filter */}</div>
|
2025-03-04 09:44:09 +08:00
|
|
|
<Button
|
|
|
|
|
as={Link}
|
|
|
|
|
to="/lg-admin/contents/create"
|
2025-03-05 17:57:52 +08:00
|
|
|
className="text-md h-[42px] rounded-md"
|
2025-03-04 09:44:09 +08:00
|
|
|
size="lg"
|
|
|
|
|
>
|
|
|
|
|
Create New
|
|
|
|
|
</Button>
|
2025-02-27 16:42:36 +07:00
|
|
|
</div>
|
2025-03-04 00:21:14 +07:00
|
|
|
|
|
|
|
|
<UiTable
|
|
|
|
|
data={dataTable}
|
|
|
|
|
columns={dataColumns}
|
|
|
|
|
slots={dataSlot}
|
|
|
|
|
options={dataOptions}
|
|
|
|
|
title="Daftar Konten"
|
|
|
|
|
/>
|
2025-02-25 15:45:27 +07:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|