/** * @page Service Jobs Dashboard ERP/CRM (`app/(admin)/services/page.tsx`) * @purpose General dashboard queue for active scheduling service jobs, calendars, and technician tracking. */ 'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { adminService } from '@/services/api/adminService'; import { Wrench, Clock, Calendar, CheckCircle, AlertCircle, Loader2, Plus, Filter, FileText, UserCheck } from 'lucide-react'; import { formatCurrency } from '@/lib/utils'; export default function AdminServicesDashboard() { const [jobs, setJobs] = useState([]); const [loading, setLoading] = useState(true); const [errorMsg, setErrorMsg] = useState(null); const [filterStatus, setFilterStatus] = useState('ALL'); useEffect(() => { loadJobs(); }, []); const loadJobs = async () => { setLoading(true); setErrorMsg(null); try { const data = await adminService.listServiceJobs(); // Deduplicate by job_id to prevent React key conflicts const seen = new Set(); const unique = (data as any[]).filter(j => { if (seen.has(j.job_id)) return false; seen.add(j.job_id); return true; }); setJobs(unique); } catch (err: any) { setErrorMsg(err.message || 'Failed to load service job queues.'); } finally { setLoading(false); } }; const filteredJobs = filterStatus === 'ALL' ? jobs : jobs.filter(j => j.status === filterStatus); if (loading) { return (
); } return (
{/* Header section */}

Service Jobs & Repairs

Manage online slot appointments and walk-in counter diagnostics

New Walk-In Intake
{errorMsg && (
{errorMsg}
)} {/* Filter and stats cards */}
Filter Status Queue
{/* Table list */}
{filteredJobs.length > 0 ? ( filteredJobs.map((job) => ( )) ) : ( )}
Job Reference Customer Device / Service Price Current Step Intake Date
{job.job_no} {job.customer_name || 'Guest Customer'} {job.customer_phone && job.customer_phone !== 'N/A' ? job.customer_phone : (job.customer_email && job.customer_email !== 'N/A' ? job.customer_email : '—')} {job.device_brand} {job.device_model} {job.service_name} {formatCurrency(job.base_price)} {new Date(job.created_at).toLocaleDateString()}
No active service jobs match this queue filter.
); }