diff options
Diffstat (limited to 'src/app/(protected)/(tabs)')
| -rw-r--r-- | src/app/(protected)/(tabs)/reservations/index.tsx | 220 |
1 files changed, 128 insertions, 92 deletions
diff --git a/src/app/(protected)/(tabs)/reservations/index.tsx b/src/app/(protected)/(tabs)/reservations/index.tsx index 8eaa80e..e790cb4 100644 --- a/src/app/(protected)/(tabs)/reservations/index.tsx +++ b/src/app/(protected)/(tabs)/reservations/index.tsx @@ -1,4 +1,8 @@ -import { useState } from 'react'; +import { useReservations } from "@/features/reservations/hooks/useReservations"; +import theme from "@/theme"; +import { MaterialIcons } from "@expo/vector-icons"; +import { useRouter } from "expo-router"; +import { useState } from "react"; import { ActivityIndicator, Alert, @@ -8,12 +12,10 @@ import { StyleSheet, Text, View, -} from 'react-native'; -import { MaterialIcons } from '@expo/vector-icons'; -import theme from '@/theme'; -import { useReservations } from '@/features/reservations/hooks/useReservations'; +} from "react-native"; -const { colors, spacing, radius, typography, fontWeight, layout, shadows } = theme; +const { colors, spacing, radius, typography, fontWeight, layout, shadows } = + theme; function getReservationWindowStart(date: string, startTime: string): Date { return new Date(`${date}T${startTime}:00`); @@ -27,7 +29,8 @@ function canCheckIn(date: string, startTime: string, endTime: string): boolean { const now = new Date(); const reservationStart = getReservationWindowStart(date, startTime); const reservationEnd = getReservationWindowEnd(date, endTime); - const checkInOpensAt = new Date(reservationStart.getTime() - 15 * 60 * 1000); + // permitir check-in desde 30 minutos antes de la hora de la reserva + const checkInOpensAt = new Date(reservationStart.getTime() - 30 * 60 * 1000); return now >= checkInOpensAt && now <= reservationEnd; } @@ -35,30 +38,33 @@ function canCheckIn(date: string, startTime: string, endTime: string): boolean { function hasToDate(value: unknown): value is { toDate: () => Date } { return ( !!value && - typeof value === 'object' && - 'toDate' in value && - typeof value.toDate === 'function' + typeof value === "object" && + "toDate" in value && + typeof value.toDate === "function" ); } function formatCheckInAt(value: unknown): string { if (!hasToDate(value)) { - return 'Registrada'; + return "Registrada"; } const date = value.toDate(); if (!(date instanceof Date) || Number.isNaN(date.getTime())) { - return 'Registrada'; + return "Registrada"; } - return new Intl.DateTimeFormat('es-ES', { - dateStyle: 'short', - timeStyle: 'short', + return new Intl.DateTimeFormat("es-ES", { + dateStyle: "short", + timeStyle: "short", }).format(date); } export default function ReservationsScreen() { + // router para navegar a otras pantallas + const router = useRouter(); + // hook principal de reservas const { activeReservations, @@ -73,14 +79,14 @@ export default function ReservationsScreen() { } = useReservations(); // controla la pestaña visible de reservas - const [activeTab, setActiveTab] = useState<'active' | 'history'>('active'); + const [activeTab, setActiveTab] = useState<"active" | "history">("active"); // confirmacion antes de cancelar una reserva // en web usamos window.confirm porque Alert puede no comportarse bien const handleCancelReservation = (reservationId: string) => { - if (Platform.OS === 'web') { + if (Platform.OS === "web") { const confirmed = window.confirm( - 'Esta acción marcará la reserva como cancelada.' + "Esta acción marcará la reserva como cancelada.", ); if (confirmed) { @@ -91,18 +97,18 @@ export default function ReservationsScreen() { } // en movil sigue usando el Alert Alert.alert( - 'Cancelar reserva', - 'Esta acción marcará la reserva como cancelada.', + "Cancelar reserva", + "Esta acción marcará la reserva como cancelada.", [ - { text: 'Volver', style: 'cancel' }, + { text: "Volver", style: "cancel" }, { - text: 'Cancelar reserva', - style: 'destructive', + text: "Cancelar reserva", + style: "destructive", onPress: () => { void cancelReservation(reservationId); }, }, - ] + ], ); }; @@ -145,14 +151,14 @@ export default function ReservationsScreen() { <Pressable style={[ styles.tabButton, - activeTab === 'active' && styles.tabButtonActive, + activeTab === "active" && styles.tabButtonActive, ]} - onPress={() => setActiveTab('active')} + onPress={() => setActiveTab("active")} > <Text style={[ styles.tabButtonText, - activeTab === 'active' && styles.tabButtonTextActive, + activeTab === "active" && styles.tabButtonTextActive, ]} > Activas ({activeReservations.length}) @@ -162,14 +168,14 @@ export default function ReservationsScreen() { <Pressable style={[ styles.tabButton, - activeTab === 'history' && styles.tabButtonActive, + activeTab === "history" && styles.tabButtonActive, ]} - onPress={() => setActiveTab('history')} + onPress={() => setActiveTab("history")} > <Text style={[ styles.tabButtonText, - activeTab === 'history' && styles.tabButtonTextActive, + activeTab === "history" && styles.tabButtonTextActive, ]} > Historial ({historyReservations.length}) @@ -178,7 +184,7 @@ export default function ReservationsScreen() { </View> {/* seccion de reservas activas */} - {activeTab === 'active' ? ( + {activeTab === "active" ? ( <View style={styles.section}> <View style={styles.sectionHeader}> <Text style={styles.sectionTitle}>Activas</Text> @@ -186,7 +192,9 @@ export default function ReservationsScreen() { {activeReservations.length === 0 ? ( <View style={styles.emptyCard}> - <Text style={styles.emptyTitle}>No tienes reservas activas</Text> + <Text style={styles.emptyTitle}> + No tienes reservas activas + </Text> <Text style={styles.emptyText}> Cuando realices una nueva reserva, aparecerá aquí. </Text> @@ -212,7 +220,9 @@ export default function ReservationsScreen() { </View> <View style={[styles.statusBadge, styles.statusActive]}> - <Text style={[styles.statusText, styles.statusTextActive]}> + <Text + style={[styles.statusText, styles.statusTextActive]} + > Activa </Text> </View> @@ -249,7 +259,7 @@ export default function ReservationsScreen() { <Text style={styles.detailText}> {item.checkInAt ? `Llegada registrada: ${formatCheckInAt(item.checkInAt)}` - : 'Llegada pendiente'} + : "Llegada pendiente"} </Text> </View> </View> @@ -257,8 +267,9 @@ export default function ReservationsScreen() { {/* linea separadora antes de acciones */} <View style={styles.cardDivider} /> - {/* boton de check-in visible siempre de forma temporal para ajustar diseño */} - {!item.checkInAt ? ( + {/* boton de check-in solo visible cuando se puede hacer check-in */} + {!item.checkInAt && + canCheckIn(item.date, item.startTime, item.endTime) ? ( <Pressable style={styles.checkInButton} onPress={() => { @@ -268,8 +279,8 @@ export default function ReservationsScreen() { > <Text style={styles.checkInButtonText}> {checkingInReservationId === item.id - ? 'Registrando llegada...' - : 'He llegado'} + ? "Registrando llegada..." + : "He llegado"} </Text> </Pressable> ) : null} @@ -282,6 +293,21 @@ export default function ReservationsScreen() { styles.editButton, pressed && styles.editButtonPressed, ]} + onPress={() => { + // navegar a create en modo edicion, pasando los parametros necesarios + router.push({ + pathname: "/(protected)/reservations/create", + params: { + mode: "edit", + reservationId: item.id, + officeId: item.officeId, + officeName: item.officeName, + oldDate: item.date, + oldStartTime: item.startTime, + oldEndTime: item.endTime, + }, + }); + }} > <Text style={styles.editButtonText}>Editar</Text> </Pressable> @@ -296,9 +322,15 @@ export default function ReservationsScreen() { disabled={cancelingReservationId === item.id} > <View style={styles.cancelContent}> - <MaterialIcons name="cancel" size={14} color="#DC2626" /> + <MaterialIcons + name="cancel" + size={14} + color="#DC2626" + /> <Text style={styles.cancelButtonText}> - {cancelingReservationId === item.id ? 'Cancelando...' : 'Cancelar'} + {cancelingReservationId === item.id + ? "Cancelando..." + : "Cancelar"} </Text> </View> </Pressable> @@ -310,7 +342,7 @@ export default function ReservationsScreen() { ) : null} {/* seccion historial */} - {activeTab === 'history' ? ( + {activeTab === "history" ? ( <View style={styles.section}> <View style={styles.sectionHeader}> <Text style={styles.sectionTitle}>Historial</Text> @@ -339,14 +371,16 @@ export default function ReservationsScreen() { <View style={styles.cardTitleBlock}> <Text style={styles.cardTitle}>{item.officeName}</Text> - <Text style={styles.cardSubtitle}>Reserva finalizada</Text> + <Text style={styles.cardSubtitle}> + Reserva finalizada + </Text> </View> </View> <View style={[ styles.statusBadge, - item.status === 'completed' + item.status === "completed" ? styles.statusCompleted : styles.statusCancelled, ]} @@ -354,12 +388,14 @@ export default function ReservationsScreen() { <Text style={[ styles.statusText, - item.status === 'completed' + item.status === "completed" ? styles.statusTextCompleted : styles.statusTextCancelled, ]} > - {item.status === 'completed' ? 'Completada' : 'Cancelada'} + {item.status === "completed" + ? "Completada" + : "Cancelada"} </Text> </View> </View> @@ -395,7 +431,7 @@ export default function ReservationsScreen() { <Text style={styles.detailText}> {item.checkInAt ? `Llegada registrada: ${formatCheckInAt(item.checkInAt)}` - : 'Llegada no registrada'} + : "Llegada no registrada"} </Text> </View> </View> @@ -431,10 +467,10 @@ const styles = StyleSheet.create({ fontSize: typography.xxl, fontWeight: fontWeight.semibold, color: colors.text, - textAlign: 'left', + textAlign: "left", maxWidth: layout.contentWidth, - width: '100%', - alignSelf: 'center', + width: "100%", + alignSelf: "center", }, // scroll principal @@ -450,15 +486,15 @@ const styles = StyleSheet.create({ paddingBottom: spacing.xxxl, gap: spacing.xl, maxWidth: layout.contentWidth, - width: '100%', - alignSelf: 'center', + width: "100%", + alignSelf: "center", }, // estado de carga / error center: { flex: 1, - alignItems: 'center', - justifyContent: 'center', + alignItems: "center", + justifyContent: "center", padding: spacing.xxxl, gap: spacing.md, backgroundColor: colors.background, @@ -471,9 +507,9 @@ const styles = StyleSheet.create({ // cabecera de seccion sectionHeader: { - flexDirection: 'row', - alignItems: 'center', - justifyContent: 'space-between', + flexDirection: "row", + alignItems: "center", + justifyContent: "space-between", }, // titulo de seccion @@ -485,9 +521,9 @@ const styles = StyleSheet.create({ // fila de pestañas superiores tabsRow: { - flexDirection: 'row', + flexDirection: "row", gap: spacing.sm, - backgroundColor: '#E9EEF5', + backgroundColor: "#E9EEF5", borderRadius: radius.xxl, padding: spacing.xs, }, @@ -497,7 +533,7 @@ const styles = StyleSheet.create({ flex: 1, paddingVertical: spacing.md, borderRadius: radius.xl, - alignItems: 'center', + alignItems: "center", }, // boton activo @@ -531,16 +567,16 @@ const styles = StyleSheet.create({ // cabecera de la tarjeta cardHeader: { - flexDirection: 'row', - alignItems: 'flex-start', - justifyContent: 'space-between', + flexDirection: "row", + alignItems: "flex-start", + justifyContent: "space-between", gap: spacing.md, }, // bloque izquierdo de la cabecera de la card cardHeaderLeft: { - flexDirection: 'row', - alignItems: 'flex-start', + flexDirection: "row", + alignItems: "flex-start", gap: spacing.md, flex: 1, }, @@ -551,8 +587,8 @@ const styles = StyleSheet.create({ height: 40, borderRadius: radius.md, backgroundColor: colors.primarySoft, - alignItems: 'center', - justifyContent: 'center', + alignItems: "center", + justifyContent: "center", }, // bloque de titulo de tarjeta @@ -583,17 +619,17 @@ const styles = StyleSheet.create({ // estado activa statusActive: { - backgroundColor: '#DCFCE7', + backgroundColor: "#DCFCE7", }, // estado completada statusCompleted: { - backgroundColor: '#DBEAFE', + backgroundColor: "#DBEAFE", }, // estado cancelada statusCancelled: { - backgroundColor: '#FEE2E2', + backgroundColor: "#FEE2E2", }, // texto base del estado @@ -604,17 +640,17 @@ const styles = StyleSheet.create({ // color texto activa statusTextActive: { - color: '#166534', + color: "#166534", }, // color texto completada statusTextCompleted: { - color: '#1D4ED8', + color: "#1D4ED8", }, // color texto cancelada statusTextCancelled: { - color: '#B91C1C', + color: "#B91C1C", }, // lista de detalles @@ -624,8 +660,8 @@ const styles = StyleSheet.create({ // fila individual de detalle detailRow: { - flexDirection: 'row', - alignItems: 'center', + flexDirection: "row", + alignItems: "center", gap: spacing.sm, }, @@ -649,7 +685,7 @@ const styles = StyleSheet.create({ paddingHorizontal: spacing.xl, paddingVertical: spacing.md, borderRadius: radius.md, - alignItems: 'center', + alignItems: "center", }, // texto del boton principal @@ -663,7 +699,7 @@ const styles = StyleSheet.create({ backgroundColor: colors.successBg, paddingVertical: spacing.md, borderRadius: radius.md, - alignItems: 'center', + alignItems: "center", marginTop: spacing.xs, }, @@ -676,28 +712,28 @@ const styles = StyleSheet.create({ // fila de acciones secundarias // coloca editar a la izquierda y cancelar a la derecha actionsRow: { - flexDirection: 'row', - justifyContent: 'space-between', - alignItems: 'center', + flexDirection: "row", + justifyContent: "space-between", + alignItems: "center", marginTop: spacing.xs, }, - // boton editar reserva + // boton editar reserva editButton: { paddingVertical: spacing.sm, paddingHorizontal: spacing.md, borderRadius: radius.md, backgroundColor: colors.surface, - alignItems: 'center', - justifyContent: 'center', + alignItems: "center", + justifyContent: "center", }, // estado pulsado del boton editar editButtonPressed: { - backgroundColor: '#EAF2FF', + backgroundColor: "#EAF2FF", }, - // texto del boton editar + // texto del boton editar editButtonText: { color: colors.primary, fontWeight: fontWeight.medium, @@ -710,26 +746,26 @@ const styles = StyleSheet.create({ paddingHorizontal: spacing.md, borderRadius: radius.md, backgroundColor: colors.surface, - alignItems: 'center', - justifyContent: 'center', + alignItems: "center", + justifyContent: "center", }, // estado pulsado del boton cancelar cancelButtonPressed: { - backgroundColor: '#FEECEC', + backgroundColor: "#FEECEC", }, // texto del boton cancelar cancelButtonText: { - color: '#DC2626', + color: "#DC2626", fontWeight: fontWeight.medium, fontSize: typography.sm, }, // contenido interno del boton cancelar cancelContent: { - flexDirection: 'row', - alignItems: 'center', + flexDirection: "row", + alignItems: "center", gap: spacing.xs, }, @@ -760,6 +796,6 @@ const styles = StyleSheet.create({ // error general error: { color: colors.error, - textAlign: 'center', + textAlign: "center", }, -});
\ No newline at end of file +}); |