All files / src/app/admin/support page.tsx

0% Statements 0/74
100% Branches 0/0
0% Functions 0/1
0% Lines 0/74

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                                                                                                                                     
export const dynamic = "force-dynamic";

import { Metadata } from 'next';
import { prisma } from '@/lib/prisma';
import SupportDashboard from '@/components/features/admin/support/SupportDashboard';
import { SupportStats } from '@/types/support';

export const metadata: Metadata = {
  title: 'Support Dashboard | Admin | Elite Events',
  description: 'Manage customer support tickets and articles'};

export default async function AdminSupportPage() {
  // Get stats
  const [
    totalTickets,
    openTickets,
    resolvedToday,
    ticketsByStatus,
    ticketsByPriority,
    recentTickets,
  ] = await Promise.all([
    prisma.supportTicket.count(),
    prisma.supportTicket.count({
      where: { status: { in: ['OPEN', 'IN_PROGRESS', 'AWAITING_CUSTOMER', 'AWAITING_AGENT'] } }}),
    prisma.supportTicket.count({
      where: {
        status: 'RESOLVED',
        resolvedAt: {
          gte: new Date(new Date().setHours(0, 0, 0, 0))}}}),
    prisma.supportTicket.groupBy({
      by: ['status'],
      _count: true}),
    prisma.supportTicket.groupBy({
      by: ['priority'],
      _count: true}),
    prisma.supportTicket.findMany({
      take: 5,
      orderBy: { createdAt: 'desc' },
      select: {
        id: true,
        ticketNumber: true,
        subject: true,
        status: true,
        priority: true,
        createdAt: true}}),
  ]);

  // Transform grouped data
  const statusCounts = ticketsByStatus.reduce((acc, item) => {
    acc[item.status] = item._count;
    return acc;
  }, {} as Record<string, number>);

  const priorityCounts = ticketsByPriority.reduce((acc, item) => {
    acc[item.priority] = item._count;
    return acc;
  }, {} as Record<string, number>);

  const stats: SupportStats = {
    totalTickets,
    openTickets,
    resolvedToday,
    avgResponseTime: 0, // Would need more complex calculation
    ticketsByStatus: statusCounts,
    ticketsByPriority: priorityCounts,
    ticketsByCategory: {}};

  return (
    <SupportDashboard
      stats={stats}
      recentTickets={recentTickets}
    />
  );
}