diff options
| author | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-04-19 21:46:46 +0100 |
|---|---|---|
| committer | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-04-19 21:46:46 +0100 |
| commit | be90a5f202f80bb423c6e0aaf1c4d5feca668f01 (patch) | |
| tree | c91081a6c60d2f1efb4de22c324721c5d798e3ee /src/app/(auth)/register.tsx | |
| parent | 40cc6cea25d048c2e77e11bbfea0cd1e5eb784f6 (diff) | |
| parent | 4d0962a44715f71acd2fc9ea59bf87d8da70f662 (diff) | |
Merge branch 'feature/anita' into develop
Diffstat (limited to 'src/app/(auth)/register.tsx')
| -rw-r--r-- | src/app/(auth)/register.tsx | 85 |
1 files changed, 75 insertions, 10 deletions
diff --git a/src/app/(auth)/register.tsx b/src/app/(auth)/register.tsx index 0b57ce5..902c752 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 { MaterialIcons } from '@expo/vector-icons'; +import { useState } from 'react'; import theme from '@/theme'; import { useRegister } from '@/features/auth/hooks/useRegister'; import { StatusMessage } from '@/shared/ui/StatusMessage'; @@ -21,6 +22,27 @@ export default function RegisterScreen() { error, } = useRegister(); + // estado para confirmar contraseña + const [confirmPassword, setConfirmPassword] = useState(''); + + // estados para mostrar/ocultar contraseña + const [showPassword, setShowPassword] = useState(false); + const [showConfirmPassword, setShowConfirmPassword] = useState(false); + + // error local (frontend) + const [localError, setLocalError] = useState<string | null>(null); + + const handleSubmit = () => { + setLocalError(null); + + if (password !== confirmPassword) { + setLocalError('Las contraseñas no coinciden'); + return; + } + + submit(); + }; + return ( <View style={styles.container}> {/* contenido central acotado */} @@ -62,20 +84,62 @@ export default function RegisterScreen() { {/* campo contraseña */} <Text style={styles.label}>Contraseña</Text> - <TextInput - style={styles.input} - placeholder="Mínimo 8 caracteres" - placeholderTextColor={colors.textSecondary} - secureTextEntry - value={password} - onChangeText={setPassword} - /> + <View style={styles.inputWrapper}> + <TextInput + style={styles.inputWithIcon} + placeholder="Mínimo 8 caracteres" + placeholderTextColor={colors.textSecondary} + secureTextEntry={!showPassword} + value={password} + onChangeText={setPassword} + /> + + <Pressable + onPress={() => setShowPassword((prev) => !prev)} + style={styles.iconButton} + > + <MaterialIcons + name={showPassword ? 'visibility-off' : 'visibility'} + size={20} + color={colors.textSecondary} + /> + </Pressable> + </View> + + {/* campo confirmar contraseña */} + <Text style={styles.label}>Confirmar contraseña</Text> + <View style={styles.inputWrapper}> + <TextInput + style={styles.inputWithIcon} + placeholder="Repite la contraseña" + placeholderTextColor={colors.textSecondary} + secureTextEntry={!showConfirmPassword} + value={confirmPassword} + onChangeText={setConfirmPassword} + /> + + <Pressable + onPress={() => setShowConfirmPassword((prev) => !prev)} + style={styles.iconButton} + > + <MaterialIcons + name={showConfirmPassword ? 'visibility-off' : 'visibility'} + size={20} + color={colors.textSecondary} + /> + </Pressable> + </View> {/* mensaje de error */} + {localError ? <StatusMessage message={localError} /> : null} {error ? <StatusMessage message={error} /> : null} {/* boton principal */} - <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}> + <Pressable + style={styles.button} + onPress={handleSubmit} + disabled={isSubmitting} + > <Text style={styles.buttonText}> {isSubmitting ? 'Registrando...' : 'Crear cuenta'} </Text> @@ -84,7 +148,8 @@ export default function RegisterScreen() { {/* enlace inferior a login */} <Link href="/(auth)/login" style={styles.link}> - ¿Ya tienes cuenta? <Text style={styles.linkHighlight}>Inicia sesión</Text> + ¿Ya tienes cuenta?{' '} + <Text style={styles.linkHighlight}>Inicia sesión</Text> </Link> </View> </View> |