feat: add dashboard categories page with data table and loader
This commit is contained in:
parent
2c05c543ce
commit
df41e4050c
68
app/pages/dashboard-categories/index.tsx
Normal file
68
app/pages/dashboard-categories/index.tsx
Normal file
@ -0,0 +1,68 @@
|
||||
import DataTable from 'datatables.net-dt'
|
||||
import DT from 'datatables.net-react'
|
||||
import { Link, useRouteLoaderData } from 'react-router'
|
||||
|
||||
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.categories._index'
|
||||
export const CategoriesPage = () => {
|
||||
const loaderData = useRouteLoaderData<typeof loader>(
|
||||
'routes/_admin.lg-admin._dashboard.categories._index',
|
||||
)
|
||||
const dataTable = loaderData?.dataCategories
|
||||
|
||||
DataTable.use(DT)
|
||||
const dataColumns = [
|
||||
{
|
||||
title: 'No',
|
||||
render: (
|
||||
data: unknown,
|
||||
type: unknown,
|
||||
row: unknown,
|
||||
meta: { row: number },
|
||||
) => {
|
||||
return meta.row + 1
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Nama Kategori',
|
||||
data: 'name',
|
||||
},
|
||||
{
|
||||
title: 'Code Katgeori',
|
||||
data: 'code',
|
||||
},
|
||||
]
|
||||
|
||||
const dataOptions = {
|
||||
paging: true,
|
||||
searching: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<TitleDashboard title="Kategori" />
|
||||
<div className="mb-8 flex items-end justify-between gap-5">
|
||||
<div className="flex-1">{/* TODO: Filter */}</div>
|
||||
<Button
|
||||
as={Link}
|
||||
to="/lg-admin/category/create"
|
||||
className="text-md h-[42px] rounded-md"
|
||||
size="lg"
|
||||
>
|
||||
Create New
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<UiTable
|
||||
data={dataTable}
|
||||
columns={dataColumns}
|
||||
options={dataOptions}
|
||||
title="Daftar Katgeori"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
15
app/routes/_admin.lg-admin._dashboard.categories._index.tsx
Normal file
15
app/routes/_admin.lg-admin._dashboard.categories._index.tsx
Normal file
@ -0,0 +1,15 @@
|
||||
import { getCategories } from '~/apis/common/get-categories'
|
||||
import { handleCookie } from '~/libs/cookies'
|
||||
import { CategoriesPage } from '~/pages/dashboard-categories'
|
||||
|
||||
import type { Route } from './+types/_admin.lg-admin._dashboard.categories._index'
|
||||
|
||||
export const loader = async ({ request }: Route.LoaderArgs) => {
|
||||
const { staffToken } = await handleCookie(request)
|
||||
const { data: dataCategories } = await getCategories({
|
||||
accessToken: staffToken,
|
||||
})
|
||||
return { dataCategories }
|
||||
}
|
||||
const DashboardCategoriesLayout = () => <CategoriesPage />
|
||||
export default DashboardCategoriesLayout
|
||||
Loading…
x
Reference in New Issue
Block a user