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-07 09:04:11 +08:00
|
|
|
import type { TCategoryResponse } from '~/apis/common/get-categories'
|
2025-03-09 10:23:11 +08:00
|
|
|
import type { TNewsResponse } from '~/apis/common/get-news'
|
2025-03-07 09:04:11 +08:00
|
|
|
import type { TTagResponse } from '~/apis/common/get-tags'
|
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-07 12:11:48 +08:00
|
|
|
import type { loader } from '~/routes/_admin.lg-admin._dashboard.contents._index'
|
2025-03-06 19:47:45 +07:00
|
|
|
import { formatDate } from '~/utils/formatter'
|
2025-02-25 15:45:27 +07:00
|
|
|
|
|
|
|
|
export const ContentsPage = () => {
|
2025-03-06 09:30:53 +08:00
|
|
|
const loaderData = useRouteLoaderData<typeof loader>(
|
2025-03-07 12:11:48 +08:00
|
|
|
'routes/_admin.lg-admin._dashboard.contents._index',
|
2025-03-06 09:30:53 +08:00
|
|
|
)
|
|
|
|
|
|
2025-02-25 15:45:27 +07:00
|
|
|
DataTable.use(DT)
|
2025-03-09 09:44:41 +08:00
|
|
|
const dataTable = loaderData?.newsData?.sort(
|
2025-03-07 14:43:12 +08:00
|
|
|
(a, b) => new Date(b.live_at).getTime() - new Date(a.live_at).getTime(),
|
|
|
|
|
)
|
2025-03-04 00:21:14 +07:00
|
|
|
const dataColumns = [
|
2025-03-06 23:49:12 +07:00
|
|
|
{
|
|
|
|
|
title: 'No',
|
2025-03-07 08:50:04 +08:00
|
|
|
render: (
|
|
|
|
|
data: unknown,
|
|
|
|
|
type: unknown,
|
|
|
|
|
row: unknown,
|
|
|
|
|
meta: { row: number },
|
|
|
|
|
) => {
|
2025-03-06 23:49:12 +07:00
|
|
|
return meta.row + 1
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-03-07 08:50:04 +08:00
|
|
|
{
|
2025-03-07 14:40:04 +08:00
|
|
|
title: 'Tanggal Live',
|
2025-03-07 08:50:04 +08:00
|
|
|
data: 'live_at',
|
|
|
|
|
},
|
2025-03-06 23:32:15 +07:00
|
|
|
{
|
2025-03-07 14:43:12 +08:00
|
|
|
title: 'Penulis',
|
2025-03-06 23:32:15 +07:00
|
|
|
},
|
2025-02-25 15:45:27 +07:00
|
|
|
{ title: 'Judul', data: 'title' },
|
2025-02-26 23:26:46 +07:00
|
|
|
{
|
2025-03-07 08:50:04 +08:00
|
|
|
title: 'Kategori',
|
|
|
|
|
data: 'categories',
|
|
|
|
|
},
|
|
|
|
|
{ title: 'Tag', data: 'tags' },
|
|
|
|
|
{
|
2025-03-07 10:30:46 +08:00
|
|
|
title: 'Subscription',
|
2025-03-06 09:30:53 +08:00
|
|
|
data: 'is_premium',
|
2025-02-26 23:26:46 +07:00
|
|
|
},
|
2025-03-06 19:47:45 +07:00
|
|
|
{
|
|
|
|
|
title: 'Action',
|
2025-03-06 22:49:56 +07:00
|
|
|
data: 'slug',
|
2025-03-06 19:47:45 +07:00
|
|
|
},
|
2025-02-25 15:45:27 +07:00
|
|
|
]
|
2025-03-04 00:21:14 +07:00
|
|
|
const dataSlot = {
|
2025-03-07 08:50:04 +08:00
|
|
|
1: (value: string) => formatDate(value),
|
2025-03-07 09:04:11 +08:00
|
|
|
2: (_value: unknown, _type: unknown, data: TNewsResponse) => (
|
2025-03-07 08:50:04 +08:00
|
|
|
<div>
|
|
|
|
|
<div>{data.author.name}</div>
|
|
|
|
|
<div className="text-sm text-[#7C7C7C]">ID: {data.id.slice(0, 8)}</div>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
2025-03-09 13:44:04 +08:00
|
|
|
4: (value: TCategoryResponse[]) => (
|
|
|
|
|
<div className="text-xs">{value.map((item) => item.name).join(', ')}</div>
|
|
|
|
|
),
|
|
|
|
|
5: (value: TTagResponse[]) => (
|
|
|
|
|
<div className="text-xs">{value.map((item) => item.name).join(', ')}</div>
|
|
|
|
|
),
|
2025-03-07 08:50:04 +08:00
|
|
|
6: (value: string) =>
|
|
|
|
|
value ? (
|
|
|
|
|
<div className="rounded-full bg-[#FFFCAF] px-2 text-center text-[#DBCA6E]">
|
|
|
|
|
Premium
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="rounded-full bg-[#F5F5F5] px-2 text-center text-[#4C5CA0]">
|
|
|
|
|
Normal
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
7: (value: string) => (
|
|
|
|
|
<Button
|
|
|
|
|
as="a"
|
|
|
|
|
href={`/lg-admin/contents/update/${value}`}
|
|
|
|
|
className="text-md rounded-md"
|
|
|
|
|
size="sm"
|
|
|
|
|
>
|
2025-03-07 13:53:07 +08:00
|
|
|
Update Artikel
|
2025-03-07 08:50:04 +08:00
|
|
|
</Button>
|
|
|
|
|
),
|
2025-03-04 00:21:14 +07:00
|
|
|
}
|
|
|
|
|
const dataOptions = {
|
|
|
|
|
paging: true,
|
|
|
|
|
searching: true,
|
|
|
|
|
ordering: true,
|
|
|
|
|
info: true,
|
|
|
|
|
}
|
2025-02-25 15:45:27 +07:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="relative">
|
2025-03-09 14:54:18 +08:00
|
|
|
<TitleDashboard title="Artikel" />
|
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"
|
|
|
|
|
>
|
2025-03-07 13:53:07 +08:00
|
|
|
Buat Artikel
|
2025-03-04 09:44:09 +08:00
|
|
|
</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}
|
2025-03-09 14:54:18 +08:00
|
|
|
title="Daftar Artikel"
|
2025-03-04 00:21:14 +07:00
|
|
|
/>
|
2025-02-25 15:45:27 +07:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|