import { View, Text, ScrollView, RefreshControl, ActivityIndicator, TouchableOpacity } from 'react-native'; import { useQuery } from '@tanstack/react-query'; import { router } from 'expo-router'; import { api } from '../../services/api'; import { useAuthStore } from '../../stores/authStore'; const PRIORITY_COLOR: Record = { HIGH: '#DC2626', MEDIUM: '#D97706', LOW: '#6B7280' }; const TICKET_STATUS_COLOR: Record = { OPEN: '#2563EB', IN_PROGRESS: '#D97706', RESOLVED: '#16A34A', CLOSED: '#6B7280' }; function KpiCard({ label, value, color, onPress }: { label: string; value: string | number; color: string; onPress?: () => void }) { return ( {label} {value} ); } function QuickAction({ icon, label, onPress }: { icon: string; label: string; onPress: () => void }) { return ( {icon} {label} ); } export default function DashboardScreen() { const { user } = useAuthStore(); const { data, isLoading, refetch, isRefetching } = useQuery({ queryKey: ['dashboard'], queryFn: () => api.get('/api/v1/dashboard/summary').then(r => r.data), }); const greeting = () => { const h = new Date().getHours(); if (h < 12) return 'Good morning'; if (h < 17) return 'Good afternoon'; return 'Good evening'; }; return ( } > {/* Header */} {greeting()}, {user?.firstName ?? 'Field Staff'} 👋 {new Date().toLocaleDateString('en-PH', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })} {isLoading ? ( ) : ( {/* KPIs */} Overview router.push('/(app)/clients')} /> router.push('/(app)/clients')} /> router.push('/(app)/payments')} /> {/* Quick Actions */} Quick Actions router.push('/(app)/payments/record')} /> router.push('/(app)/tickets/create')} /> router.push('/(app)/installations')} /> router.push('/(app)/remittances/submit')} /> {/* Recent Tickets */} Recent Tickets {(data?.recentTickets ?? []).length === 0 ? ( No recent tickets router.push('/(app)/tickets/create')} > Create Ticket ) : ( (data?.recentTickets ?? []).map((t: any) => ( router.push(`/(app)/tickets/${t.id}`)} > {t.subject} {t.priority} {t.clientName ?? 'No client'} {t.status} )) )} )} ); }