- Backend: FastAPI app with all models, services, schemas, routes - Admin Panel: Next.js dashboard with all modules (CRM, POS, repairs, warranties, billing, notifications, etc.) - Ecommerce: storefront (submodule) + product catalog - AI Agents: .agents/ skill library for Antigravity IDE - Docs: architecture, billing, notification gateway markdown - Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
113 lines
4.9 KiB
TypeScript
113 lines
4.9 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
import { crmService, CrmCustomer } from '@/services/api/crmService';
|
|
import { Wrench, Phone, Mail, Star, RefreshCw } from 'lucide-react';
|
|
import { toast } from 'sonner';
|
|
|
|
export default function ServiceRepairCustomersPage() {
|
|
const [customers, setCustomers] = useState<CrmCustomer[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
loadCustomers();
|
|
}, []);
|
|
|
|
const loadCustomers = async () => {
|
|
try {
|
|
setLoading(true);
|
|
const data = await crmService.getCustomers();
|
|
// Filter customers who have repairs or service tier VIP/PRIORITY/STANDARD
|
|
const svcCusts = data.filter((c) => (c.total_repairs_count || 0) > 0 || c.is_dual_customer || c.service_tier);
|
|
setCustomers(svcCusts);
|
|
} catch (err) {
|
|
toast.error('Failed to load service customers');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="p-6 space-y-6 max-w-7xl mx-auto">
|
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 border-b border-border pb-4">
|
|
<div>
|
|
<h1 className="text-2xl font-bold tracking-tight text-foreground flex items-center gap-2.5">
|
|
<Wrench className="w-7 h-7 text-primary" />
|
|
Service Repair Customers
|
|
</h1>
|
|
<p className="text-xs text-muted-foreground mt-0.5">
|
|
Customer directory for device repair intake, IMEI service history, and VIP service tiers
|
|
</p>
|
|
</div>
|
|
|
|
<button
|
|
onClick={loadCustomers}
|
|
className="w-8 h-8 rounded-lg border border-border bg-card flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted"
|
|
>
|
|
<RefreshCw className="w-4 h-4" />
|
|
</button>
|
|
</div>
|
|
|
|
{loading ? (
|
|
<div className="py-20 text-center text-muted-foreground animate-pulse text-sm">
|
|
Loading Service Repair Customers...
|
|
</div>
|
|
) : customers.length === 0 ? (
|
|
<div className="py-16 text-center bg-card border border-border rounded-xl">
|
|
<Wrench className="w-10 h-10 text-primary mx-auto mb-2 opacity-50" />
|
|
<h3 className="text-sm font-semibold text-foreground">No service customers recorded yet</h3>
|
|
<p className="text-xs text-muted-foreground mt-1">
|
|
Customers will appear here when repair tickets or service quotes are registered.
|
|
</p>
|
|
</div>
|
|
) : (
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
{customers.map((c) => (
|
|
<div key={c.customer_id} className="bg-card border border-border hover:border-primary/40 rounded-xl p-4 shadow-xs space-y-3 flex flex-col justify-between">
|
|
<div className="space-y-2">
|
|
<div className="flex items-start justify-between gap-2">
|
|
<div>
|
|
<h3 className="font-bold text-sm text-foreground flex items-center gap-1.5">
|
|
<span>{c.name || c.first_name || 'Service Customer'}</span>
|
|
</h3>
|
|
<p className="text-[11px] text-muted-foreground">{c.email || 'No email'}</p>
|
|
</div>
|
|
<span className="px-2 py-0.5 rounded-full text-[10px] font-bold bg-primary/10 text-primary">
|
|
{c.service_tier || 'STANDARD'}
|
|
</span>
|
|
</div>
|
|
|
|
<div className="space-y-1 text-xs pt-1">
|
|
<div className="flex items-center gap-1.5 text-foreground font-medium">
|
|
<Phone className="w-3.5 h-3.5 text-muted-foreground" />
|
|
{c.phone}
|
|
</div>
|
|
{c.email && (
|
|
<div className="flex items-center gap-1.5 text-muted-foreground truncate">
|
|
<Mail className="w-3.5 h-3.5 shrink-0" />
|
|
<span className="truncate">{c.email}</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{(c.is_dual_customer || ((c.total_orders_count || 0) > 0 && (c.total_repairs_count || 0) > 0)) && (
|
|
<div className="pt-2">
|
|
<span className="inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full bg-amber-500/10 text-amber-600 border border-amber-500/30 text-[10px] font-bold">
|
|
<Star className="w-3.5 h-3.5 fill-amber-500 text-amber-500" />
|
|
⭐ Gold Star VIP Dual Customer
|
|
</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="pt-3 border-t border-border flex items-center justify-between text-xs text-muted-foreground">
|
|
<span>Total Repairs: {c.total_repairs_count || 0}</span>
|
|
<span className="font-semibold text-foreground">Sales Tier: {c.sales_tier || 'BRONZE'}</span>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|