feat: Implement alert system and network connectivity handling, refactor error handling across screens

This commit is contained in:
2026-01-30 12:38:25 +01:00
parent 9bb8279631
commit 7a6a7f5d35
14 changed files with 277 additions and 40 deletions

View File

@ -1,7 +1,8 @@
import { useAlert } from '@/components/AlertComponent';
import { Download, FileText, Plus, Search, Calendar as CalendarIcon, ChevronLeft } from 'lucide-react-native';
import React, { useCallback, useEffect, useState } from 'react';
import { RangePickerModal } from '@/components/RangePickerModal';
import { Alert, RefreshControl, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native';
import { RefreshControl, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native';
import { useLocalSearchParams, useRouter } from 'expo-router';
import { ConstructionSite, DocumentItem } from '@/types/types';
import LoadingScreen from '@/components/LoadingScreen';
@ -13,6 +14,7 @@ import AddDocumentModal from '@/components/AddDocumentModal';
export default function SiteDocumentsScreen() {
const router = useRouter();
const alert = useAlert();
const params = useLocalSearchParams();
const [site, setSite] = useState<ConstructionSite | null>(null);
const [documents, setDocuments] = useState<DocumentItem[]>([]);
@ -34,7 +36,7 @@ export default function SiteDocumentsScreen() {
setDocuments(response.data);
} catch (error) {
console.error('Errore nel recupero dei documenti del cantiere:', error);
Alert.alert('Errore', 'Impossibile recuperare i documenti del cantiere. Riprova più tardi.');
alert.showAlert('error', 'Errore', 'Impossibile recuperare i documenti del cantiere. Riprova più tardi.');
} finally {
setIsLoading(false);
setRefreshing(false);
@ -99,7 +101,7 @@ export default function SiteDocumentsScreen() {
await downloadAndShareDocument(mimetype, fileName, fileUrl);
} catch (error) {
console.error('Errore nel download/condivisione del documento:', error);
Alert.alert('Errore', 'Impossibile scaricare il documento. Riprova più tardi.');
alert.showAlert('error', 'Errore', 'Impossibile scaricare il documento. Riprova più tardi.');
}
};
@ -108,12 +110,12 @@ export default function SiteDocumentsScreen() {
setIsUploading(true);
try {
await uploadDocument(file, Number(params.id), customTitle);
Alert.alert('Successo', 'Documento caricato con successo!');
alert.showAlert('success', 'Successo', 'Documento caricato con successo!');
setShowUploadModal(false);
fetchSiteDocuments(Number(params.id), true);
} catch (error) {
console.error('Errore nel caricamento del documento:', error);
Alert.alert('Errore', 'Impossibile caricare il documento. Riprova più tardi.');
alert.showAlert('error', 'Errore', 'Impossibile caricare il documento. Riprova più tardi.');
} finally {
setIsUploading(false);
}