import { View, Text, FlatList, TouchableOpacity, ActivityIndicator, RefreshControl } from 'react-native'; import { useQuery } from '@tanstack/react-query'; import { router } from 'expo-router'; import { api } from '../../../services/api'; // Installations are tickets of type INSTALLATION (or filtered by subject prefix) // We query tickets with type=INSTALLATION if the API supports it, fallback to all open tickets async function fetchInstallations() { try { const res = await api.get('/api/v1/tickets?type=INSTALLATION&limit=50'); return res.data?.data ?? res.data ?? []; } catch { // Fallback: all OPEN tickets const res = await api.get('/api/v1/tickets?status=OPEN&limit=50'); return res.data?.data ?? res.data ?? []; } } const STATUS_STYLE: Record = { OPEN: { bg: '#EFF6FF', text: '#2563EB' }, IN_PROGRESS: { bg: '#FFFBEB', text: '#D97706' }, RESOLVED: { bg: '#F0FDF4', text: '#16A34A' }, CLOSED: { bg: '#F3F4F6', text: '#6B7280' }, }; export default function InstallationsScreen() { const { data, isLoading, refetch, isRefetching } = useQuery({ queryKey: ['installations'], queryFn: fetchInstallations, }); const installations: any[] = data ?? []; return ( {/* Header */} Installations {installations.length} pending {isLoading ? ( ) : ( item.id} refreshControl={} contentContainerStyle={{ padding: 16 }} renderItem={({ item }) => { const statusStyle = STATUS_STYLE[item.status] ?? { bg: '#F3F4F6', text: '#6B7280' }; return ( router.push(`/(app)/installations/${item.id}`)} > {item.subject} {item.status?.replace('_', ' ')} {item.client?.firstName} {item.client?.lastName} {item.createdAt ? new Date(item.createdAt).toLocaleDateString() : ''} {item.client?.address && ( 📍 {item.client.address} )} {/* Confirm button if not yet resolved */} {item.status !== 'RESOLVED' && item.status !== 'CLOSED' && ( router.push(`/(app)/installations/${item.id}`)} > 📷 Confirm Installation )} ); }} ListEmptyComponent={ 🔌 No installations pending All caught up! } /> )} ); }