109 lines
2.6 KiB
TypeScript
109 lines
2.6 KiB
TypeScript
import DT from 'datatables.net-dt'
|
|
import DataTable from 'datatables.net-react'
|
|
import { Link, useRouteLoaderData } from 'react-router'
|
|
|
|
import { Button } from '~/components/ui/button'
|
|
import { getStatusBadge, type TColorBadge } from '~/components/ui/color-badge'
|
|
import { UiTable } from '~/components/ui/table'
|
|
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
|
import type { loader } from '~/routes/_admin.lg-admin._dashboard.subscribe-plan._index'
|
|
import { formatNumberWithPeriods } from '~/utils/formatter'
|
|
|
|
export const SubscribePlanPage = () => {
|
|
const loaderData = useRouteLoaderData<typeof loader>(
|
|
'routes/_admin.lg-admin._dashboard.subscribe-plan._index',
|
|
)
|
|
|
|
DataTable.use(DT)
|
|
const { subscriptionsData: dataTable } = loaderData || {}
|
|
|
|
const dataColumns = [
|
|
{
|
|
title: 'No',
|
|
render: (
|
|
_data: unknown,
|
|
_type: unknown,
|
|
_row: unknown,
|
|
meta: { row: number },
|
|
) => {
|
|
return meta.row + 1
|
|
},
|
|
},
|
|
{
|
|
title: 'Nama',
|
|
data: 'name',
|
|
},
|
|
{
|
|
title: 'Kode',
|
|
data: 'code',
|
|
},
|
|
{
|
|
title: 'Length',
|
|
data: 'length',
|
|
},
|
|
{
|
|
title: 'Price',
|
|
data: 'price',
|
|
},
|
|
{
|
|
title: 'Status',
|
|
data: 'status',
|
|
},
|
|
{
|
|
title: 'Action',
|
|
data: 'id',
|
|
},
|
|
]
|
|
const dataSlot = {
|
|
4: (value: number) => (
|
|
<div className="text-right">Rp. {formatNumberWithPeriods(value)}</div>
|
|
),
|
|
5: (value: number) => (
|
|
<span
|
|
className={`rounded-lg px-2 text-sm ${getStatusBadge(value as TColorBadge)}`}
|
|
>
|
|
{value === 1 ? 'Active' : 'Inactive'}
|
|
</span>
|
|
),
|
|
6: (value: string) => (
|
|
<Button
|
|
as="a"
|
|
href={`/lg-admin/subscribe-plan/update/${value}`}
|
|
className="text-md rounded-md"
|
|
size="sm"
|
|
>
|
|
Update Subscribe Plan
|
|
</Button>
|
|
),
|
|
}
|
|
return (
|
|
<div className="relative">
|
|
<TitleDashboard title="Subscribe Plan" />
|
|
<div className="mb-8 flex items-end justify-between">
|
|
<div className="flex-1">{/* TODO: Filter */}</div>
|
|
<Button
|
|
as={Link}
|
|
to="/lg-admin/subscribe-plan/create"
|
|
className="text-md h-[42px] rounded-md"
|
|
size="lg"
|
|
>
|
|
Buat Subscribe Plan
|
|
</Button>
|
|
</div>
|
|
|
|
<UiTable
|
|
data={dataTable || []}
|
|
columns={dataColumns}
|
|
slots={dataSlot}
|
|
options={{
|
|
paging: true,
|
|
searching: true,
|
|
ordering: true,
|
|
info: true,
|
|
}}
|
|
title=" Daftar Subscribe Plan"
|
|
/>
|
|
</div>
|
|
)
|
|
}
|