summaryrefslogtreecommitdiffstats
path: root/src/app/(auth)/register.tsx
blob: 902c752e60b62d291eb02b27954fd46d9b348aae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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';

const { colors, spacing, radius, typography, fontWeight, layout, shadows } = theme;

export default function RegisterScreen() {
  // hook de registro
  const {
    displayName,
    email,
    password,
    setDisplayName,
    setEmail,
    setPassword,
    submit,
    isSubmitting,
    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 */}
      <View style={styles.content}>
        {/* icono superior */}
        <View style={styles.iconBox}>
          <MaterialIcons name="business" size={28} color={colors.white} />
        </View>

        {/* titulo principal */}
        <Text style={styles.title}>Crear cuenta</Text>

        {/* subtitulo */}
        <Text style={styles.subtitle}>Únete a App Oficina hoy mismo</Text>

        {/* tarjeta del formulario */}
        <View style={styles.formCard}>
          {/* campo nombre */}
          <Text style={styles.label}>Nombre completo</Text>
          <TextInput
            style={styles.input}
            placeholder="Ej: Juan Pérez"
            placeholderTextColor={colors.textSecondary}
            value={displayName}
            onChangeText={setDisplayName}
          />

          {/* campo correo */}
          <Text style={styles.label}>Correo electrónico</Text>
          <TextInput
            style={styles.input}
            placeholder="tu@email.com"
            placeholderTextColor={colors.textSecondary}
            autoCapitalize="none"
            keyboardType="email-address"
            value={email}
            onChangeText={setEmail}
          />

          {/* campo contraseña */}
          <Text style={styles.label}>Contraseña</Text>
          <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={handleSubmit}
            disabled={isSubmitting}
          >
            <Text style={styles.buttonText}>
              {isSubmitting ? 'Registrando...' : 'Crear cuenta'}
            </Text>
          </Pressable>
        </View>

        {/* enlace inferior a login */}
        <Link href="/(auth)/login" style={styles.link}>
          ¿Ya tienes cuenta?{' '}
          <Text style={styles.linkHighlight}>Inicia sesión</Text>
        </Link>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  // contenedor principal de la pantalla
  container: {
    flex: 1,
    backgroundColor: colors.background,
  },

  // contenido central acotado y centrado
  content: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    paddingHorizontal: spacing.xl,
    paddingTop: spacing.xl,
    paddingBottom: spacing.xl,
    gap: spacing.lg,
    maxWidth: layout.contentWidth,
    width: '100%',
    alignSelf: 'center',
  },

  // caja azul del icono superior
  iconBox: {
    width: 56,
    height: 56,
    borderRadius: radius.lg,
    backgroundColor: colors.primary,
    alignItems: 'center',
    justifyContent: 'center',
    alignSelf: 'center',
    ...shadows.card,
  },

  // titulo principal
  title: {
    fontSize: 36,
    fontWeight: fontWeight.semibold,
    color: colors.text,
    textAlign: 'center',
  },

  // subtitulo explicativo
  subtitle: {
    fontSize: typography.md,
    color: colors.textSecondary,
    textAlign: 'center',
    lineHeight: 22,
  },

  // tarjeta del formulario de registro
  formCard: {
    width: '100%',
    backgroundColor: colors.surface,
    borderRadius: radius.xxl,
    borderWidth: 1,
    borderColor: colors.border,
    padding: spacing.lg,
    gap: spacing.md,
    ...shadows.card,
  },

  // texto de etiqueta de los inputs
  label: {
    fontSize: typography.sm,
    color: colors.text,
    fontWeight: fontWeight.medium,
  },

  // input de formulario
  input: {
    borderWidth: 1,
    borderColor: colors.border,
    borderRadius: radius.md,
    paddingHorizontal: spacing.lg,
    paddingVertical: spacing.md,
    backgroundColor: colors.background,
    color: colors.text,
  },

  // boton principal
  button: {
    backgroundColor: colors.primary,
    paddingVertical: spacing.lg,
    borderRadius: radius.md,
    alignItems: 'center',
    justifyContent: 'center',
    marginTop: spacing.sm,
  },

  // texto del boton principal
  buttonText: {
    color: colors.white,
    fontWeight: fontWeight.semibold,
    fontSize: typography.md,
  },

  // enlace inferior
  link: {
    marginTop: spacing.sm,
    fontSize: typography.md,
    color: colors.textSecondary,
    textAlign: 'center',
  },

  // parte destacada del enlace
  linkHighlight: {
    color: colors.primary,
    fontWeight: fontWeight.medium,
  },
});