feat: add admin content module pages
Local Build and Deploy / deploy (push) Successful in 47s

This commit is contained in:
Simo committed 2026-07-12 15:27:07 +02:00
1 parent f422bb4a0b
commit 2606092337
24 files changed
+2892

No files matched your search

File diff suppressed because it is too large. Load diff
+25
View File
@@ -0,0 +1,25 @@
import { redirect } from 'next/navigation'
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
import { prisma } from '@/lib/prisma'
import { BannersManager } from './banners-manager'
export default async function BannersPage() {
const { session, permissions } = await getAdminContext()
if (!canAccess(permissions, PERMS.BANNERS_VIEW, session.user.rank)) {
redirect('/admin')
}
const banners = await prisma.websiteBanner.findMany({
orderBy: { sortOrder: 'asc' },
})
return (
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold tracking-tight">Banners</h1>
<p className="text-muted-foreground">Manage homepage banners and promotional slides</p>
</div>
<BannersManager banners={banners} />
</div>
)
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,40 @@
'use client'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
interface Registration {
id: number
userId: number
username: string
createdAt: Date
}
interface Props {
registrations: Registration[]
}
export function EventRegistrations({ registrations }: Props) {
return (
<Card>
<CardHeader>
<CardTitle>Registrations ({registrations.length})</CardTitle>
</CardHeader>
<CardContent>
{registrations.length === 0 ? (
<p className="text-sm text-muted-foreground text-center py-4">No registrations yet.</p>
) : (
<div className="divide-y max-h-[400px] overflow-y-auto">
{registrations.map((r) => (
<div key={r.id} className="flex items-center justify-between py-2">
<span className="text-sm font-medium">{r.username}</span>
<span className="text-xs text-muted-foreground">
{new Date(r.createdAt).toLocaleString()}
</span>
</div>
))}
</div>
)}
</CardContent>
</Card>
)
}
@@ -0,0 +1,99 @@
'use client'
import { Plus } from 'lucide-react'
import { useState } from 'react'
import { addEventWinner } from '@/actions/events'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { useServerAction } from '@/hooks/use-server-action'
interface Winner {
id: number
userId: number
position: number
username: string
createdAt: Date
}
interface Props {
eventId: number
winners: Winner[]
}
export function EventWinnersManager({ eventId, winners }: Props) {
const { run, isPending } = useServerAction()
const [showForm, setShowForm] = useState(false)
const [userId, setUserId] = useState('')
const [position, setPosition] = useState(winners.length + 1)
function handleAdd(e: React.FormEvent) {
e.preventDefault()
run(() => addEventWinner({ eventId, userId: Number(userId), position }), {
successMessage: 'Winner added!',
onSuccess: () => {
setShowForm(false)
setUserId('')
setPosition(position + 1)
},
})
}
return (
<Card>
<CardHeader className="flex flex-row items-center justify-between">
<CardTitle>Winners</CardTitle>
<Button size="sm" onClick={() => setShowForm(!showForm)}>
<Plus className="h-4 w-4 mr-1" /> Add Winner
</Button>
</CardHeader>
<CardContent className="space-y-3">
{showForm && (
<form onSubmit={handleAdd} className="border rounded-lg p-4 flex gap-3 items-end">
<div className="space-y-1">
<Label>User ID</Label>
<Input
type="number"
value={userId}
onChange={(e) => setUserId(e.target.value)}
required
placeholder="12345"
/>
</div>
<div className="space-y-1">
<Label>Position</Label>
<Input
type="number"
value={position}
onChange={(e) => setPosition(Number(e.target.value))}
min={1}
/>
</div>
<Button type="submit" size="sm" disabled={isPending}>
Add
</Button>
</form>
)}
{winners.length === 0 && !showForm && (
<p className="text-sm text-muted-foreground text-center py-4">No winners yet.</p>
)}
<div className="divide-y">
{winners.map((w) => (
<div key={w.id} className="flex items-center gap-3 py-2.5">
<span className="flex h-7 w-7 items-center justify-center rounded-full bg-primary text-primary-foreground text-xs font-bold">
{w.position}
</span>
<span className="font-medium text-sm">{w.username}</span>
<span className="text-xs text-muted-foreground ml-auto">
{new Date(w.createdAt).toLocaleDateString()}
</span>
</div>
))}
</div>
</CardContent>
</Card>
)
}
File diff suppressed because it is too large. Load diff
+27
View File
@@ -0,0 +1,27 @@
import { redirect } from 'next/navigation'
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
import { prisma } from '@/lib/prisma'
import { EventForm } from '../event-form'
export default async function CreateEventPage() {
const { session, permissions } = await getAdminContext()
if (!canAccess(permissions, PERMS.EVENTS_EDIT, session.user.rank)) {
redirect('/admin/events')
}
const eventTypes = await prisma.websiteEventType.findMany({
where: { isActive: 1 },
orderBy: { name: 'asc' },
})
return (
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold tracking-tight">Create Event</h1>
<p className="text-muted-foreground">Schedule a new hotel event</p>
</div>
<EventForm eventTypes={eventTypes} />
</div>
)
}
File diff suppressed because it is too large. Load diff
+81
View File
@@ -0,0 +1,81 @@
'use client'
import { Pencil } from 'lucide-react'
import Link from 'next/link'
import { DataTable } from '@/components/admin/data-table'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import type { DataTableColumn, PaginatedResult } from '@/types'
interface EventRow {
id: number
title: string
typeName: string
typeColor: string
startsAt: Date
endsAt: Date | null
status: string
hostUserId: number
}
const statusVariants: Record<string, 'default' | 'secondary' | 'outline' | 'destructive'> = {
published: 'default',
draft: 'secondary',
cancelled: 'destructive',
completed: 'outline',
}
function getColumns(): DataTableColumn<EventRow>[] {
return [
{ key: 'id', label: 'ID', sortable: true },
{
key: 'title',
label: 'Title',
sortable: true,
render: (value) => <span className="font-medium">{String(value)}</span>,
},
{
key: 'typeName',
label: 'Type',
sortable: false,
render: (_, row) => (
<Badge style={{ backgroundColor: row.typeColor, color: '#fff' }}>{row.typeName}</Badge>
),
},
{
key: 'startsAt',
label: 'Starts',
sortable: true,
render: (value) => (
<span className="text-sm">{new Date(value as unknown as string).toLocaleString()}</span>
),
},
{
key: 'status',
label: 'Status',
sortable: true,
render: (value) => (
<Badge variant={statusVariants[String(value)] ?? 'secondary'}>{String(value)}</Badge>
),
},
{
key: 'actions',
label: 'Actions',
render: (_, row) => (
<Button variant="ghost" size="icon" asChild>
<Link href={`/admin/events/${row.id}`}>
<Pencil className="h-4 w-4" />
</Link>
</Button>
),
},
]
}
interface EventsTableProps {
data: PaginatedResult<EventRow>
}
export function EventsTable({ data }: EventsTableProps) {
return <DataTable data={data} columns={getColumns()} searchPlaceholder="Search events..." />
}
+68
View File
@@ -0,0 +1,68 @@
import Link from 'next/link'
import { Button } from '@/components/ui/button'
import { fetchAdminList } from '@/lib/admin-list'
import { PERMS } from '@/lib/permissions'
import { EventsTable } from './events-table'
export default async function EventsPage({
params: paramsPromise,
searchParams,
}: {
params: Promise<{ locale: string }>
searchParams: Promise<Record<string, string>>
}) {
const result = await fetchAdminList(
{
permission: PERMS.EVENTS_VIEW,
model: 'websiteEvent',
searchFields: ['title'],
defaultSort: { startsAt: 'desc' },
include: { type: { select: { name: true, color: true } } },
mapRow: (e: {
id: number
title: string
type: { name: string; color: string }
startsAt: Date
endsAt: Date | null
status: string
hostUserId: number
_count?: { registrations: number }
}) => ({
id: e.id,
title: e.title,
typeName: e.type.name,
typeColor: e.type.color,
startsAt: e.startsAt,
endsAt: e.endsAt,
status: e.status,
hostUserId: e.hostUserId,
}),
},
paramsPromise,
searchParams,
)
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold tracking-tight">Events</h1>
<p className="text-muted-foreground">Manage hotel events, calendar and prizes</p>
</div>
<Button asChild>
<Link href="/admin/events/create">New Event</Link>
</Button>
</div>
<EventsTable
data={{
rows: result.rows,
total: result.total,
page: result.page,
perPage: result.perPage,
lastPage: result.lastPage,
}}
/>
</div>
)
}
File diff suppressed because it is too large. Load diff
+26
View File
@@ -0,0 +1,26 @@
import { redirect } from 'next/navigation'
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
import { prisma } from '@/lib/prisma'
import { EventTypesManager } from './event-types-manager'
export default async function EventTypesPage() {
const { session, permissions } = await getAdminContext()
if (!canAccess(permissions, PERMS.EVENTS_EDIT, session.user.rank)) {
redirect('/admin/events')
}
const eventTypes = await prisma.websiteEventType.findMany({
orderBy: { name: 'asc' },
})
return (
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold tracking-tight">Event Types</h1>
<p className="text-muted-foreground">Manage event categories and types</p>
</div>
<EventTypesManager eventTypes={eventTypes} />
</div>
)
}
+4
View File
@@ -72,6 +72,10 @@ function getNavGroups(t: (key: string) => string) {
{ href: "/admin/writeable-boxes", label: t("writeableBoxes"), icon: <SquarePen size={16} /> }, { href: "/admin/writeable-boxes", label: t("writeableBoxes"), icon: <SquarePen size={16} /> },
{ href: "/admin/photos", label: t("photos"), icon: <Image size={16} /> }, { href: "/admin/photos", label: t("photos"), icon: <Image size={16} /> },
{ href: "/admin/tickets", label: t("tickets"), icon: <MessageSquare size={16} /> }, { href: "/admin/tickets", label: t("tickets"), icon: <MessageSquare size={16} /> },
{ href: "/admin/events", label: "Events", icon: <Calendar size={16} /> },
{ href: "/admin/polls", label: "Polls", icon: <ClipboardList size={16} /> },
{ href: "/admin/banners", label: "Banners", icon: <Image size={16} /> },
{ href: "/admin/prefixes", label: "Prefixes", icon: <Languages size={16} /> },
], ],
}, },
{ {
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+74
View File
@@ -0,0 +1,74 @@
'use client'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
interface QuestionResult {
id: number
question: string
options: string
votes: string[] // array of answer strings
}
interface Props {
questions: QuestionResult[]
}
export function PollResultsView({ questions }: Props) {
return (
<Card>
<CardHeader>
<CardTitle>Results</CardTitle>
</CardHeader>
<CardContent className="space-y-6">
{questions.map((q) => {
const options = q.options.split('\n').filter(Boolean)
const totalVotes = q.votes.length
// Count votes per option
const voteCounts = new Map<string, number>()
for (const opt of options) voteCounts.set(opt, 0)
for (const vote of q.votes) {
voteCounts.set(vote, (voteCounts.get(vote) ?? 0) + 1)
}
return (
<div key={q.id}>
<h4 className="text-sm font-medium mb-3">{q.question}</h4>
{options.length > 0 ? (
<div className="space-y-2">
{options.map((opt) => {
const count = voteCounts.get(opt) ?? 0
const pct = totalVotes > 0 ? Math.round((count / totalVotes) * 100) : 0
return (
<div key={opt}>
<div className="flex justify-between text-xs mb-1">
<span>{opt}</span>
<span className="text-muted-foreground">
{count} votes ({pct}%)
</span>
</div>
<div className="h-2 w-full rounded-full bg-muted overflow-hidden">
<div
className="h-full rounded-full bg-primary transition-all"
style={{ width: `${pct}%` }}
/>
</div>
</div>
)
})}
</div>
) : (
<div className="text-sm text-muted-foreground">
{totalVotes} free-text responses
</div>
)}
<p className="text-xs text-muted-foreground mt-2">
{totalVotes} total vote{totalVotes !== 1 ? 's' : ''}
</p>
</div>
)
})}
</CardContent>
</Card>
)
}
+21
View File
@@ -0,0 +1,21 @@
import { redirect } from 'next/navigation'
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
import { PollForm } from '../poll-form'
export default async function CreatePollPage() {
const { session, permissions } = await getAdminContext()
if (!canAccess(permissions, PERMS.POLLS_EDIT, session.user.rank)) {
redirect('/admin/polls')
}
return (
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold tracking-tight">Create Poll</h1>
<p className="text-muted-foreground">Create a new community poll or survey</p>
</div>
<PollForm />
</div>
)
}
+67
View File
@@ -0,0 +1,67 @@
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>
)
}
File diff suppressed because it is too large. Load diff
+79
View File
@@ -0,0 +1,79 @@
'use client'
import { Pencil } from 'lucide-react'
import Link from 'next/link'
import { DataTable } from '@/components/admin/data-table'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import type { DataTableColumn, PaginatedResult } from '@/types'
interface PollRow {
id: number
title: string
status: string
showResults: number
multipleChoice: number
startsAt: Date | null
endsAt: Date | null
createdAt: Date
}
const statusVariants: Record<string, 'default' | 'secondary' | 'outline'> = {
active: 'default',
draft: 'secondary',
closed: 'outline',
}
function getColumns(): DataTableColumn<PollRow>[] {
return [
{ key: 'id', label: 'ID', sortable: true },
{
key: 'title',
label: 'Title',
sortable: true,
render: (value) => <span className="font-medium">{String(value)}</span>,
},
{
key: 'status',
label: 'Status',
sortable: true,
render: (value) => (
<Badge variant={statusVariants[String(value)] ?? 'secondary'}>{String(value)}</Badge>
),
},
{
key: 'multipleChoice',
label: 'Type',
render: (value) => (
<span className="text-sm">{Number(value) ? 'Multiple choice' : 'Single choice'}</span>
),
},
{
key: 'createdAt',
label: 'Created',
sortable: true,
render: (value) => (
<span className="text-sm">{new Date(value as unknown as string).toLocaleDateString()}</span>
),
},
{
key: 'actions',
label: 'Actions',
render: (_, row) => (
<Button variant="ghost" size="icon" asChild>
<Link href={`/admin/polls/${row.id}`}>
<Pencil className="h-4 w-4" />
</Link>
</Button>
),
},
]
}
interface PollsTableProps {
data: PaginatedResult<PollRow>
}
export function PollsTable({ data }: PollsTableProps) {
return <DataTable data={data} columns={getColumns()} searchPlaceholder="Search polls..." />
}
+28
View File
@@ -0,0 +1,28 @@
import { Skeleton } from '@/components/ui/skeleton'
export default function PrefixesLoading() {
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<Skeleton className="h-9 w-40" />
<Skeleton className="h-5 w-64 mt-2" />
</div>
</div>
<div className="flex items-center gap-3">
<Skeleton className="h-10 w-64" />
<Skeleton className="h-10 w-24" />
</div>
<div className="rounded-md border">
{Array.from({ length: 8 }).map((_, i) => (
<div key={i} className="flex items-center gap-6 px-4 py-3 border-b last:border-0">
<Skeleton className="h-4 w-12" />
<Skeleton className="h-4 w-32" />
<Skeleton className="h-4 w-24" />
<Skeleton className="h-5 w-16 rounded-full" />
</div>
))}
</div>
</div>
)
}
+25
View File
@@ -0,0 +1,25 @@
import { redirect } from 'next/navigation'
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
import { PrefixesClient } from './prefixes-client'
export default async function PrefixesPage() {
const { session, permissions } = await getAdminContext()
if (!canAccess(permissions, PERMS.PREFIXES_VIEW, session.user.rank)) {
redirect('/admin')
}
const canEdit = canAccess(permissions, PERMS.PREFIXES_EDIT, session.user.rank)
return (
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold tracking-tight">Custom Prefixes</h1>
<p className="text-muted-foreground">
Gestisci i prefissi degli utenti, la blacklist e le impostazioni
</p>
</div>
<PrefixesClient canEdit={canEdit} />
</div>
)
}
File diff suppressed because it is too large. Load diff
+40
View File
@@ -0,0 +1,40 @@
"use client";
import { cn } from "@/lib/utils";
interface DateTimePickerProps {
value?: Date | string | null;
onChange: (date: Date | null) => void;
placeholder?: string;
disabled?: boolean;
className?: string;
showTime?: boolean;
}
function inputValue(value: Date | string | null | undefined, showTime: boolean): string {
if (!value) return "";
const date = value instanceof Date ? value : new Date(value);
if (Number.isNaN(date.getTime())) return "";
const local = new Date(date.getTime() - date.getTimezoneOffset() * 60_000);
return local.toISOString().slice(0, showTime ? 16 : 10);
}
export function DateTimePicker({
value,
onChange,
placeholder,
disabled = false,
className,
showTime = true,
}: DateTimePickerProps) {
return (
<input
aria-label={placeholder ?? (showTime ? "Date and time" : "Date")}
className={cn("w-full", className)}
disabled={disabled}
type={showTime ? "datetime-local" : "date"}
value={inputValue(value, showTime)}
onChange={(event) => onChange(event.target.value ? new Date(event.target.value) : null)}
/>
);
}