feat(admin): technician assignment in service list and technician workbench view
This commit is contained in:
parent
1cd5dc7cb6
commit
d94f74b0c2
3 changed files with 108 additions and 3 deletions
|
|
@ -260,13 +260,14 @@ function formatDeviceName(brand?: string, model?: string, fallback = '—') {
|
||||||
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Device / service</th>
|
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Device / service</th>
|
||||||
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Price</th>
|
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Price</th>
|
||||||
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Status</th>
|
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Status</th>
|
||||||
|
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Technician</th>
|
||||||
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Date</th>
|
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Date</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="bg-card">
|
<tbody className="bg-card">
|
||||||
{filteredJobs.length === 0 ? (
|
{filteredJobs.length === 0 ? (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={6} className="text-center py-12 text-[13px] text-muted-foreground">
|
<td colSpan={7} className="text-center py-12 text-[13px] text-muted-foreground">
|
||||||
{searchQuery || queueTab !== 'all' || filterStatus !== 'ALL'
|
{searchQuery || queueTab !== 'all' || filterStatus !== 'ALL'
|
||||||
? 'No jobs match your search.'
|
? 'No jobs match your search.'
|
||||||
: 'No service jobs found.'}
|
: 'No service jobs found.'}
|
||||||
|
|
@ -276,7 +277,9 @@ function formatDeviceName(brand?: string, model?: string, fallback = '—') {
|
||||||
pager.items.map((job) => (
|
pager.items.map((job) => (
|
||||||
<tr key={job.job_id} className="border-t border-border hover:bg-muted/10">
|
<tr key={job.job_id} className="border-t border-border hover:bg-muted/10">
|
||||||
<td className="px-5 py-3.5 text-[13px] font-semibold text-foreground font-mono">
|
<td className="px-5 py-3.5 text-[13px] font-semibold text-foreground font-mono">
|
||||||
{job.job_no || job.job_id}
|
<Link href={`/technician?job_id=${job.job_id}`} className="hover:underline text-primary">
|
||||||
|
{job.job_no || job.job_id}
|
||||||
|
</Link>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-5 py-3.5">
|
<td className="px-5 py-3.5">
|
||||||
<p className="text-[13px] font-medium text-foreground">{job.customer_name || 'Guest customer'}</p>
|
<p className="text-[13px] font-medium text-foreground">{job.customer_name || 'Guest customer'}</p>
|
||||||
|
|
@ -300,6 +303,20 @@ function formatDeviceName(brand?: string, model?: string, fallback = '—') {
|
||||||
<td className="px-5 py-3.5">
|
<td className="px-5 py-3.5">
|
||||||
{getStatusBadge(job.status)}
|
{getStatusBadge(job.status)}
|
||||||
</td>
|
</td>
|
||||||
|
<td className="px-5 py-3.5">
|
||||||
|
{job.assigned_technician_name ? (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-semibold bg-emerald-50 text-emerald-700 border border-emerald-200">
|
||||||
|
{job.assigned_technician_name}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<Link
|
||||||
|
href={`/technician?job_id=${job.job_id}`}
|
||||||
|
className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-semibold bg-amber-50 text-amber-700 border border-amber-200 hover:bg-amber-100"
|
||||||
|
>
|
||||||
|
Assign Tech
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
<td className="px-5 py-3.5 text-[13px] text-muted-foreground">
|
<td className="px-5 py-3.5 text-[13px] text-muted-foreground">
|
||||||
{job.created_at ? new Date(job.created_at).toLocaleDateString() : '—'}
|
{job.created_at ? new Date(job.created_at).toLocaleDateString() : '—'}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,10 @@ export default function TechnicianPortalPage() {
|
||||||
const [pickupStatus, setPickupStatus] = useState('BOOKED_PICKUP');
|
const [pickupStatus, setPickupStatus] = useState('BOOKED_PICKUP');
|
||||||
const [savingLogistics, setSavingLogistics] = useState(false);
|
const [savingLogistics, setSavingLogistics] = useState(false);
|
||||||
|
|
||||||
|
const [technicians, setTechnicians] = useState<any[]>([]);
|
||||||
|
const [selectedTechId, setSelectedTechId] = useState('');
|
||||||
|
const [assigningTech, setAssigningTech] = useState(false);
|
||||||
|
|
||||||
const [inspectionData, setInspectionData] = useState({
|
const [inspectionData, setInspectionData] = useState({
|
||||||
result: 'CUSTOMER_REPORT_CONFIRMED',
|
result: 'CUSTOMER_REPORT_CONFIRMED',
|
||||||
customer_report: '',
|
customer_report: '',
|
||||||
|
|
@ -239,6 +243,13 @@ export default function TechnicianPortalPage() {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
setJobs(unique);
|
setJobs(unique);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const techList = await adminService.fetchActiveTechnicians();
|
||||||
|
setTechnicians(techList);
|
||||||
|
} catch (tErr: any) {
|
||||||
|
console.warn('Technician list fetch:', tErr.message);
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.warn('Technician queue load:', err.message);
|
console.warn('Technician queue load:', err.message);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -246,6 +257,21 @@ export default function TechnicianPortalPage() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleAssignTechnician = async () => {
|
||||||
|
if (!activeJobId || !selectedTechId) return;
|
||||||
|
setAssigningTech(true);
|
||||||
|
try {
|
||||||
|
await adminService.assignTechnicianToJob(activeJobId, selectedTechId);
|
||||||
|
toast.success('Technician assigned successfully! WhatsApp alert dispatched.');
|
||||||
|
handleSelectJob(activeJobId);
|
||||||
|
loadAssignedJobs();
|
||||||
|
} catch (err: any) {
|
||||||
|
toast.error(err.message || 'Failed to assign technician.');
|
||||||
|
} finally {
|
||||||
|
setAssigningTech(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadAssignedJobs();
|
loadAssignedJobs();
|
||||||
if (targetJobId) {
|
if (targetJobId) {
|
||||||
|
|
@ -260,6 +286,7 @@ export default function TechnicianPortalPage() {
|
||||||
try {
|
try {
|
||||||
const data = await adminService.getServiceJobDetailsAdmin(jobId);
|
const data = await adminService.getServiceJobDetailsAdmin(jobId);
|
||||||
setActiveJob(data);
|
setActiveJob(data);
|
||||||
|
setSelectedTechId(data.assigned_technician_id || '');
|
||||||
setAdditionalCost('0');
|
setAdditionalCost('0');
|
||||||
setCourierName(data.courier_name || '');
|
setCourierName(data.courier_name || '');
|
||||||
setAwbNumber(data.awb_number || '');
|
setAwbNumber(data.awb_number || '');
|
||||||
|
|
@ -567,13 +594,14 @@ export default function TechnicianPortalPage() {
|
||||||
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Device / service</th>
|
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Device / service</th>
|
||||||
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Price</th>
|
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Price</th>
|
||||||
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Status</th>
|
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Status</th>
|
||||||
|
<th className="px-5 py-3 text-left text-[13px] font-semibold text-gray-700">Technician</th>
|
||||||
<th className="px-5 py-3 text-center text-[13px] font-semibold text-gray-700">Action</th>
|
<th className="px-5 py-3 text-center text-[13px] font-semibold text-gray-700">Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="bg-card">
|
<tbody className="bg-card">
|
||||||
{filteredJobs.length === 0 ? (
|
{filteredJobs.length === 0 ? (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={6} className="text-center py-12 text-[13px] text-muted-foreground">
|
<td colSpan={7} className="text-center py-12 text-[13px] text-muted-foreground">
|
||||||
{searchQuery || queueTab !== 'all' ? 'No jobs match your search.' : 'No jobs currently assigned.'}
|
{searchQuery || queueTab !== 'all' ? 'No jobs match your search.' : 'No jobs currently assigned.'}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -601,6 +629,17 @@ export default function TechnicianPortalPage() {
|
||||||
</td>
|
</td>
|
||||||
<td className="px-5 py-3.5 text-[13px] text-muted-foreground">{money(job.base_price)}</td>
|
<td className="px-5 py-3.5 text-[13px] text-muted-foreground">{money(job.base_price)}</td>
|
||||||
<td className="px-5 py-3.5">{renderStatusBadge(job.status)}</td>
|
<td className="px-5 py-3.5">{renderStatusBadge(job.status)}</td>
|
||||||
|
<td className="px-5 py-3.5">
|
||||||
|
{job.assigned_technician_name ? (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-semibold bg-emerald-50 text-emerald-700 border border-emerald-200">
|
||||||
|
{job.assigned_technician_name}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-semibold bg-amber-50 text-amber-700 border border-amber-200">
|
||||||
|
Unassigned
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
<td className="px-5 py-3.5">
|
<td className="px-5 py-3.5">
|
||||||
<div className="flex items-center justify-center">
|
<div className="flex items-center justify-center">
|
||||||
<button
|
<button
|
||||||
|
|
@ -683,6 +722,44 @@ export default function TechnicianPortalPage() {
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Technician Assignment Card */}
|
||||||
|
<div className="p-3 border border-border bg-card crm-radius-card space-y-2.5">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<span className="text-[12px] font-semibold text-foreground flex items-center gap-1.5">
|
||||||
|
<User className="w-3.5 h-3.5 text-primary" /> Assigned Technician
|
||||||
|
</span>
|
||||||
|
{activeJob.assigned_technician_name ? (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-semibold bg-emerald-50 text-emerald-700 border border-emerald-200">
|
||||||
|
{activeJob.assigned_technician_name}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded text-[11px] font-semibold bg-amber-50 text-amber-700 border border-amber-200">
|
||||||
|
Unassigned
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="flex-1">
|
||||||
|
<CustomSelect
|
||||||
|
value={selectedTechId}
|
||||||
|
onChange={(val) => setSelectedTechId(val)}
|
||||||
|
options={[
|
||||||
|
{ value: '', label: 'Select technician' },
|
||||||
|
...technicians.map((t) => ({ value: t.technician_id, label: `${t.name} (${t.role})` })),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={!selectedTechId || assigningTech}
|
||||||
|
onClick={handleAssignTechnician}
|
||||||
|
className="h-9 px-3 crm-radius-control bg-primary hover:bg-primary/90 text-white text-[13px] font-medium cursor-pointer disabled:opacity-50 shrink-0"
|
||||||
|
>
|
||||||
|
{assigningTech ? 'Assigning...' : 'Assign'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{!isUnpaidOnlineDraft(activeJob) && activeJob.status !== 'FINAL_PAYMENT_PENDING' && (
|
{!isUnpaidOnlineDraft(activeJob) && activeJob.status !== 'FINAL_PAYMENT_PENDING' && (
|
||||||
<div>
|
<div>
|
||||||
<label className={labelClass}>Status</label>
|
<label className={labelClass}>Status</label>
|
||||||
|
|
|
||||||
|
|
@ -338,6 +338,17 @@ export const adminService = {
|
||||||
async fetchCustomers(): Promise<any[]> {
|
async fetchCustomers(): Promise<any[]> {
|
||||||
return apiFetch<any[]>('/api/v1/admin/customers');
|
return apiFetch<any[]>('/api/v1/admin/customers');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async fetchActiveTechnicians(): Promise<Array<{ technician_id: string; user_id: string; name: string; email: string; phone: string; role: string }>> {
|
||||||
|
return apiFetch<any[]>('/api/v1/service/technicians/active');
|
||||||
|
},
|
||||||
|
|
||||||
|
async assignTechnicianToJob(jobId: string, technicianId: string, reason?: string): Promise<any> {
|
||||||
|
return apiFetch<any>(`/api/v1/service/jobs/${jobId}/assign-technician`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ technician_id: technicianId, reason }),
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue