All files / src/components/features/admin/support/TicketManagement TicketTable.tsx

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

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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168                                                                                                                                                                                                                                                                                                                                               
'use client';

/**
 * TicketTable - Table display of support tickets
 */

import React from 'react';
import Link from 'next/link';
import { SupportTicketWithRelations } from '@/types/support';
import { TICKET_STATUS_CONFIG, TICKET_PRIORITY_CONFIG } from '@/constants/support';
import { Icon } from '@/components/ui/icons';

export interface TicketTableProps {
  /** List of tickets to display */
  tickets: SupportTicketWithRelations[];
  /** Loading state */
  loading: boolean;
  /** Selected ticket IDs */
  selectedIds: Set<string>;
  /** Handler for select all */
  onSelectAll: (checked: boolean) => void;
  /** Handler for selecting individual ticket */
  onSelectOne: (id: string, checked: boolean) => void;
}

export default function TicketTable({
  tickets,
  loading,
  selectedIds,
  onSelectAll,
  onSelectOne}: TicketTableProps) {
  const allSelected = tickets.length > 0 && selectedIds.size === tickets.length;
  const someSelected = selectedIds.size > 0 && selectedIds.size < tickets.length;

  if (loading) {
    return (
      <div className="bg-white rounded-lg border border-gray-200 p-8 text-center">
        <div className="animate-spin h-8 w-8 border-4 border-blue-600 border-t-transparent rounded-full mx-auto" />
        <p className="text-gray-500 mt-4">Loading tickets...</p>
      </div>
    );
  }

  if (tickets.length === 0) {
    return (
      <div className="bg-white rounded-lg border border-gray-200 p-8 text-center">
        <Icon name="clipboard-list" size={48} className="text-gray-400 mx-auto mb-4" />
        <p className="text-gray-500">No tickets found</p>
      </div>
    );
  }

  return (
    <div className="bg-white rounded-lg border border-gray-200 overflow-hidden">
      <div className="overflow-x-auto">
        <table className="min-w-full divide-y divide-gray-200">
          <thead className="bg-gray-50">
            <tr>
              <th className="px-4 py-3 w-10">
                <input
                  type="checkbox"
                  checked={allSelected}
                  ref={(el) => {
                    if (el) el.indeterminate = someSelected;
                  }}
                  onChange={(e) => onSelectAll(e.target.checked)}
                  className="h-4 w-4 text-blue-600 rounded border-gray-300 focus:ring-blue-500"
                />
              </th>
              <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Ticket
              </th>
              <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Customer
              </th>
              <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Status
              </th>
              <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Priority
              </th>
              <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Assigned To
              </th>
              <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Created
              </th>
              <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Last Updated
              </th>
            </tr>
          </thead>
          <tbody className="bg-white divide-y divide-gray-200">
            {tickets.map((ticket) => {
              const statusConfig = TICKET_STATUS_CONFIG[ticket.status as keyof typeof TICKET_STATUS_CONFIG];
              const priorityConfig = TICKET_PRIORITY_CONFIG[ticket.priority as keyof typeof TICKET_PRIORITY_CONFIG];

              return (
                <tr
                  key={ticket.id}
                  className="hover:bg-gray-50"
                >
                  <td className="px-4 py-3">
                    <input
                      type="checkbox"
                      checked={selectedIds.has(ticket.id)}
                      onChange={(e) => onSelectOne(ticket.id, e.target.checked)}
                      className="h-4 w-4 text-blue-600 rounded border-gray-300 focus:ring-blue-500"
                    />
                  </td>
                  <td className="px-4 py-3">
                    <Link
                      href={`/admin/support/tickets/${ticket.id}`}
                      className="group"
                    >
                      <p className="text-sm font-medium text-gray-500">
                        {ticket.ticketNumber}
                      </p>
                      <p className="text-sm font-medium text-gray-900 group-hover:text-blue-600 truncate max-w-xs">
                        {ticket.subject}
                      </p>
                    </Link>
                  </td>
                  <td className="px-4 py-3">
                    <p className="text-sm text-gray-900">{ticket.customerName}</p>
                    <p className="text-xs text-gray-500">{ticket.customerEmail}</p>
                  </td>
                  <td className="px-4 py-3">
                    <span
                      className={`inline-flex px-2 py-0.5 text-xs font-medium rounded-full ${statusConfig?.bgColor || 'bg-gray-100'} ${statusConfig?.color || 'text-gray-600'}`}
                    >
                      {statusConfig?.label || ticket.status}
                    </span>
                  </td>
                  <td className="px-4 py-3">
                    <span
                      className={`inline-flex px-2 py-0.5 text-xs font-medium rounded-full ${priorityConfig?.bgColor || 'bg-gray-100'} ${priorityConfig?.color || 'text-gray-600'}`}
                    >
                      {priorityConfig?.label || ticket.priority}
                    </span>
                  </td>
                  <td className="px-4 py-3">
                    {ticket.assignedTo ? (
                      <span className="text-sm text-gray-900">
                        {ticket.assignedTo.name}
                      </span>
                    ) : (
                      <span className="text-sm text-gray-400 italic">
                        Unassigned
                      </span>
                    )}
                  </td>
                  <td className="px-4 py-3 text-sm text-gray-500">
                    {new Date(ticket.createdAt).toLocaleDateString()}
                  </td>
                  <td className="px-4 py-3 text-sm text-gray-500">
                    {new Date(ticket.updatedAt).toLocaleDateString()}
                  </td>
                </tr>
              );
            })}
          </tbody>
        </table>
      </div>
    </div>
  );
}