import {
ActivityIndicator,
Alert,
Pressable,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import { useReservations } from '@/features/reservations/hooks/useReservations';
export default function ReservationsScreen() {
const {
activeReservations,
historyReservations,
loading,
error,
reload,
cancelReservation,
cancelingReservationId,
} = useReservations();
const handleCancelReservation = (reservationId: string) => {
Alert.alert(
'Cancelar reserva',
'Esta acción marcará la reserva como cancelada.',
[
{ text: 'Volver', style: 'cancel' },
{
text: 'Cancelar reserva',
style: 'destructive',
onPress: () => {
void cancelReservation(reservationId);
},
},
]
);
};
if (loading) {
return (
);
}
if (error) {
return (
{error}
Reintentar
);
}
return (
Mis reservas
Activas
{activeReservations.length === 0 ? (
No tienes reservas activas
) : (
activeReservations.map((item) => (
{item.officeName}
Activa
Fecha: {item.date}
Inicio: {item.startTime}
Fin: {item.endTime}
handleCancelReservation(item.id)}
disabled={cancelingReservationId === item.id}
>
{cancelingReservationId === item.id
? 'Cancelando...'
: 'Cancelar reserva'}
))
)}
Historial
{historyReservations.length === 0 ? (
No tienes reservas en el historial
) : (
historyReservations.map((item) => (
{item.officeName}
{item.status === 'completed' ? 'Completada' : 'Cancelada'}
Fecha: {item.date}
Inicio: {item.startTime}
Fin: {item.endTime}
))
)}
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 16,
},
center: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 24,
},
title: {
fontSize: 28,
fontWeight: '700',
marginBottom: 16,
},
list: {
gap: 12,
paddingBottom: 24,
},
section: {
gap: 12,
},
sectionTitle: {
fontSize: 20,
fontWeight: '700',
},
card: {
borderWidth: 1,
borderColor: '#ddd',
borderRadius: 12,
padding: 16,
gap: 6,
},
cardHeader: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
gap: 12,
},
cardTitle: {
fontSize: 18,
fontWeight: '600',
flex: 1,
},
statusBadge: {
borderRadius: 999,
paddingHorizontal: 10,
paddingVertical: 4,
},
statusActive: {
backgroundColor: '#d7f5df',
},
statusCancelled: {
backgroundColor: '#f3d8d8',
},
statusCompleted: {
backgroundColor: '#dce8f8',
},
statusText: {
fontSize: 12,
fontWeight: '700',
color: '#333',
},
error: {
color: 'red',
marginBottom: 12,
},
button: {
backgroundColor: '#1f6feb',
paddingHorizontal: 16,
paddingVertical: 12,
borderRadius: 10,
},
buttonText: {
color: '#fff',
fontWeight: '600',
},
cancelButton: {
backgroundColor: '#c62828',
paddingVertical: 12,
borderRadius: 10,
alignItems: 'center',
marginTop: 8,
},
empty: {
color: '#666',
},
});