From 5719daa84b8361015a561de76c3db2ab63b5ea5c Mon Sep 17 00:00:00 2001 From: lorentz Date: Tue, 17 Mar 2026 23:44:00 -0400 Subject: [PATCH] fix: mobile dashboard priority labels now join priorities table - API: replaced hardcoded wrong map (1=Critical etc) with JOIN on priorities table - API: sorted by count DESC instead of priority value - Frontend: PRIORITY_COLOR/TEXT maps updated to cover all 10 actual Autotask values (1-11) - Middleware: added /api/mobile to publicRoutes (was getting auth-redirected) --- app/api/mobile/dashboard/route.ts | 8 ++++---- app/mobile/dashboard/page.tsx | 22 ++++++++++++++++++++-- middleware.ts | 2 ++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/api/mobile/dashboard/route.ts b/app/api/mobile/dashboard/route.ts index 9ef8e0d..9ae0c69 100644 --- a/app/api/mobile/dashboard/route.ts +++ b/app/api/mobile/dashboard/route.ts @@ -17,10 +17,11 @@ export async function GET() { GROUP BY t.queue_id, q.label ORDER BY count DESC LIMIT 8 `), postgresClient.query(` - SELECT t.priority, COUNT(*) as count + SELECT t.priority, p.label, COUNT(*) as count FROM tickets t + LEFT JOIN priorities p ON p.value = t.priority WHERE t.status != 5 AND t.is_deleted = false - GROUP BY t.priority ORDER BY t.priority + GROUP BY t.priority, p.label ORDER BY count DESC `), postgresClient.query(` SELECT t.id, t.ticket_number, t.title, t.status, t.priority, @@ -55,7 +56,6 @@ export async function GET() { 56: 'Waiting Vendor', 58: 'Waiting Parts', 59: 'Pending Approval', 60: 'In Deployment', 66: 'Closed', 68: 'Resolved', 70: 'Customer Follow-Up', 71: 'Archived', }; - const priorityLabels: Record = { 1: 'Critical', 2: 'High', 3: 'Medium', 4: 'Low' }; const slaRow = sla.rows[0]; @@ -73,7 +73,7 @@ export async function GET() { })), by_priority: byPriority.rows.map(r => ({ priority: parseInt(r.priority), - label: priorityLabels[r.priority] ?? `P${r.priority}`, + label: r.label ?? `P${r.priority}`, count: parseInt(r.count), })), recent: recentActivity.rows, diff --git a/app/mobile/dashboard/page.tsx b/app/mobile/dashboard/page.tsx index b4c266d..ecdaf38 100644 --- a/app/mobile/dashboard/page.tsx +++ b/app/mobile/dashboard/page.tsx @@ -17,10 +17,28 @@ interface DashboardData { } const PRIORITY_COLOR: Record = { - 1: 'bg-red-500', 2: 'bg-orange-400', 3: 'bg-yellow-400', 4: 'bg-slate-300', + 1: 'bg-slate-300', // Standard + 2: 'bg-slate-300', // Medium + 3: 'bg-slate-300', // Standard + 4: 'bg-red-500', // Critical + 6: 'bg-orange-400', // High + 7: 'bg-purple-500', // Security Event + 8: 'bg-yellow-400', // Minor Service + 9: 'bg-orange-500', // Major Service + 10: 'bg-blue-400', // Installation + 11: 'bg-pink-400', // Fast Track }; const PRIORITY_TEXT: Record = { - 1: 'text-red-600', 2: 'text-orange-500', 3: 'text-yellow-600', 4: 'text-slate-500', + 1: 'text-slate-500', // Standard + 2: 'text-slate-500', // Medium + 3: 'text-slate-500', // Standard + 4: 'text-red-600', // Critical + 6: 'text-orange-500', // High + 7: 'text-purple-600', // Security Event + 8: 'text-yellow-600', // Minor Service + 9: 'text-orange-600', // Major Service + 10: 'text-blue-600', // Installation + 11: 'text-pink-600', // Fast Track }; function pct(n: number, d: number) { diff --git a/middleware.ts b/middleware.ts index 1b0e8fd..44392ae 100644 --- a/middleware.ts +++ b/middleware.ts @@ -20,6 +20,8 @@ const publicRoutes = [ "/api/integrations/status", // Legal pages required by Intuit "/legal", + // Mobile app API endpoints + "/api/mobile", // OpenClaw external agent API (auth via x-openclaw-key header) "/api/openclaw", // Sync endpoints called by scheduler