Refactor: Implement emergency system plan
This commit is contained in:
@@ -17,17 +17,20 @@ export const useEmergencyData = () => {
|
||||
|
||||
const loadEmergencyData = async () => {
|
||||
if (!isAuthenticated) {
|
||||
console.log('Emergency system: User not authenticated');
|
||||
setError('Usuario no autenticado');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('Emergency system: Loading data for user role:', user?.role);
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
if (isOfficer) {
|
||||
// Load data for officers and admins
|
||||
console.log('Emergency system: Loading officer/admin data');
|
||||
const [incidentsData, alertsData, officersData, statsData] = await Promise.all([
|
||||
isAdmin ? emergencyApi.getAllIncidents({ page: 1, limit: 50 }) : emergencyApi.getMyIncidents(),
|
||||
emergencyApi.getActiveEmergencyAlerts(),
|
||||
@@ -35,21 +38,31 @@ export const useEmergencyData = () => {
|
||||
emergencyApi.getSecurityStats(),
|
||||
]);
|
||||
|
||||
console.log('Emergency system: Data loaded successfully', {
|
||||
incidents: incidentsData,
|
||||
alerts: alertsData,
|
||||
officers: officersData,
|
||||
stats: statsData
|
||||
});
|
||||
|
||||
setIncidents(isAdmin ? (incidentsData as any)?.incidents || incidentsData || [] : incidentsData as Incident[]);
|
||||
setEmergencyAlerts(alertsData);
|
||||
setOfficers(officersData);
|
||||
setEmergencyAlerts(alertsData || []);
|
||||
setOfficers(officersData || []);
|
||||
setStats(statsData);
|
||||
} else {
|
||||
// Regular users can only see their own reported incidents
|
||||
console.log('Emergency system: Loading user incidents');
|
||||
const myIncidents = await emergencyApi.getMyIncidents();
|
||||
setIncidents(myIncidents);
|
||||
console.log('Emergency system: User incidents loaded', myIncidents);
|
||||
setIncidents(myIncidents || []);
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('Error loading emergency data:', error);
|
||||
setError(error.message);
|
||||
console.error('Emergency system: Error loading data:', error);
|
||||
setError(`Error de conexión: ${error.message}`);
|
||||
|
||||
// Use mock data for development/testing
|
||||
// Use comprehensive mock data for development/testing
|
||||
console.log('Emergency system: Using mock data due to API error');
|
||||
setStats({
|
||||
totalIncidents: 15,
|
||||
activeIncidents: 3,
|
||||
@@ -71,6 +84,111 @@ export const useEmergencyData = () => {
|
||||
low: 5
|
||||
}
|
||||
});
|
||||
|
||||
// Mock incidents data
|
||||
const mockIncidents: Incident[] = [
|
||||
{
|
||||
id: '1',
|
||||
type: 'theft',
|
||||
priority: 'high',
|
||||
status: 'pending',
|
||||
title: 'Robo en Plaza Central',
|
||||
description: 'Reporte de robo a turista en la plaza principal',
|
||||
location: {
|
||||
latitude: 18.4861,
|
||||
longitude: -69.9312,
|
||||
address: 'Plaza Central, Punta Cana'
|
||||
},
|
||||
reportedBy: {
|
||||
id: '1',
|
||||
name: 'María González',
|
||||
phone: '+1809-555-0123'
|
||||
},
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString()
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: 'medical',
|
||||
priority: 'critical',
|
||||
status: 'assigned',
|
||||
title: 'Emergencia Médica en Hotel',
|
||||
description: 'Turista con problemas cardíacos',
|
||||
location: {
|
||||
latitude: 18.4856,
|
||||
longitude: -69.9289,
|
||||
address: 'Hotel Paradise, Punta Cana'
|
||||
},
|
||||
reportedBy: {
|
||||
id: '2',
|
||||
name: 'Hotel Paradise Staff',
|
||||
phone: '+1809-555-0456'
|
||||
},
|
||||
assignedOfficer: {
|
||||
id: 'off1',
|
||||
name: 'Sgt. Carlos Medina',
|
||||
badge: 'POL-001'
|
||||
},
|
||||
createdAt: new Date(Date.now() - 30 * 60 * 1000).toISOString(),
|
||||
updatedAt: new Date(Date.now() - 15 * 60 * 1000).toISOString()
|
||||
}
|
||||
];
|
||||
|
||||
// Mock emergency alerts
|
||||
const mockAlerts: EmergencyAlert[] = [
|
||||
{
|
||||
id: 'alert1',
|
||||
type: 'panic',
|
||||
priority: 'critical',
|
||||
status: 'active',
|
||||
location: {
|
||||
latitude: 18.4870,
|
||||
longitude: -69.9320,
|
||||
address: 'Bavaro Beach'
|
||||
},
|
||||
user: {
|
||||
id: '3',
|
||||
name: 'Ana Pérez',
|
||||
phone: '+1809-555-0789'
|
||||
},
|
||||
createdAt: new Date(Date.now() - 5 * 60 * 1000).toISOString()
|
||||
}
|
||||
];
|
||||
|
||||
// Mock officers
|
||||
const mockOfficers: Officer[] = [
|
||||
{
|
||||
id: 'off1',
|
||||
name: 'Sgt. Carlos Medina',
|
||||
badge: 'POL-001',
|
||||
rank: 'Sargento',
|
||||
status: 'busy',
|
||||
location: {
|
||||
latitude: 18.4856,
|
||||
longitude: -69.9289
|
||||
},
|
||||
phone: '+1809-555-1001',
|
||||
assignedIncidents: 1
|
||||
},
|
||||
{
|
||||
id: 'off2',
|
||||
name: 'Of. María Rodríguez',
|
||||
badge: 'POL-002',
|
||||
rank: 'Oficial',
|
||||
status: 'available',
|
||||
location: {
|
||||
latitude: 18.4861,
|
||||
longitude: -69.9312
|
||||
},
|
||||
phone: '+1809-555-1002',
|
||||
assignedIncidents: 0
|
||||
}
|
||||
];
|
||||
|
||||
setIncidents(mockIncidents);
|
||||
setEmergencyAlerts(mockAlerts);
|
||||
setOfficers(mockOfficers);
|
||||
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user