diff options
| author | Anita <ana.tqtc@gmail.com> | 2026-04-19 19:20:09 +0100 |
|---|---|---|
| committer | Anita <ana.tqtc@gmail.com> | 2026-04-19 19:20:09 +0100 |
| commit | ed52756173468bfe98cdb62d95483b4949b27351 (patch) | |
| tree | 9b7bb8f068abb9f879e4e629ab0892319ed31d29 /src/app/(protected)/reservations/create.tsx | |
| parent | e68c8c3e71b0130b8a749cc40a2760fd71c4040c (diff) | |
feat(reservations): edición de reservas + validación de disponibilidad + mejoras de flujo refs #7
Diffstat (limited to 'src/app/(protected)/reservations/create.tsx')
| -rw-r--r-- | src/app/(protected)/reservations/create.tsx | 250 |
1 files changed, 166 insertions, 84 deletions
diff --git a/src/app/(protected)/reservations/create.tsx b/src/app/(protected)/reservations/create.tsx index 8d03275..4cddd33 100644 --- a/src/app/(protected)/reservations/create.tsx +++ b/src/app/(protected)/reservations/create.tsx @@ -1,4 +1,9 @@ -import { Link, useLocalSearchParams } from 'expo-router'; +import { useCreateReservation } from "@/features/reservations/hooks/useCreateReservation"; +import { useUpdateReservation } from "@/features/reservations/hooks/useUpdateReservation"; +import { StatusMessage } from "@/shared/ui/StatusMessage"; +import theme from "@/theme"; +import { MaterialIcons } from "@expo/vector-icons"; +import { Link, useLocalSearchParams, useRouter } from "expo-router"; import { KeyboardAvoidingView, Platform, @@ -8,27 +13,61 @@ import { Text, TextInput, View, -} from 'react-native'; -import { MaterialIcons } from '@expo/vector-icons'; -import theme from '@/theme'; -import { useCreateReservation } from '@/features/reservations/hooks/useCreateReservation'; -import { StatusMessage } from '@/shared/ui/StatusMessage'; +} from "react-native"; -const { colors, spacing, radius, typography, fontWeight, layout, shadows } = theme; +const { colors, spacing, radius, typography, fontWeight, layout, shadows } = + theme; export default function CreateReservationScreen() { + // router para navegar + const router = useRouter(); + // parametros recibidos al entrar desde otra pantalla const params = useLocalSearchParams<{ + mode?: string; + reservationId?: string; officeId?: string; officeName?: string; + date?: string; + startTime?: string; + endTime?: string; + oldDate?: string; + oldStartTime?: string; + oldEndTime?: string; }>(); + // determinar si estamos en modo crear o editar + const isEditMode = params.mode === "edit"; + + // extraer parametros de creacion const officeId = - typeof params.officeId === 'string' ? params.officeId : undefined; + typeof params.officeId === "string" ? params.officeId : undefined; const officeName = - typeof params.officeName === 'string' ? params.officeName : undefined; + typeof params.officeName === "string" ? params.officeName : undefined; + + // extraer parametros de edicion + const reservationId = + typeof params.reservationId === "string" ? params.reservationId : ""; + const oldDate = typeof params.oldDate === "string" ? params.oldDate : ""; + const oldStartTime = + typeof params.oldStartTime === "string" ? params.oldStartTime : ""; + const oldEndTime = + typeof params.oldEndTime === "string" ? params.oldEndTime : ""; + + // usar el hook correspondiente segun el modo + const createReservation = useCreateReservation({ officeId, officeName }); + const updateReservation = useUpdateReservation({ + reservationId, + officeId: officeId || params.officeId || "", + officeName: officeName || params.officeName || "", + oldDate, + oldStartTime, + oldEndTime, + }); + + // seleccionar el hook activo segun el modo + const hook = isEditMode ? updateReservation : createReservation; - // hook de creacion de reserva const { date, startTime, @@ -36,21 +75,22 @@ export default function CreateReservationScreen() { isFormComplete, isSubmitting, error, - successMessage, setDate, setStartTime, setEndTime, submit, - } = useCreateReservation({ officeId, officeName }); + } = hook; return ( <KeyboardAvoidingView style={styles.container} - behavior={Platform.OS === 'ios' ? 'padding' : undefined} + behavior={Platform.OS === "ios" ? "padding" : undefined} > {/* cabecera superior */} <View style={styles.topBar}> - <Text style={styles.topBarTitle}>Crear reserva</Text> + <Text style={styles.topBarTitle}> + {isEditMode ? "Editar reserva" : "Crear reserva"} + </Text> </View> <ScrollView @@ -60,9 +100,13 @@ export default function CreateReservationScreen() { > {/* texto introductorio */} <View style={styles.introSection}> - <Text style={styles.title}>Nueva reserva</Text> + <Text style={styles.title}> + {isEditMode ? "Editar reserva" : "Nueva reserva"} + </Text> <Text style={styles.subtitle}> - Selecciona el espacio, la fecha y el horario de tu reserva. + {isEditMode + ? "Actualiza el horario de tu reserva." + : "Selecciona el espacio, la fecha y el horario de tu reserva."} </Text> </View> @@ -81,27 +125,29 @@ export default function CreateReservationScreen() { <View style={styles.cardTitleBlock}> <Text style={styles.cardTitle}>Espacio</Text> <Text style={styles.cardSubtitle}> - {officeName ?? 'No indicado'} + {officeName ?? "No indicado"} </Text> </View> </View> </View> {/* enlace para volver a oficinas */} - <View style={styles.changeOfficeRow}> - <Link href="/(protected)/(tabs)/offices" asChild> - <Pressable - style={({ pressed }) => [ - styles.changeOfficeButton, - pressed && styles.changeOfficeButtonPressed, - ]} - > - <Text style={styles.changeOfficeButtonText}> - Cambiar oficina - </Text> - </Pressable> - </Link> - </View> + {!isEditMode && ( + <View style={styles.changeOfficeRow}> + <Link href="/(protected)/(tabs)/offices" asChild> + <Pressable + style={({ pressed }) => [ + styles.changeOfficeButton, + pressed && styles.changeOfficeButtonPressed, + ]} + > + <Text style={styles.changeOfficeButtonText}> + Cambiar oficina + </Text> + </Pressable> + </Link> + </View> + )} </View> {/* tarjeta de condiciones de reserva */} @@ -110,25 +156,15 @@ export default function CreateReservationScreen() { <View style={styles.rulesList}> <View style={styles.ruleRow}> - <MaterialIcons - name="schedule" - size={16} - color={colors.primary} - /> + <MaterialIcons name="schedule" size={16} color={colors.primary} /> <Text style={styles.ruleText}> Horario permitido: de 08:00 a 20:00 </Text> </View> <View style={styles.ruleRow}> - <MaterialIcons - name="timer" - size={16} - color={colors.primary} - /> - <Text style={styles.ruleText}> - Duración mínima: 30 minutos - </Text> + <MaterialIcons name="timer" size={16} color={colors.primary} /> + <Text style={styles.ruleText}>Duración mínima: 30 minutos</Text> </View> <View style={styles.ruleRow}> @@ -137,9 +173,7 @@ export default function CreateReservationScreen() { size={16} color={colors.primary} /> - <Text style={styles.ruleText}> - Duración máxima: 8 horas - </Text> + <Text style={styles.ruleText}>Duración máxima: 8 horas</Text> </View> </View> </View> @@ -153,21 +187,21 @@ export default function CreateReservationScreen() { <Text style={styles.label}>Fecha</Text> {/* en web usamos calendario nativo */} - {Platform.OS === 'web' ? ( + {Platform.OS === "web" ? ( <input type="date" value={date} onChange={(e) => setDate(e.target.value)} - min={new Date().toISOString().split('T')[0]} + min={new Date().toISOString().split("T")[0]} style={{ height: 46, border: `1px solid ${colors.border}`, borderRadius: radius.md, - padding: '0 14px', + padding: "0 14px", fontSize: 14, color: colors.text, backgroundColor: colors.background, - outline: 'none', + outline: "none", }} /> ) : ( @@ -183,9 +217,9 @@ export default function CreateReservationScreen() { )} <Text style={styles.helper}> - {Platform.OS === 'web' - ? 'Selecciona una fecha en el calendario' - : 'Formato: YYYY-MM-DD'} + {Platform.OS === "web" + ? "Selecciona una fecha en el calendario" + : "Formato: YYYY-MM-DD"} </Text> </View> @@ -222,11 +256,8 @@ export default function CreateReservationScreen() { {/* mensajes de error / exito */} {error ? <StatusMessage message={error} /> : null} - {successMessage ? ( - <StatusMessage message={successMessage} tone="success" /> - ) : null} - {/* boton principal de guardar */} + {/* boton principal de guardar / actualizar */} <Pressable style={({ pressed }) => [ styles.primaryButton, @@ -240,10 +271,32 @@ export default function CreateReservationScreen() { disabled={!isFormComplete || isSubmitting} > <Text style={styles.primaryButtonText}> - {isSubmitting ? 'Guardando...' : 'Guardar reserva'} + {isSubmitting + ? isEditMode + ? "Actualizando..." + : "Guardando..." + : isEditMode + ? "Actualizar reserva" + : "Guardar reserva"} </Text> </Pressable> </View> + + {/* boton cancelar fuera de la tarjeta */} + {isEditMode && ( + <Pressable + style={({ pressed }) => [ + styles.cancelButton, + pressed && styles.cancelButtonPressed, + ]} + onPress={() => router.back()} + > + <View style={styles.cancelContent}> + <MaterialIcons name="cancel" size={14} color="#DC2626" /> + <Text style={styles.cancelButtonText}>Cancelar</Text> + </View> + </Pressable> + )} </ScrollView> </KeyboardAvoidingView> ); @@ -271,10 +324,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 @@ -290,8 +343,8 @@ const styles = StyleSheet.create({ paddingBottom: spacing.xxxl, gap: spacing.xl, maxWidth: layout.contentWidth, - width: '100%', - alignSelf: 'center', + width: "100%", + alignSelf: "center", }, // bloque introductorio @@ -326,26 +379,26 @@ const styles = StyleSheet.create({ // tarjeta de condiciones con tono azul suave rulesCard: { - backgroundColor: '#F4F8FF', + backgroundColor: "#F4F8FF", borderRadius: radius.xxl, padding: spacing.lg, borderWidth: 1, - borderColor: '#D7E3F7', + borderColor: "#D7E3F7", gap: spacing.md, }, // cabecera de tarjeta cardHeader: { - flexDirection: 'row', - alignItems: 'flex-start', - justifyContent: 'space-between', + flexDirection: "row", + alignItems: "flex-start", + justifyContent: "space-between", gap: spacing.md, }, // bloque izquierdo de cabecera cardHeaderLeft: { - flexDirection: 'row', - alignItems: 'flex-start', + flexDirection: "row", + alignItems: "flex-start", gap: spacing.md, flex: 1, }, @@ -356,8 +409,8 @@ const styles = StyleSheet.create({ height: 40, borderRadius: radius.md, backgroundColor: colors.primarySoft, - alignItems: 'center', - justifyContent: 'center', + alignItems: "center", + justifyContent: "center", }, // bloque de textos de la tarjeta @@ -382,8 +435,8 @@ const styles = StyleSheet.create({ // boton secundario para cambiar oficina changeOfficeRow: { - width: '100%', - alignItems: 'flex-end', + width: "100%", + alignItems: "flex-end", }, changeOfficeButton: { paddingVertical: spacing.xs, @@ -393,7 +446,7 @@ const styles = StyleSheet.create({ // estado pulsado del boton cambiar oficina changeOfficeButtonPressed: { - backgroundColor: '#EAF2FF', + backgroundColor: "#EAF2FF", }, // texto del boton cambiar oficina @@ -424,8 +477,8 @@ const styles = StyleSheet.create({ // fila de una regla ruleRow: { - flexDirection: 'row', - alignItems: 'center', + flexDirection: "row", + alignItems: "center", gap: spacing.sm, }, @@ -443,7 +496,7 @@ const styles = StyleSheet.create({ // fila de campos de hora timeRow: { - flexDirection: 'row', + flexDirection: "row", gap: spacing.lg, }, @@ -481,19 +534,19 @@ const styles = StyleSheet.create({ backgroundColor: colors.primary, paddingVertical: spacing.lg, borderRadius: radius.md, - alignItems: 'center', - justifyContent: 'center', + alignItems: "center", + justifyContent: "center", marginTop: spacing.sm, }, // estado pulsado del boton principal primaryButtonPressed: { - backgroundColor: '#185DCB', + backgroundColor: "#185DCB", }, // boton deshabilitado primaryButtonDisabled: { - backgroundColor: '#8FB5EC', + backgroundColor: "#8FB5EC", }, // texto del boton principal @@ -502,4 +555,33 @@ const styles = StyleSheet.create({ fontWeight: fontWeight.semibold, fontSize: typography.md, }, -});
\ No newline at end of file + + // boton cancelar reserva + cancelButton: { + paddingVertical: spacing.sm, + paddingHorizontal: spacing.md, + borderRadius: radius.md, + backgroundColor: colors.surface, + alignItems: "center", + justifyContent: "center", + }, + + // estado pulsado del boton cancelar + cancelButtonPressed: { + backgroundColor: "#FEECEC", + }, + + // texto del boton cancelar + cancelButtonText: { + color: "#DC2626", + fontWeight: fontWeight.medium, + fontSize: typography.sm, + }, + + // contenido interno del boton cancelar + cancelContent: { + flexDirection: "row", + alignItems: "center", + gap: spacing.xs, + }, +}); |