feat: Implement alert system and network connectivity handling, refactor error handling across screens
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { useAlert } from '@/components/AlertComponent';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { View, Text, TouchableOpacity, ScrollView, Alert, RefreshControl } from 'react-native';
|
||||
import { View, Text, TouchableOpacity, ScrollView, RefreshControl } from 'react-native';
|
||||
import { QrCode, CheckCircle2, Nfc } from 'lucide-react-native';
|
||||
import QrScanModal from '@/components/QrScanModal';
|
||||
import NfcScanModal from '@/components/NfcScanModal';
|
||||
@ -11,6 +12,7 @@ import NfcManager from 'react-native-nfc-manager';
|
||||
|
||||
export default function AttendanceScreen() {
|
||||
const [scannerType, setScannerType] = useState<'qr' | 'nfc'>('qr');
|
||||
const alert = useAlert();
|
||||
const [showScanner, setShowScanner] = useState(false);
|
||||
const [lastScan, setLastScan] = useState<{ type: string; time: string; site: string } | null>(null);
|
||||
const [attendances, setAttendances] = useState<AttendanceRecord[]>([]);
|
||||
@ -36,7 +38,7 @@ export default function AttendanceScreen() {
|
||||
setAttendances(response.data);
|
||||
} catch (error) {
|
||||
console.error('Errore nel recupero delle presenze:', error);
|
||||
Alert.alert('Errore', 'Impossibile recuperare le presenze. Riprova più tardi.');
|
||||
alert.showAlert('error', 'Errore', 'Impossibile recuperare le presenze. Riprova più tardi.');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
setRefreshing(false);
|
||||
@ -67,23 +69,20 @@ export default function AttendanceScreen() {
|
||||
try {
|
||||
const supported = await NfcManager.isSupported();
|
||||
if (!supported) {
|
||||
Alert.alert('NFC non supportato', 'Il tuo dispositivo non supporta la scansione NFC.');
|
||||
alert.showAlert('warning', 'NFC non supportato', 'Il tuo dispositivo non supporta la scansione NFC.');
|
||||
return;
|
||||
}
|
||||
|
||||
const enabled = await NfcManager.isEnabled();
|
||||
if (!enabled) {
|
||||
Alert.alert('NFC disattivato', 'Per favore attiva l\'NFC nelle impostazioni del dispositivo per continuare.', [
|
||||
{ text: 'OK' },
|
||||
{ text: 'Vai alle impostazioni', onPress: () => NfcManager.goToNfcSetting() }
|
||||
]);
|
||||
alert.showAlert('warning', 'NFC disattivato', 'Per favore attiva l\'NFC nelle impostazioni del dispositivo per continuare.');
|
||||
return;
|
||||
}
|
||||
|
||||
setShowScanner(true);
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
Alert.alert('Errore', 'Impossibile verificare lo stato dell\'NFC.');
|
||||
alert.showAlert('error', 'Errore', 'Impossibile verificare lo stato dell\'NFC.');
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -106,7 +105,7 @@ export default function AttendanceScreen() {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Errore nell\'invio dei dati di scansione:', error);
|
||||
Alert.alert('Errore', 'Impossibile registrare la presenza. Riprova più tardi.');
|
||||
alert.showAlert('error', 'Errore', 'Impossibile registrare la presenza. Riprova più tardi.');
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user