feat: Implement alert system and network connectivity handling, refactor error handling across screens
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { Building2, ChevronRight, MapPin, Search } from 'lucide-react-native';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Alert, RefreshControl, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
||||
import { RefreshControl, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
||||
import { useRouter } from 'expo-router';
|
||||
import api from '@/utils/api';
|
||||
import LoadingScreen from '@/components/LoadingScreen';
|
||||
import { ConstructionSite } from '@/types/types';
|
||||
import { useAlert } from '@/components/AlertComponent';
|
||||
|
||||
export default function SitesScreen() {
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
@ -12,6 +13,7 @@ export default function SitesScreen() {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const router = useRouter();
|
||||
const alert = useAlert();
|
||||
|
||||
// Fetch cantieri e documenti
|
||||
const fetchConstructionSites = async () => {
|
||||
@ -23,7 +25,7 @@ export default function SitesScreen() {
|
||||
setConstructionSites(response.data);
|
||||
} catch (error) {
|
||||
console.error('Errore nel recupero dei cantieri:', error);
|
||||
Alert.alert('Errore', 'Impossibile recuperare i cantieri. Riprova più tardi.');
|
||||
alert.showAlert('error', 'Errore', 'Impossibile recuperare i cantieri. Riprova più tardi.');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
setRefreshing(false);
|
||||
|
||||
Reference in New Issue
Block a user