diff options
| author | Anita <ana.tqtc@gmail.com> | 2026-04-18 19:15:56 +0100 |
|---|---|---|
| committer | Anita <ana.tqtc@gmail.com> | 2026-04-18 19:15:56 +0100 |
| commit | ffe71f502d3388121d1cfdacfa18cbea4895f5da (patch) | |
| tree | 01f509708184e7d9fbdfc3d25664e2283c26b969 /src/app/(auth)/register.tsx | |
| parent | 0284c201ba4e7fb0e619be91104220ae24bcf45d (diff) | |
feat(auth): mejora UX login y register (mostrar contraseña y validación) refs #6
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> |