summaryrefslogtreecommitdiffstats
path: root/src/app/(protected)/(tabs)/reservations/index.tsx
diff options
context:
space:
mode:
authorAlberto Duarte Delgado <alberto@albertoduarte.com>2026-04-01 17:29:30 +0100
committerAlberto Duarte Delgado <alberto@albertoduarte.com>2026-04-01 17:29:30 +0100
commit47538e50cbad770ddeb998904253afcdd51e20f6 (patch)
tree996350fba5c88744458faa7a969b3136d189bfa3 /src/app/(protected)/(tabs)/reservations/index.tsx
parente22992e29801e04ca4352045c5bd2f36eac1c31c (diff)
disponibilidad de reservas, home mejorado y check-in
Diffstat (limited to 'src/app/(protected)/(tabs)/reservations/index.tsx')
-rw-r--r--src/app/(protected)/(tabs)/reservations/index.tsx74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/app/(protected)/(tabs)/reservations/index.tsx b/src/app/(protected)/(tabs)/reservations/index.tsx
index ccec7e9..59d2cad 100644
--- a/src/app/(protected)/(tabs)/reservations/index.tsx
+++ b/src/app/(protected)/(tabs)/reservations/index.tsx
@@ -9,6 +9,49 @@ import {
} from 'react-native';
import { useReservations } from '@/features/reservations/hooks/useReservations';
+function getReservationWindowStart(date: string, startTime: string): Date {
+ return new Date(`${date}T${startTime}:00`);
+}
+
+function getReservationWindowEnd(date: string, endTime: string): Date {
+ return new Date(`${date}T${endTime}:00`);
+}
+
+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);
+
+ return now >= checkInOpensAt && now <= reservationEnd;
+}
+
+function hasToDate(value: unknown): value is { toDate: () => Date } {
+ return (
+ !!value &&
+ typeof value === 'object' &&
+ 'toDate' in value &&
+ typeof value.toDate === 'function'
+ );
+}
+
+function formatCheckInAt(value: unknown): string {
+ if (!hasToDate(value)) {
+ return 'Registrada';
+ }
+
+ const date = value.toDate();
+
+ if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
+ return 'Registrada';
+ }
+
+ return new Intl.DateTimeFormat('es-ES', {
+ dateStyle: 'short',
+ timeStyle: 'short',
+ }).format(date);
+}
+
export default function ReservationsScreen() {
const {
activeReservations,
@@ -18,6 +61,8 @@ export default function ReservationsScreen() {
reload,
cancelReservation,
cancelingReservationId,
+ checkingInReservationId,
+ checkInReservation,
} = useReservations();
const handleCancelReservation = (reservationId: string) => {
@@ -83,6 +128,25 @@ export default function ReservationsScreen() {
<Text>Fecha: {item.date}</Text>
<Text>Inicio: {item.startTime}</Text>
<Text>Fin: {item.endTime}</Text>
+ <Text>
+ Llegada: {item.checkInAt ? formatCheckInAt(item.checkInAt) : 'Pendiente'}
+ </Text>
+
+ {!item.checkInAt && canCheckIn(item.date, item.startTime, item.endTime) ? (
+ <Pressable
+ style={styles.checkInButton}
+ onPress={() => {
+ void checkInReservation(item.id);
+ }}
+ disabled={checkingInReservationId === item.id}
+ >
+ <Text style={styles.buttonText}>
+ {checkingInReservationId === item.id
+ ? 'Registrando llegada...'
+ : 'He llegado'}
+ </Text>
+ </Pressable>
+ ) : null}
<Pressable
style={styles.cancelButton}
@@ -126,6 +190,9 @@ export default function ReservationsScreen() {
<Text>Fecha: {item.date}</Text>
<Text>Inicio: {item.startTime}</Text>
<Text>Fin: {item.endTime}</Text>
+ <Text>
+ Llegada: {item.checkInAt ? formatCheckInAt(item.checkInAt) : 'No registrada'}
+ </Text>
</View>
))
)}
@@ -220,6 +287,13 @@ const styles = StyleSheet.create({
alignItems: 'center',
marginTop: 8,
},
+ checkInButton: {
+ backgroundColor: '#2e7d32',
+ paddingVertical: 12,
+ borderRadius: 10,
+ alignItems: 'center',
+ marginTop: 8,
+ },
empty: {
color: '#666',
},