diff options
| author | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-03-30 17:37:42 +0100 |
|---|---|---|
| committer | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-03-30 17:37:42 +0100 |
| commit | 174f1acd46c4ffbde88c04465e8fa6b6810ce113 (patch) | |
| tree | d0c6705b0130f088e76b7303d394ff2a8d66129c /src/app | |
| parent | 31584b4e5a3a551e2ceb15281a38677c39c46e12 (diff) | |
logica de reservas
Diffstat (limited to 'src/app')
| -rw-r--r-- | src/app/(protected)/(tabs)/reservations/index.tsx | 92 | ||||
| -rw-r--r-- | src/app/(protected)/offices/[officeId].tsx | 18 | ||||
| -rw-r--r-- | src/app/(protected)/offices/\ | 129 | ||||
| -rw-r--r-- | src/app/(protected)/reservations/create.tsx | 110 |
4 files changed, 331 insertions, 18 deletions
diff --git a/src/app/(protected)/(tabs)/reservations/index.tsx b/src/app/(protected)/(tabs)/reservations/index.tsx index 817ec6e..56f7832 100644 --- a/src/app/(protected)/(tabs)/reservations/index.tsx +++ b/src/app/(protected)/(tabs)/reservations/index.tsx @@ -1,10 +1,55 @@ -import { StyleSheet, Text, View } from 'react-native'; +import { + ActivityIndicator, + FlatList, + Pressable, + StyleSheet, + Text, + View, +} from 'react-native'; +import { useReservations } from '@/features/reservations/hooks/useReservations'; export default function ReservationsScreen() { + const { reservations, loading, error, reload } = useReservations(); + + if (loading) { + return ( + <View style={styles.center}> + <ActivityIndicator size="large" /> + </View> + ); + } + + if (error) { + return ( + <View style={styles.center}> + <Text style={styles.error}>{error}</Text> + <Pressable style={styles.button} onPress={reload}> + <Text style={styles.buttonText}>Reintentar</Text> + </Pressable> + </View> + ); + } + return ( <View style={styles.container}> - <Text style={styles.title}>Reservas</Text> - <Text style={styles.text}>Pantalla en construcción.</Text> + <Text style={styles.title}>Mis reservas</Text> + + <FlatList + data={reservations} + keyExtractor={(item) => item.id} + contentContainerStyle={styles.list} + ListEmptyComponent={ + <Text style={styles.empty}>No tienes reservas todavía</Text> + } + renderItem={({ item }) => ( + <View style={styles.card}> + <Text style={styles.cardTitle}>{item.officeName}</Text> + <Text>Fecha: {item.date}</Text> + <Text>Inicio: {item.startTime}</Text> + <Text>Fin: {item.endTime}</Text> + </View> + )} + /> </View> ); } @@ -13,16 +58,47 @@ const styles = StyleSheet.create({ container: { flex: 1, padding: 16, - justifyContent: 'center', + }, + center: { + flex: 1, alignItems: 'center', - gap: 12, + justifyContent: 'center', + padding: 24, }, title: { fontSize: 28, fontWeight: '700', + marginBottom: 16, + }, + list: { + gap: 12, + }, + card: { + borderWidth: 1, + borderColor: '#ddd', + borderRadius: 12, + padding: 16, + gap: 6, + }, + cardTitle: { + fontSize: 18, + fontWeight: '600', + }, + error: { + color: 'red', + marginBottom: 12, + }, + button: { + backgroundColor: '#1f6feb', + paddingHorizontal: 16, + paddingVertical: 12, + borderRadius: 10, + }, + buttonText: { + color: '#fff', + fontWeight: '600', }, - text: { - fontSize: 16, - color: '#555', + empty: { + color: '#666', }, }); diff --git a/src/app/(protected)/offices/[officeId].tsx b/src/app/(protected)/offices/[officeId].tsx index 77fd610..34095c5 100644 --- a/src/app/(protected)/offices/[officeId].tsx +++ b/src/app/(protected)/offices/[officeId].tsx @@ -53,11 +53,21 @@ export default function OfficeDetailScreen() { ) : null} </View> - <Link href="/(protected)/reservations/create" asChild> - <Pressable style={styles.button}> - <Text style={styles.buttonText}>Reservar este espacio</Text> - </Pressable> + <Link + href={{ + pathname: '/(protected)/reservations/create', + params: { + officeId: office.id, + officeName: office.name, + }, + }} + asChild + > + <Pressable style={styles.button}> + <Text style={styles.buttonText}>Reservar este espacio</Text> + </Pressable> </Link> + </View> ); } diff --git a/src/app/(protected)/offices/\ b/src/app/(protected)/offices/\ new file mode 100644 index 0000000..34095c5 --- /dev/null +++ b/src/app/(protected)/offices/\ @@ -0,0 +1,129 @@ +import { Link, useLocalSearchParams } from 'expo-router'; +import { ActivityIndicator, Pressable, StyleSheet, Text, View } from 'react-native'; +import { useOffice } from '@/features/offices/hooks/useOffice'; + +export default function OfficeDetailScreen() { + const params = useLocalSearchParams<{ officeId: string }>(); + const officeId = typeof params.officeId === 'string' ? params.officeId : undefined; + + const { office, loading, error, reload } = useOffice(officeId); + + if (loading) { + return ( + <View style={styles.center}> + <ActivityIndicator size="large" /> + </View> + ); + } + + if (error || !office) { + return ( + <View style={styles.center}> + <Text style={styles.error}>{error ?? 'No se pudo cargar la oficina'}</Text> + + <Pressable style={styles.button} onPress={reload}> + <Text style={styles.buttonText}>Reintentar</Text> + </Pressable> + + <Link href="/(protected)/offices" asChild> + <Pressable style={styles.secondaryButton}> + <Text style={styles.buttonText}>Volver a espacios</Text> + </Pressable> + </Link> + </View> + ); + } + + return ( + <View style={styles.container}> + <Text style={styles.title}>{office.name}</Text> + + <View style={styles.card}> + <Text style={styles.label}>Ubicación</Text> + <Text style={styles.value}>{office.location}</Text> + + <Text style={styles.label}>Capacidad</Text> + <Text style={styles.value}>{office.capacity} personas</Text> + + {office.description ? ( + <> + <Text style={styles.label}>Descripción</Text> + <Text style={styles.value}>{office.description}</Text> + </> + ) : null} + </View> + + <Link + href={{ + pathname: '/(protected)/reservations/create', + params: { + officeId: office.id, + officeName: office.name, + }, + }} + asChild + > + <Pressable style={styles.button}> + <Text style={styles.buttonText}>Reservar este espacio</Text> + </Pressable> + </Link> + + </View> + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + padding: 16, + gap: 16, + }, + center: { + flex: 1, + alignItems: 'center', + justifyContent: 'center', + padding: 24, + gap: 12, + }, + title: { + fontSize: 28, + fontWeight: '700', + }, + card: { + borderWidth: 1, + borderColor: '#ddd', + borderRadius: 12, + padding: 16, + gap: 10, + }, + label: { + fontSize: 14, + fontWeight: '700', + color: '#444', + }, + value: { + fontSize: 16, + color: '#111', + }, + button: { + backgroundColor: '#1f6feb', + paddingVertical: 14, + borderRadius: 10, + alignItems: 'center', + }, + secondaryButton: { + backgroundColor: '#555', + paddingVertical: 14, + paddingHorizontal: 16, + borderRadius: 10, + alignItems: 'center', + }, + buttonText: { + color: '#fff', + fontWeight: '600', + }, + error: { + color: 'red', + textAlign: 'center', + }, +}); diff --git a/src/app/(protected)/reservations/create.tsx b/src/app/(protected)/reservations/create.tsx index c1c88b3..138f0ee 100644 --- a/src/app/(protected)/reservations/create.tsx +++ b/src/app/(protected)/reservations/create.tsx @@ -1,10 +1,72 @@ -import { StyleSheet, Text, View } from 'react-native'; +import { useLocalSearchParams } from 'expo-router'; +import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native'; +import { useCreateReservation } from '@/features/reservations/hooks/useCreateReservation'; export default function CreateReservationScreen() { + const params = useLocalSearchParams<{ + officeId?: string; + officeName?: string; + }>(); + + const officeId = + typeof params.officeId === 'string' ? params.officeId : undefined; + const officeName = + typeof params.officeName === 'string' ? params.officeName : undefined; + + const { + date, + startTime, + endTime, + isSubmitting, + error, + successMessage, + setDate, + setStartTime, + setEndTime, + submit, + } = useCreateReservation({ officeId, officeName }); + return ( <View style={styles.container}> <Text style={styles.title}>Crear reserva</Text> - <Text style={styles.text}>Pantalla en construcción.</Text> + + <View style={styles.infoBox}> + <Text style={styles.label}>Espacio</Text> + <Text style={styles.value}>{officeName ?? 'No indicado'}</Text> + + <Text style={styles.label}>ID oficina</Text> + <Text style={styles.value}>{officeId ?? 'No indicado'}</Text> + </View> + + <TextInput + style={styles.input} + placeholder="Fecha (YYYY-MM-DD)" + value={date} + onChangeText={setDate} + /> + + <TextInput + style={styles.input} + placeholder="Hora inicio (HH:MM)" + value={startTime} + onChangeText={setStartTime} + /> + + <TextInput + style={styles.input} + placeholder="Hora fin (HH:MM)" + value={endTime} + onChangeText={setEndTime} + /> + + {error ? <Text style={styles.error}>{error}</Text> : null} + {successMessage ? <Text style={styles.success}>{successMessage}</Text> : null} + + <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}> + <Text style={styles.buttonText}> + {isSubmitting ? 'Guardando...' : 'Guardar reserva'} + </Text> + </Pressable> </View> ); } @@ -13,16 +75,52 @@ const styles = StyleSheet.create({ container: { flex: 1, padding: 16, - justifyContent: 'center', - alignItems: 'center', gap: 12, }, title: { fontSize: 28, fontWeight: '700', + marginBottom: 8, + }, + infoBox: { + borderWidth: 1, + borderColor: '#ddd', + borderRadius: 12, + padding: 12, + gap: 6, + marginBottom: 8, }, - text: { + label: { + fontSize: 14, + fontWeight: '700', + color: '#444', + }, + value: { fontSize: 16, - color: '#555', + color: '#111', + }, + input: { + borderWidth: 1, + borderColor: '#ccc', + borderRadius: 10, + paddingHorizontal: 14, + paddingVertical: 12, + }, + button: { + backgroundColor: '#1f6feb', + paddingVertical: 14, + borderRadius: 10, + alignItems: 'center', + marginTop: 8, + }, + buttonText: { + color: '#fff', + fontWeight: '600', + }, + error: { + color: 'red', + }, + success: { + color: 'green', }, }); |