195 lines
8.1 KiB
TypeScript
195 lines
8.1 KiB
TypeScript
'use client';
|
|
|
|
import {
|
|
Wrench,
|
|
Layers,
|
|
Clock,
|
|
ShieldCheck,
|
|
Building2,
|
|
} from 'lucide-react';
|
|
import { cn } from '@/lib/utils';
|
|
import Link from 'next/link';
|
|
import { DashboardHeaderNav } from '@/components/dashboard/DashboardHeaderNav';
|
|
import { useDashboardData } from '@/components/dashboard/useDashboardData';
|
|
import {
|
|
CARD,
|
|
formatInr,
|
|
CardTitle,
|
|
DeltaPill,
|
|
} from '@/components/dashboard/DashboardShared';
|
|
|
|
export default function TechnicianDashboardPage() {
|
|
const {
|
|
stats: displayStats,
|
|
loading,
|
|
refreshing,
|
|
userName,
|
|
fetchData,
|
|
} = useDashboardData();
|
|
|
|
const byStatus = displayStats.orders_by_status ?? {};
|
|
const countOf = (key: string) => byStatus[key] ?? 0;
|
|
const totalOrders = displayStats.total_orders ?? 0;
|
|
const delivered = countOf('delivered');
|
|
const conversionDelta = 15.5;
|
|
|
|
if (loading) {
|
|
return (
|
|
<div className="flex flex-col gap-4 animate-pulse">
|
|
<div className="h-8 w-48 bg-muted crm-radius-section" />
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4">
|
|
{[...Array(4)].map((_, i) => (
|
|
<div key={i} className="h-28 bg-muted crm-radius-section" />
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-col gap-4">
|
|
<DashboardHeaderNav
|
|
title="Technician Workshop Dashboard"
|
|
subtitle="Device service queue, repair job compatibility matrix, and workshop throughput"
|
|
userName={userName}
|
|
refreshing={refreshing}
|
|
onRefresh={() => fetchData(true)}
|
|
/>
|
|
|
|
{/* KPI Cards Row */}
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4">
|
|
<div className={cn(CARD, 'p-4')}>
|
|
<div className="flex items-start justify-between">
|
|
<div>
|
|
<p className="text-[13px] text-muted-foreground">Supported Device Models</p>
|
|
<p className="text-[22px] font-bold text-foreground mt-2 tracking-tight">
|
|
{displayStats.total_device_models}
|
|
</p>
|
|
</div>
|
|
<span className="w-10 h-10 rounded-full bg-primary text-white flex items-center justify-center shrink-0">
|
|
<Wrench className="w-5 h-5" />
|
|
</span>
|
|
</div>
|
|
<div className="mt-2 flex items-center gap-2">
|
|
<span className="text-[12px] text-muted-foreground">Repair compatibility list</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={cn(CARD, 'p-4')}>
|
|
<div className="flex items-start justify-between">
|
|
<div>
|
|
<p className="text-[13px] text-muted-foreground">Supported Device Series</p>
|
|
<p className="text-[22px] font-bold text-foreground mt-2 tracking-tight">
|
|
{displayStats.total_device_series}
|
|
</p>
|
|
</div>
|
|
<span className="w-10 h-10 rounded-full bg-indigo-600 text-white flex items-center justify-center shrink-0">
|
|
<Layers className="w-5 h-5" />
|
|
</span>
|
|
</div>
|
|
<div className="mt-2 flex items-center gap-2">
|
|
<span className="text-[12px] text-muted-foreground">Across {displayStats.total_brands} brands</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={cn(CARD, 'p-4')}>
|
|
<div className="flex items-start justify-between">
|
|
<div>
|
|
<p className="text-[13px] text-muted-foreground">Service Intake Orders</p>
|
|
<p className="text-[22px] font-bold text-foreground mt-2 tracking-tight">{totalOrders}</p>
|
|
</div>
|
|
<span className="w-10 h-10 rounded-full bg-amber-600 text-white flex items-center justify-center shrink-0">
|
|
<Clock className="w-5 h-5" />
|
|
</span>
|
|
</div>
|
|
<div className="mt-2 flex items-center gap-2">
|
|
<span className="text-[12px] text-muted-foreground">Warranty & repair jobs</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={cn(CARD, 'p-4')}>
|
|
<div className="flex items-start justify-between">
|
|
<div>
|
|
<p className="text-[13px] text-muted-foreground">Completed Services</p>
|
|
<p className="text-[22px] font-bold text-foreground mt-2 tracking-tight">{delivered}</p>
|
|
</div>
|
|
<span className="w-10 h-10 rounded-full bg-emerald-600 text-white flex items-center justify-center shrink-0">
|
|
<ShieldCheck className="w-5 h-5" />
|
|
</span>
|
|
</div>
|
|
<div className="mt-2 flex items-center gap-2">
|
|
<DeltaPill value={conversionDelta} />
|
|
<span className="text-[12px] text-muted-foreground">Inspected & delivered</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Workshop Queue & Compatibility Matrix */}
|
|
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
|
<div className={cn(CARD, 'lg:col-span-2 p-5 flex flex-col')}>
|
|
<div className="flex items-center justify-between gap-2 mb-3">
|
|
<CardTitle>Technician Service Queue</CardTitle>
|
|
<Link href="/services/intake" className="text-xs font-semibold text-primary hover:underline">
|
|
Open Repair Intake
|
|
</Link>
|
|
</div>
|
|
<div className="overflow-x-auto">
|
|
<table className="crm-data-table min-w-[500px]">
|
|
<thead>
|
|
<tr className="border-y border-border">
|
|
<th className="text-left font-medium text-muted-foreground px-4 py-2">Job Ref</th>
|
|
<th className="text-left font-medium text-muted-foreground px-4 py-2">Customer</th>
|
|
<th className="text-left font-medium text-muted-foreground px-4 py-2">Repair Status</th>
|
|
<th className="text-left font-medium text-muted-foreground px-4 py-2">Value</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{(displayStats.recent_orders ?? []).map((order) => (
|
|
<tr key={order.order_no} className="border-b border-border last:border-0">
|
|
<td className="px-4 py-2.5 font-semibold text-foreground">{order.order_no}</td>
|
|
<td className="px-4 py-2.5 text-foreground">{order.customer_name}</td>
|
|
<td className="px-4 py-2.5">
|
|
<span className="inline-flex items-center h-5 px-2 rounded-full text-[10px] font-semibold bg-amber-500/10 text-amber-600 border border-amber-500/20 capitalize">
|
|
{order.status}
|
|
</span>
|
|
</td>
|
|
<td className="px-4 py-2.5 font-bold text-foreground">{formatInr(order.amount)}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={cn(CARD, 'p-5 flex flex-col')}>
|
|
<CardTitle>Device Repair Matrix</CardTitle>
|
|
<div className="mt-4 space-y-3.5 flex-1">
|
|
<div className="p-3 rounded-lg bg-card border border-border flex items-center justify-between">
|
|
<div>
|
|
<p className="text-xs text-muted-foreground">Device Models Configured</p>
|
|
<p className="text-base font-bold text-foreground mt-0.5">{displayStats.total_device_models}</p>
|
|
</div>
|
|
<Wrench className="w-5 h-5 text-primary" />
|
|
</div>
|
|
|
|
<div className="p-3 rounded-lg bg-card border border-border flex items-center justify-between">
|
|
<div>
|
|
<p className="text-xs text-muted-foreground">Device Series Catalog</p>
|
|
<p className="text-base font-bold text-foreground mt-0.5">{displayStats.total_device_series}</p>
|
|
</div>
|
|
<Layers className="w-5 h-5 text-indigo-500" />
|
|
</div>
|
|
|
|
<div className="p-3 rounded-lg bg-card border border-border flex items-center justify-between">
|
|
<div>
|
|
<p className="text-xs text-muted-foreground">Supported Brands</p>
|
|
<p className="text-base font-bold text-foreground mt-0.5">{displayStats.total_brands}</p>
|
|
</div>
|
|
<Building2 className="w-5 h-5 text-amber-500" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|