import { useQuery } from '@tanstack/react-query' import { api } from '@/lib/api-client' import type { RepairTicket } from '@/types/repair' import type { PaginatedResponse } from '@lunarfront/shared/schemas' import { Input } from '@/components/ui/input' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Plus, Search } from 'lucide-react' import { useState } from 'react' const STATUS_COLORS: Record = { new: 'bg-blue-500/10 text-blue-500', in_transit: 'bg-blue-500/10 text-blue-500', intake: 'bg-blue-500/10 text-blue-500', diagnosing: 'bg-yellow-500/10 text-yellow-500', pending_approval: 'bg-yellow-500/10 text-yellow-500', approved: 'bg-orange-500/10 text-orange-500', in_progress: 'bg-orange-500/10 text-orange-500', pending_parts: 'bg-orange-500/10 text-orange-500', ready: 'bg-green-500/10 text-green-500', picked_up: 'bg-muted text-muted-foreground', delivered: 'bg-muted text-muted-foreground', cancelled: 'bg-destructive/10 text-destructive', } const STATUS_LABELS: Record = { new: 'New', in_transit: 'In Transit', intake: 'Intake', diagnosing: 'Diagnosing', pending_approval: 'Pending Approval', approved: 'Approved', in_progress: 'In Progress', pending_parts: 'Pending Parts', ready: 'Ready', picked_up: 'Picked Up', delivered: 'Delivered', cancelled: 'Cancelled', } interface RepairQueuePanelProps { selectedTicketId: string | null onSelectTicket: (id: string) => void onNewIntake: () => void statusFilter: string[] | null } export function RepairQueuePanel({ selectedTicketId, onSelectTicket, onNewIntake, statusFilter }: RepairQueuePanelProps) { const [search, setSearch] = useState('') const { data, isLoading } = useQuery({ queryKey: ['repair-tickets', 'station-queue', search, statusFilter], queryFn: () => api.get>('/v1/repair-tickets', { page: 1, limit: 100, q: search || undefined, sort: 'created_at', order: 'desc', ...(statusFilter ? { status: statusFilter.join(',') } : {}), }), staleTime: 30_000, refetchInterval: 30_000, }) const tickets = data?.data ?? [] function timeAgo(dateStr: string) { const diff = Date.now() - new Date(dateStr).getTime() const hours = Math.floor(diff / 3600000) if (hours < 1) return 'Just now' if (hours < 24) return `${hours}h ago` const days = Math.floor(hours / 24) return `${days}d ago` } return (
setSearch(e.target.value)} className="pl-9 h-9" />
{isLoading ? (
{Array.from({ length: 5 }).map((_, i) => (
))}
) : tickets.length === 0 ? (
No tickets found
) : (
{tickets.map((ticket) => ( ))}
)}
) }