style: format code with prettier
Local Build and Deploy / deploy (push) Successful in 49s

This commit is contained in:
openhands committed 2026-07-12 21:07:34 +02:00
1 parent e85e4d74ea
commit 2e4ed76121
378 files changed
+22404 -20686

No files matched your search

+58 -54
View File
@@ -1,51 +1,59 @@
import { AlertCircle, CheckCircle2, Clock, Loader2, Ticket } from 'lucide-react'
import Link from 'next/link'
import { redirect } from 'next/navigation'
import { Badge } from '@/components/ui/badge'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
import { prisma } from '@/lib/prisma'
import { AlertCircle, CheckCircle2, Clock, Loader2, Ticket } from "lucide-react";
import Link from "next/link";
import { redirect } from "next/navigation";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
import { prisma } from "@/lib/prisma";
const STATUS_CONFIG = {
open: { label: 'Open', icon: AlertCircle, class: 'bg-[var(--admin-info-subtle)] text-[var(--admin-info)]' },
in_progress: { label: 'In Progress', icon: Loader2, class: 'bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]' },
waiting: { label: 'Waiting', icon: Clock, class: 'bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]' },
closed: { label: 'Closed', icon: CheckCircle2, class: 'bg-muted text-muted-foreground' },
} as const
open: { label: "Open", icon: AlertCircle, class: "bg-[var(--admin-info-subtle)] text-[var(--admin-info)]" },
in_progress: {
label: "In Progress",
icon: Loader2,
class: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
},
waiting: {
label: "Waiting",
icon: Clock,
class: "bg-[var(--admin-warning-subtle)] text-[var(--admin-warning)]",
},
closed: { label: "Closed", icon: CheckCircle2, class: "bg-muted text-muted-foreground" },
} as const;
const PRIORITY_COLORS = {
low: '',
normal: 'text-[var(--admin-info)]',
high: 'text-[var(--admin-warning)]',
urgent: 'text-[var(--admin-error)] font-bold',
}
low: "",
normal: "text-[var(--admin-info)]",
high: "text-[var(--admin-warning)]",
urgent: "text-[var(--admin-error)] font-bold",
};
interface PageProps {
searchParams: Promise<{ status?: string; page?: string }>
searchParams: Promise<{ status?: string; page?: string }>;
}
export default async function AdminTicketsPage({ searchParams }: PageProps) {
const { session, permissions } = await getAdminContext()
const { session, permissions } = await getAdminContext();
if (!canAccess(permissions, PERMS.TICKETS_VIEW, session.user.rank)) {
redirect('/admin')
redirect("/admin");
}
const sp = await searchParams
const statusFilter = sp.status || 'active'
const page = Math.max(1, Number(sp.page) || 1)
const perPage = 20
const sp = await searchParams;
const statusFilter = sp.status || "active";
const page = Math.max(1, Number(sp.page) || 1);
const perPage = 20;
const where =
statusFilter === 'active'
? { status: { not: 'closed' } }
: statusFilter === 'all'
statusFilter === "active"
? { status: { not: "closed" } }
: statusFilter === "all"
? {}
: { status: statusFilter }
: { status: statusFilter };
const [tickets, total, stats] = await Promise.all([
prisma.websiteTicket.findMany({
where,
orderBy: [{ createdAt: 'desc' }],
orderBy: [{ createdAt: "desc" }],
skip: (page - 1) * perPage,
take: perPage,
include: {
@@ -56,15 +64,15 @@ export default async function AdminTicketsPage({ searchParams }: PageProps) {
}),
prisma.websiteTicket.count({ where }),
Promise.all([
prisma.websiteTicket.count({ where: { status: 'open' } }),
prisma.websiteTicket.count({ where: { status: 'in_progress' } }),
prisma.websiteTicket.count({ where: { status: 'waiting' } }),
prisma.websiteTicket.count({ where: { status: 'closed' } }),
prisma.websiteTicket.count({ where: { status: "open" } }),
prisma.websiteTicket.count({ where: { status: "in_progress" } }),
prisma.websiteTicket.count({ where: { status: "waiting" } }),
prisma.websiteTicket.count({ where: { status: "closed" } }),
]),
])
]);
const [openCount, inProgressCount, waitingCount, closedCount] = stats
const totalPages = Math.ceil(total / perPage)
const [openCount, inProgressCount, waitingCount, closedCount] = stats;
const totalPages = Math.ceil(total / perPage);
return (
<div className="space-y-6">
@@ -112,18 +120,15 @@ export default async function AdminTicketsPage({ searchParams }: PageProps) {
{/* Filter tabs */}
<div className="flex gap-2">
{[
{ key: 'active', label: 'Active' },
{ key: 'open', label: 'Open' },
{ key: 'in_progress', label: 'In Progress' },
{ key: 'waiting', label: 'Waiting' },
{ key: 'closed', label: 'Closed' },
{ key: 'all', label: 'All' },
{ key: "active", label: "Active" },
{ key: "open", label: "Open" },
{ key: "in_progress", label: "In Progress" },
{ key: "waiting", label: "Waiting" },
{ key: "closed", label: "Closed" },
{ key: "all", label: "All" },
].map(({ key, label }) => (
<Link key={key} href={`/admin/tickets?status=${key}`}>
<Badge
variant={statusFilter === key ? 'default' : 'outline'}
className="cursor-pointer"
>
<Badge variant={statusFilter === key ? "default" : "outline"} className="cursor-pointer">
{label}
</Badge>
</Link>
@@ -147,9 +152,8 @@ export default async function AdminTicketsPage({ searchParams }: PageProps) {
</div>
) : (
tickets.map((ticket) => {
const status =
STATUS_CONFIG[ticket.status as keyof typeof STATUS_CONFIG] ?? STATUS_CONFIG.open
const StatusIcon = status.icon
const status = STATUS_CONFIG[ticket.status as keyof typeof STATUS_CONFIG] ?? STATUS_CONFIG.open;
const StatusIcon = status.icon;
return (
<Link
@@ -163,7 +167,7 @@ export default async function AdminTicketsPage({ searchParams }: PageProps) {
<span className="font-medium truncate">{ticket.subject}</span>
</div>
<div className="text-xs text-muted-foreground">
by {ticket.creator.username} &middot; {ticket._count.messages} msg &middot;{' '}
by {ticket.creator.username} &middot; {ticket._count.messages} msg &middot;{" "}
{ticket.category}
</div>
</div>
@@ -174,18 +178,18 @@ export default async function AdminTicketsPage({ searchParams }: PageProps) {
{status.label}
</span>
<span
className={`text-xs capitalize whitespace-nowrap ${PRIORITY_COLORS[ticket.priority as keyof typeof PRIORITY_COLORS] ?? ''}`}
className={`text-xs capitalize whitespace-nowrap ${PRIORITY_COLORS[ticket.priority as keyof typeof PRIORITY_COLORS] ?? ""}`}
>
{ticket.priority}
</span>
<span className="text-xs text-muted-foreground whitespace-nowrap">
{ticket.assignee?.username ?? '—'}
{ticket.assignee?.username ?? "—"}
</span>
<span className="text-xs text-muted-foreground whitespace-nowrap">
{new Date(ticket.createdAt).toLocaleDateString()}
</span>
</Link>
)
);
})
)}
</div>
@@ -213,5 +217,5 @@ export default async function AdminTicketsPage({ searchParams }: PageProps) {
</div>
)}
</div>
)
);
}