68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import Link from 'next/link'
|
|
import { Button } from '@/components/ui/button'
|
|
import { fetchAdminList } from '@/lib/admin-list'
|
|
import { PERMS } from '@/lib/permissions'
|
|
import { PollsTable } from './polls-table'
|
|
|
|
export default async function PollsPage({
|
|
params: paramsPromise,
|
|
searchParams,
|
|
}: {
|
|
params: Promise<{ locale: string }>
|
|
searchParams: Promise<Record<string, string>>
|
|
}) {
|
|
const result = await fetchAdminList(
|
|
{
|
|
permission: PERMS.POLLS_VIEW,
|
|
model: 'websitePoll',
|
|
searchFields: ['title'],
|
|
defaultSort: { createdAt: 'desc' },
|
|
mapRow: (p: {
|
|
id: number
|
|
title: string
|
|
status: string
|
|
showResults: number
|
|
multipleChoice: number
|
|
startsAt: Date | null
|
|
endsAt: Date | null
|
|
createdAt: Date
|
|
}) => ({
|
|
id: p.id,
|
|
title: p.title,
|
|
status: p.status,
|
|
showResults: p.showResults,
|
|
multipleChoice: p.multipleChoice,
|
|
startsAt: p.startsAt,
|
|
endsAt: p.endsAt,
|
|
createdAt: p.createdAt,
|
|
}),
|
|
},
|
|
paramsPromise,
|
|
searchParams,
|
|
)
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<h1 className="text-3xl font-bold tracking-tight">Polls</h1>
|
|
<p className="text-muted-foreground">Manage community polls and surveys</p>
|
|
</div>
|
|
<Button asChild>
|
|
<Link href="/admin/polls/create">New Poll</Link>
|
|
</Button>
|
|
</div>
|
|
|
|
<PollsTable
|
|
data={{
|
|
rows: result.rows,
|
|
total: result.total,
|
|
page: result.page,
|
|
perPage: result.perPage,
|
|
lastPage: result.lastPage,
|
|
}}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|