diff options
| author | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-04-01 13:03:25 +0100 |
|---|---|---|
| committer | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-04-01 13:03:25 +0100 |
| commit | 08ce78dbd97ad792e163482f454f285557c7cdd0 (patch) | |
| tree | 998ce8d7d48f8344d9ec34691809f2482cde5136 /src/app | |
| parent | c927739f8f221feabb6e19af2c2667eda905a2eb (diff) | |
Mejoras de UX y feedback de errores; y, manejo de status de reserva
Diffstat (limited to 'src/app')
| -rw-r--r-- | src/app/(auth)/login.tsx | 6 | ||||
| -rw-r--r-- | src/app/(auth)/register.tsx | 6 | ||||
| -rw-r--r-- | src/app/(protected)/(tabs)/profile/index.tsx | 11 | ||||
| -rw-r--r-- | src/app/(protected)/(tabs)/reservations/index.tsx | 125 | ||||
| -rw-r--r-- | src/app/(protected)/reservations/create.tsx | 167 |
5 files changed, 216 insertions, 99 deletions
diff --git a/src/app/(auth)/login.tsx b/src/app/(auth)/login.tsx index 5664bbf..7457b54 100644 --- a/src/app/(auth)/login.tsx +++ b/src/app/(auth)/login.tsx @@ -1,6 +1,7 @@ import { Link } from 'expo-router'; import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native'; import { useLogin } from '@/features/auth/hooks/useLogin'; +import { StatusMessage } from '@/shared/ui/StatusMessage'; export default function LoginScreen() { const { email, password, setEmail, setPassword, submit, isSubmitting, error } = useLogin(); @@ -26,7 +27,7 @@ export default function LoginScreen() { onChangeText={setPassword} /> - {error ? <Text style={styles.error}>{error}</Text> : null} + {error ? <StatusMessage message={error} /> : null} <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}> <Text style={styles.buttonText}> @@ -71,9 +72,6 @@ const styles = StyleSheet.create({ color: '#fff', fontWeight: '600', }, - error: { - color: 'red', - }, link: { marginTop: 12, }, diff --git a/src/app/(auth)/register.tsx b/src/app/(auth)/register.tsx index 1a39a78..0eeb058 100644 --- a/src/app/(auth)/register.tsx +++ b/src/app/(auth)/register.tsx @@ -1,6 +1,7 @@ import { Link } from 'expo-router'; import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native'; import { useRegister } from '@/features/auth/hooks/useRegister'; +import { StatusMessage } from '@/shared/ui/StatusMessage'; export default function RegisterScreen() { const { @@ -43,7 +44,7 @@ export default function RegisterScreen() { onChangeText={setPassword} /> - {error ? <Text style={styles.error}>{error}</Text> : null} + {error ? <StatusMessage message={error} /> : null} <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}> <Text style={styles.buttonText}> @@ -88,9 +89,6 @@ const styles = StyleSheet.create({ color: '#fff', fontWeight: '600', }, - error: { - color: 'red', - }, link: { marginTop: 12, }, diff --git a/src/app/(protected)/(tabs)/profile/index.tsx b/src/app/(protected)/(tabs)/profile/index.tsx index 1e87f21..760b352 100644 --- a/src/app/(protected)/(tabs)/profile/index.tsx +++ b/src/app/(protected)/(tabs)/profile/index.tsx @@ -12,6 +12,7 @@ import { useAuthSession } from '@/providers/AuthProvider'; import { useProfile } from '@/features/profile/hooks/useProfile'; import { useUpdateProfile } from '@/features/profile/hooks/useUpdateProfile'; import { router } from 'expo-router'; +import { StatusMessage } from '@/shared/ui/StatusMessage'; export default function ProfileScreen() { const { logout } = useAuthSession(); @@ -96,8 +97,8 @@ export default function ProfileScreen() { autoCorrect={false} /> - {updateError ? <Text style={styles.error}>{updateError}</Text> : null} - {successMessage ? <Text style={styles.success}>{successMessage}</Text> : null} + {updateError ? <StatusMessage message={updateError} /> : null} + {successMessage ? <StatusMessage message={successMessage} tone="success" /> : null} <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}> <Text style={styles.buttonText}> @@ -191,9 +192,7 @@ const styles = StyleSheet.create({ fontWeight: '600', }, error: { - color: 'red', - }, - success: { - color: 'green', + color: '#9f1d35', + textAlign: 'center', }, }); diff --git a/src/app/(protected)/(tabs)/reservations/index.tsx b/src/app/(protected)/(tabs)/reservations/index.tsx index a2a0d9d..ccec7e9 100644 --- a/src/app/(protected)/(tabs)/reservations/index.tsx +++ b/src/app/(protected)/(tabs)/reservations/index.tsx @@ -1,8 +1,8 @@ import { ActivityIndicator, Alert, - FlatList, Pressable, + ScrollView, StyleSheet, Text, View, @@ -11,7 +11,8 @@ import { useReservations } from '@/features/reservations/hooks/useReservations'; export default function ReservationsScreen() { const { - reservations, + activeReservations, + historyReservations, loading, error, reload, @@ -59,48 +60,77 @@ export default function ReservationsScreen() { <View style={styles.container}> <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}> - <View style={styles.cardHeader}> - <Text style={styles.cardTitle}>{item.officeName}</Text> - <View - style={[ - styles.statusBadge, - item.status === 'active' ? styles.statusActive : styles.statusCancelled, - ]} - > - <Text style={styles.statusText}> - {item.status === 'active' ? 'Activa' : 'Cancelada'} - </Text> + <ScrollView contentContainerStyle={styles.list}> + <View style={styles.section}> + <Text style={styles.sectionTitle}>Activas</Text> + + {activeReservations.length === 0 ? ( + <Text style={styles.empty}>No tienes reservas activas</Text> + ) : ( + activeReservations.map((item) => ( + <View key={item.id} style={styles.card}> + <View style={styles.cardHeader}> + <Text style={styles.cardTitle}>{item.officeName}</Text> + <View + style={[ + styles.statusBadge, + styles.statusActive, + ]} + > + <Text style={styles.statusText}>Activa</Text> + </View> + </View> + <Text>Fecha: {item.date}</Text> + <Text>Inicio: {item.startTime}</Text> + <Text>Fin: {item.endTime}</Text> + + <Pressable + style={styles.cancelButton} + onPress={() => handleCancelReservation(item.id)} + disabled={cancelingReservationId === item.id} + > + <Text style={styles.buttonText}> + {cancelingReservationId === item.id + ? 'Cancelando...' + : 'Cancelar reserva'} + </Text> + </Pressable> </View> - </View> - <Text>Fecha: {item.date}</Text> - <Text>Inicio: {item.startTime}</Text> - <Text>Fin: {item.endTime}</Text> + )) + )} + </View> + + <View style={styles.section}> + <Text style={styles.sectionTitle}>Historial</Text> - {item.status === 'active' ? ( - <Pressable - style={styles.cancelButton} - onPress={() => handleCancelReservation(item.id)} - disabled={cancelingReservationId === item.id} - > - <Text style={styles.buttonText}> - {cancelingReservationId === item.id - ? 'Cancelando...' - : 'Cancelar reserva'} - </Text> - </Pressable> - ) : null} - </View> - )} - /> + {historyReservations.length === 0 ? ( + <Text style={styles.empty}>No tienes reservas en el historial</Text> + ) : ( + historyReservations.map((item) => ( + <View key={item.id} style={styles.card}> + <View style={styles.cardHeader}> + <Text style={styles.cardTitle}>{item.officeName}</Text> + <View + style={[ + styles.statusBadge, + item.status === 'completed' + ? styles.statusCompleted + : styles.statusCancelled, + ]} + > + <Text style={styles.statusText}> + {item.status === 'completed' ? 'Completada' : 'Cancelada'} + </Text> + </View> + </View> + <Text>Fecha: {item.date}</Text> + <Text>Inicio: {item.startTime}</Text> + <Text>Fin: {item.endTime}</Text> + </View> + )) + )} + </View> + </ScrollView> </View> ); } @@ -123,6 +153,14 @@ const styles = StyleSheet.create({ }, list: { gap: 12, + paddingBottom: 24, + }, + section: { + gap: 12, + }, + sectionTitle: { + fontSize: 20, + fontWeight: '700', }, card: { borderWidth: 1, @@ -153,6 +191,9 @@ const styles = StyleSheet.create({ statusCancelled: { backgroundColor: '#f3d8d8', }, + statusCompleted: { + backgroundColor: '#dce8f8', + }, statusText: { fontSize: 12, fontWeight: '700', diff --git a/src/app/(protected)/reservations/create.tsx b/src/app/(protected)/reservations/create.tsx index 138f0ee..65a16f5 100644 --- a/src/app/(protected)/reservations/create.tsx +++ b/src/app/(protected)/reservations/create.tsx @@ -1,6 +1,16 @@ import { useLocalSearchParams } from 'expo-router'; -import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native'; +import { + KeyboardAvoidingView, + Platform, + Pressable, + ScrollView, + StyleSheet, + Text, + TextInput, + View, +} from 'react-native'; import { useCreateReservation } from '@/features/reservations/hooks/useCreateReservation'; +import { StatusMessage } from '@/shared/ui/StatusMessage'; export default function CreateReservationScreen() { const params = useLocalSearchParams<{ @@ -17,6 +27,7 @@ export default function CreateReservationScreen() { date, startTime, endTime, + isFormComplete, isSubmitting, error, successMessage, @@ -27,60 +38,101 @@ export default function CreateReservationScreen() { } = useCreateReservation({ officeId, officeName }); return ( - <View style={styles.container}> - <Text style={styles.title}>Crear reserva</Text> + <KeyboardAvoidingView + style={styles.container} + behavior={Platform.OS === 'ios' ? 'padding' : undefined} + > + <ScrollView contentContainerStyle={styles.content}> + <Text style={styles.title}>Crear reserva</Text> + <Text style={styles.subtitle}> + Completa la fecha y el horario en formato 24h. + </Text> - <View style={styles.infoBox}> - <Text style={styles.label}>Espacio</Text> - <Text style={styles.value}>{officeName ?? 'No indicado'}</Text> + <View style={styles.infoBox}> + <Text style={styles.label}>Espacio</Text> + <Text style={styles.value}>{officeName ?? 'No indicado'}</Text> + </View> - <Text style={styles.label}>ID oficina</Text> - <Text style={styles.value}>{officeId ?? 'No indicado'}</Text> - </View> + <View style={styles.rulesBox}> + <Text style={styles.rulesTitle}>Condiciones de reserva</Text> + <Text style={styles.rulesText}>Horario permitido: de 08:00 a 20:00</Text> + <Text style={styles.rulesText}>Duración mínima: 30 minutos</Text> + <Text style={styles.rulesText}>Duración máxima: 8 horas</Text> + </View> - <TextInput - style={styles.input} - placeholder="Fecha (YYYY-MM-DD)" - value={date} - onChangeText={setDate} - /> + <View style={styles.field}> + <Text style={styles.label}>Fecha</Text> + <TextInput + style={styles.input} + placeholder="2026-04-01" + value={date} + onChangeText={setDate} + keyboardType="number-pad" + maxLength={10} + /> + <Text style={styles.helper}>Formato: YYYY-MM-DD</Text> + </View> - <TextInput - style={styles.input} - placeholder="Hora inicio (HH:MM)" - value={startTime} - onChangeText={setStartTime} - /> + <View style={styles.row}> + <View style={[styles.field, styles.rowField]}> + <Text style={styles.label}>Hora de inicio</Text> + <TextInput + style={styles.input} + placeholder="09:00" + value={startTime} + onChangeText={setStartTime} + keyboardType="number-pad" + maxLength={5} + /> + <Text style={styles.helper}>Formato 24h</Text> + </View> - <TextInput - style={styles.input} - placeholder="Hora fin (HH:MM)" - value={endTime} - onChangeText={setEndTime} - /> + <View style={[styles.field, styles.rowField]}> + <Text style={styles.label}>Hora de fin</Text> + <TextInput + style={styles.input} + placeholder="10:00" + value={endTime} + onChangeText={setEndTime} + keyboardType="number-pad" + maxLength={5} + /> + <Text style={styles.helper}>Debe ser posterior</Text> + </View> + </View> - {error ? <Text style={styles.error}>{error}</Text> : null} - {successMessage ? <Text style={styles.success}>{successMessage}</Text> : null} + {error ? <StatusMessage message={error} /> : null} + {successMessage ? <StatusMessage message={successMessage} tone="success" /> : null} - <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}> - <Text style={styles.buttonText}> - {isSubmitting ? 'Guardando...' : 'Guardar reserva'} - </Text> - </Pressable> - </View> + <Pressable + style={[styles.button, (!isFormComplete || isSubmitting) && styles.buttonDisabled]} + onPress={submit} + disabled={!isFormComplete || isSubmitting} + > + <Text style={styles.buttonText}> + {isSubmitting ? 'Guardando...' : 'Guardar reserva'} + </Text> + </Pressable> + </ScrollView> + </KeyboardAvoidingView> ); } const styles = StyleSheet.create({ container: { flex: 1, + }, + content: { padding: 16, - gap: 12, + gap: 14, }, title: { fontSize: 28, fontWeight: '700', - marginBottom: 8, + }, + subtitle: { + color: '#555', + marginBottom: 4, }, infoBox: { borderWidth: 1, @@ -90,6 +142,34 @@ const styles = StyleSheet.create({ gap: 6, marginBottom: 8, }, + rulesBox: { + borderWidth: 1, + borderColor: '#d7e3f7', + backgroundColor: '#f4f8ff', + borderRadius: 12, + padding: 12, + gap: 4, + }, + rulesTitle: { + fontSize: 14, + fontWeight: '700', + color: '#1d4f91', + marginBottom: 2, + }, + rulesText: { + color: '#365b86', + fontSize: 13, + }, + field: { + gap: 6, + }, + row: { + flexDirection: 'row', + gap: 12, + }, + rowField: { + flex: 1, + }, label: { fontSize: 14, fontWeight: '700', @@ -106,6 +186,10 @@ const styles = StyleSheet.create({ paddingHorizontal: 14, paddingVertical: 12, }, + helper: { + color: '#666', + fontSize: 12, + }, button: { backgroundColor: '#1f6feb', paddingVertical: 14, @@ -113,14 +197,11 @@ const styles = StyleSheet.create({ alignItems: 'center', marginTop: 8, }, + buttonDisabled: { + backgroundColor: '#8fb5ec', + }, buttonText: { color: '#fff', fontWeight: '600', }, - error: { - color: 'red', - }, - success: { - color: 'green', - }, }); |