Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4426 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 4426 Rev 5697
Línea 1... Línea -...
1
/* eslint-disable react/prop-types */
-
 
2
import React from "react";
-
 
3
import { useRef, useState, useEffect } from "react";
1
import React, { useRef, useState, useEffect } from 'react'
4
import { useForm } from "react-hook-form";
2
import { useForm } from 'react-hook-form'
5
import styled from "styled-components";
-
 
6
import { axios } from "../../../../utils";
3
import { axios } from '../../../../utils'
7
import FormErrorFeedback from "../../../../shared/form-error-feedback/FormErrorFeedback";
4
import FormErrorFeedback from '../../../../shared/form-error-feedback/FormErrorFeedback'
8
import Recaptcha from "react-recaptcha";
5
import Recaptcha from 'react-recaptcha'
9
import Spinner from "../../../../shared/loading-spinner/Spinner";
6
import Spinner from '../../../../shared/loading-spinner/Spinner'
-
 
7
import styled from 'styled-components'
10
import { Link } from "react-router-dom";
8
import { Link } from 'react-router-dom'
11
import CryptoJSAesJson from "../../../../utils/crypto-js/cryptojs-aes-format";
9
import CryptoJSAesJson from '../../../../utils/crypto-js/cryptojs-aes-format'
12
import SwitchInput from "../../../../account-settings/account-settings/shared/switch-input/SwitchInput";
10
import SwitchInput from '../../../../account-settings/account-settings/shared/switch-input/SwitchInput'
Línea 13... Línea 11...
13
 
11
 
14
const StyledCheck = styled.div`
12
const StyledCheck = styled.div`
15
  display: flex;
13
  display: flex;
16
  flex-direction: column;
14
  flex-direction: column;
Línea 21... Línea 19...
21
    margin-bottom: 1rem;
19
    margin-bottom: 1rem;
22
  }
20
  }
23
  p {
21
  p {
24
    text-align: center;
22
    text-align: center;
25
  }
23
  }
26
`;
24
`
27
const StyledSpinnerContainer = styled.div`
25
const StyledSpinnerContainer = styled.div`
28
  position: absolute;
26
  position: absolute;
29
  left: 0;
27
  left: 0;
30
  top: 0;
28
  top: 0;
31
  width: 100%;
29
  width: 100%;
Línea 33... Línea 31...
33
  background: rgba(255, 255, 255, 0.4);
31
  background: rgba(255, 255, 255, 0.4);
34
  display: flex;
32
  display: flex;
35
  justify-content: center;
33
  justify-content: center;
36
  align-items: center;
34
  align-items: center;
37
  z-index: 300;
35
  z-index: 300;
38
`;
36
`
39
const Signup = ({ captchaKey, addNotification, aes }) => {
37
const Signup = ({ captchaKey, addNotification, aes }) => {
40
 
-
 
41
  const { register, handleSubmit, setError, errors, watch } = useForm({ mode: 'onBlur' });
38
  const { register, handleSubmit, setError, errors, watch } = useForm({
-
 
39
    mode: 'onBlur',
-
 
40
  })
42
  const [termsChecked, setTermsChecked] = useState(false);
41
  const [termsChecked, setTermsChecked] = useState(false)
43
  const [registered, setRegistered] = useState(false);
42
  const [registered, setRegistered] = useState(false)
44
  const [isLoading, setIsLoading] = useState(false);
43
  const [isLoading, setIsLoading] = useState(false)
45
  const [isAdult, setIsAdult] = useState(false);
44
  const [isAdult, setIsAdult] = useState(false)
Línea 46... Línea 45...
46
 
45
 
47
  // Recaptcha
46
  // Recaptcha
48
  const [isVerified, setIsVerified] = useState(false);
47
  const [isVerified, setIsVerified] = useState(false)
49
  const reCaptchaInstance = useRef();
48
  const reCaptchaInstance = useRef()
Línea 50... Línea 49...
50
  const reCaptchaToken = useRef("");
49
  const reCaptchaToken = useRef('')
51
 
50
 
52
  useEffect(() => {
51
  useEffect(() => {
Línea 53... Línea 52...
53
    reCaptchaInstance.current.reset();
52
    reCaptchaInstance.current.reset()
54
  }, []);
53
  }, [])
55
 
54
 
56
  const signupVerifyCallbackHandler = (response) => {
55
  const signupVerifyCallbackHandler = (response) => {
57
    if (response) {
56
    if (response) {
58
      reCaptchaToken.current = response;
57
      reCaptchaToken.current = response
Línea 59... Línea 58...
59
      setIsVerified(true);
58
      setIsVerified(true)
60
    }
59
    }
61
  };
60
  }
62
 
61
 
Línea 63... Línea 62...
63
  const signupExpiredCallbackHandler = () => {
62
  const signupExpiredCallbackHandler = () => {
64
    reCaptchaToken.current = "";
63
    reCaptchaToken.current = ''
65
    setIsVerified(false);
64
    setIsVerified(false)
Línea 66... Línea -...
66
  };
-
 
67
 
65
  }
68
  const onSubmitHandler = async (data) => {
66
 
69
    setIsLoading(true);
67
  const onSubmitHandler = async (data) => {
70
    const formData = new FormData();
68
    setIsLoading(true)
71
 
69
    const formData = new FormData()
72
    Object.entries(data)
70
 
73
      .map(([key, value]) => {
71
    Object.entries(data).map(([key, value]) => {
Línea -... Línea 72...
-
 
72
      if (key === 'email' || key === 'password' || key === 'confirmation')
74
        if (key === "email" || key === "password" || key === "confirmation")
73
        return formData.append(key, CryptoJSAesJson.encrypt(value, aes))
75
          return formData.append(key, CryptoJSAesJson.encrypt(value, aes))
74
      return formData.append(key, value)
76
        return formData.append(key, value);
75
    })
77
      })
76
    formData.append('captcha', reCaptchaToken.current)
78
    formData.append("captcha", reCaptchaToken.current);
77
    formData.append('is_adult', isAdult ? 'y' : 'n')
-
 
78
 
-
 
79
    await axios
79
    formData.append("is_adult", isAdult ? 'y' : 'n');
80
      .post('/signup', formData)
-
 
81
      .then(({ data }) => {
80
 
82
        if (!data.success) {
81
    await axios.post("/signup", formData)
83
          if (typeof data.data !== 'string') {
82
      .then(({ data }) => {
84
            Object.entries(data.data).map(([key, value]) => {
83
        if (!data.success) {
85
              setError(key, {
84
          if (typeof data.data !== "string") {
86
                type: 'manual',
85
            Object.entries(data.data).map(([key, value]) => {
87
                message: Array.isArray(value) ? value[0] : value,
86
              setError(key, { type: "manual", message: Array.isArray(value) ? value[0] : value })
88
              })
Línea 87... Línea 89...
87
            })
89
            })
88
          }
90
          }
89
          addNotification({ style: "danger", msg: data.data })
91
          addNotification({ style: 'danger', msg: data.data })
90
          reCaptchaInstance.current.reset()
92
          reCaptchaInstance.current.reset()
91
          signupVerifyCallbackHandler()
93
          signupVerifyCallbackHandler()
-
 
94
          return
-
 
95
        }
92
          return
96
 
-
 
97
        reCaptchaInstance.current.reset()
93
        }
98
        signupExpiredCallbackHandler()
94
 
99
        setRegistered(true)
95
        reCaptchaInstance.current.reset();
100
      })
96
        signupExpiredCallbackHandler();
101
      .catch((err) => {
Línea 97... Línea 102...
97
        setRegistered(true);
102
        addNotification({
Línea 98... Línea 103...
98
      })
103
          style: 'danger',
99
      .catch(err => {
104
          msg: 'Disculpe, ha ocurrido un error',
100
        addNotification({ style: "danger", msg: 'Disculpe, ha ocurrido un error' })
105
        })
101
        console.log(`Error: ${err}`)
106
        console.log(`Error: ${err}`)
Línea 117... Línea 122...
117
          <button id="btn-submit" className="sign_in_sec_button">
122
          <button id="btn-submit" className="sign_in_sec_button">
118
            Entrar
123
            Entrar
119
          </button>
124
          </button>
120
        </Link>
125
        </Link>
121
      </StyledCheck>
126
      </StyledCheck>
122
    );
127
    )
123
  }
128
  }
-
 
129
 
124
  return (
130
  return (
125
    <React.Fragment>
131
    <React.Fragment>
126
      <h3>Registrarse</h3>
132
      <h3>Registrarse</h3>
127
      <form onSubmit={handleSubmit(onSubmitHandler)}>
133
      <form onSubmit={handleSubmit(onSubmitHandler)}>
128
        <div className="row">
134
        <div className="row">
Línea 131... Línea 137...
131
              <div className="sn-field">
137
              <div className="sn-field">
132
                <input
138
                <input
133
                  type="email"
139
                  type="email"
134
                  name="email"
140
                  name="email"
135
                  ref={register({
141
                  ref={register({
136
                    required: "Este campo es requerido",
142
                    required: 'Este campo es requerido',
137
                    pattern: {
143
                    pattern: {
138
                      value: /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/i,
144
                      value: /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/i,
-
 
145
                      message:
139
                      message: "Debe ser una dirección de correo electrónico valida"
146
                        'Debe ser una dirección de correo electrónico valida',
140
                    }
147
                    },
141
                  })}
148
                  })}
142
                  maxLength="64"
149
                  maxLength="64"
143
                  placeholder="Correo electrónico"
150
                  placeholder="Correo electrónico"
144
                />
151
                />
145
                <i className="la la-envelope"></i>
152
                <i className="la la-envelope"></i>
Línea 155... Línea 162...
155
              <div className="sn-field">
162
              <div className="sn-field">
156
                <input
163
                <input
157
                  type="text"
164
                  type="text"
158
                  name="first_name"
165
                  name="first_name"
159
                  ref={register({
166
                  ref={register({
160
                    required: "Este campo es requerido",
167
                    required: 'Este campo es requerido',
161
                    maxLength: {
168
                    maxLength: {
162
                      value: 64,
169
                      value: 64,
163
                      message: 'Limite de carateres superior al permitido'
170
                      message: 'Limite de carateres superior al permitido',
164
                    }
171
                    },
165
                  })}
172
                  })}
166
                  placeholder="Nombre"
173
                  placeholder="Nombre"
167
                />
174
                />
168
                <i className="la la-user"></i>
175
                <i className="la la-user"></i>
169
              </div>
176
              </div>
-
 
177
              {errors.first_name && (
-
 
178
                <FormErrorFeedback>
170
              {errors.first_name && <FormErrorFeedback>{errors.first_name.message}</FormErrorFeedback>}
179
                  {errors.first_name.message}
-
 
180
                </FormErrorFeedback>
-
 
181
              )}
171
            </div>
182
            </div>
172
          </div>
183
          </div>
173
          <div className="col-lg-12 no-pdd">
184
          <div className="col-lg-12 no-pdd">
174
            <div className="inputContainer">
185
            <div className="inputContainer">
175
              <div className="sn-field">
186
              <div className="sn-field">
176
                <input
187
                <input
177
                  type="text"
188
                  type="text"
178
                  name="last_name"
189
                  name="last_name"
179
                  ref={register({
190
                  ref={register({
180
                    required: "Este campo es requerido",
191
                    required: 'Este campo es requerido',
181
                    maxLength: {
192
                    maxLength: {
182
                      value: 64,
193
                      value: 64,
183
                      message: 'Limite de carateres superior al permitido'
194
                      message: 'Limite de carateres superior al permitido',
184
                    }
195
                    },
185
                  })}
196
                  })}
186
                  placeholder="Apellido"
197
                  placeholder="Apellido"
187
                />
198
                />
188
                <i className="la la-user"></i>
199
                <i className="la la-user"></i>
189
              </div>
200
              </div>
Línea 200... Línea 211...
200
              <div className="sn-field">
211
              <div className="sn-field">
201
                <input
212
                <input
202
                  type="password"
213
                  type="password"
203
                  name="password"
214
                  name="password"
204
                  ref={register({
215
                  ref={register({
205
                    required: "Este campo es requerido",
216
                    required: 'Este campo es requerido',
206
                    pattern: {
217
                    pattern: {
-
 
218
                      value:
207
                      value: /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$^x%x*-]).{6,16}$/i,
219
                        /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$^x%x*-]).{6,16}$/i,
-
 
220
                      message:
208
                      message: 'Debe contener entre 6 y 16 caracteres, incluida una letra mayúscula, un número y un carácter especial #?!@$^%*-'
221
                        'Debe contener entre 6 y 16 caracteres, incluida una letra mayúscula, un número y un carácter especial #?!@$^%*-',
209
                    }
222
                    },
210
                  })}
223
                  })}
211
                  title="La clave debe contener entre 6 y 16 caracteres, incluida una letra mayúscula, un número y un carácter especial #?!@$^%*-"
224
                  title="La clave debe contener entre 6 y 16 caracteres, incluida una letra mayúscula, un número y un carácter especial #?!@$^%*-"
212
                  placeholder="Clave"
225
                  placeholder="Clave"
213
                />
226
                />
214
                <i className="la la-lock"></i>
227
                <i className="la la-lock"></i>
215
              </div>
228
              </div>
-
 
229
              {errors.password && (
216
              {errors.password && <FormErrorFeedback>{errors.password.message}</FormErrorFeedback>}
230
                <FormErrorFeedback>{errors.password.message}</FormErrorFeedback>
-
 
231
              )}
217
            </div>
232
            </div>
218
          </div>
233
          </div>
219
          <div className="col-lg-12 no-pdd">
234
          <div className="col-lg-12 no-pdd">
220
            <div className="inputContainer">
235
            <div className="inputContainer">
221
              <div className="sn-field">
236
              <div className="sn-field">
222
                <input
237
                <input
223
                  type="password"
238
                  type="password"
224
                  name="confirmation"
239
                  name="confirmation"
225
                  ref={register({
240
                  ref={register({
226
                    required: "Este campo es requerido",
241
                    required: 'Este campo es requerido',
-
 
242
                    validate: (v) =>
-
 
243
                      v === watch('password') ||
227
                    validate: (v) => v === watch('password') || 'Disculpe, las claves tienen que coincidir'
244
                      'Disculpe, las claves tienen que coincidir',
228
                  })}
245
                  })}
229
                  placeholder="Confirme su clave"
246
                  placeholder="Confirme su clave"
230
                />
247
                />
231
                <i className="la la-lock" />
248
                <i className="la la-lock" />
232
              </div>
249
              </div>
-
 
250
              {errors.confirmation && (
-
 
251
                <FormErrorFeedback>
233
              {errors.confirmation && <FormErrorFeedback>{errors.confirmation.message}</FormErrorFeedback>}
252
                  {errors.confirmation.message}
-
 
253
                </FormErrorFeedback>
-
 
254
              )}
234
            </div>
255
            </div>
235
          </div>
256
          </div>
236
          <div className="col-lg-12 no-pdd">
257
          <div className="col-lg-12 no-pdd">
237
            <div className="d-flex flex-column" style={{ gap: '.5rem' }}>
258
            <div className="d-flex flex-column" style={{ gap: '.5rem' }}>
238
              <label>Eres mayor de 18</label>
259
              <label>Eres mayor de 18</label>
Línea 248... Línea 269...
248
                    type="checkbox"
269
                    type="checkbox"
249
                    name="terms_and_conditions"
270
                    name="terms_and_conditions"
250
                    id="terms_and_conditions"
271
                    id="terms_and_conditions"
251
                    checked={termsChecked}
272
                    checked={termsChecked}
252
                    ref={register({
273
                    ref={register({
253
                      required: "Este campo es requerido",
274
                      required: 'Este campo es requerido',
254
                    })}
275
                    })}
255
                    value="1"
276
                    value="1"
256
                    readOnly
277
                    readOnly
257
                  />
278
                  />
-
 
279
                  <label
-
 
280
                    htmlFor="terms_and_conditions"
258
                  <label htmlFor="terms_and_conditions" onClick={() => setTermsChecked(!termsChecked)}>
281
                    onClick={() => setTermsChecked(!termsChecked)}
-
 
282
                  >
259
                    <span></span>
283
                    <span></span>
260
                  </label>
284
                  </label>
261
                  <small onClick={() => setTermsChecked(!termsChecked)}>
285
                  <small onClick={() => setTermsChecked(!termsChecked)}>
-
 
286
                    Si, acepto los{' '}
262
                    Si, acepto los <a href="/terms-and-conditions">Términos y Condiciones.</a>
287
                    <a href="/terms-and-conditions">Términos y Condiciones.</a>
263
                  </small>
288
                  </small>
264
                </div>
289
                </div>
265
              </div>
290
              </div>
266
              {errors.terms_and_conditions &&
291
              {errors.terms_and_conditions && (
267
                <FormErrorFeedback>
292
                <FormErrorFeedback>
268
                  {errors.terms_and_conditions.message}
293
                  {errors.terms_and_conditions.message}
269
                </FormErrorFeedback>
294
                </FormErrorFeedback>
270
              }
295
              )}
271
            </div>
296
            </div>
272
          </div>
297
          </div>
Línea 273... Línea 298...
273
 
298
 
274
          <div className="col-lg-12 no-pdd">
299
          <div className="col-lg-12 no-pdd">
Línea 297... Línea 322...
297
              Registrarse
322
              Registrarse
298
            </button>
323
            </button>
299
          </div>
324
          </div>
300
        </div>
325
        </div>
301
      </form>
326
      </form>
302
      {isLoading &&
327
      {isLoading && (
303
        <StyledSpinnerContainer>
328
        <StyledSpinnerContainer>
304
          <Spinner />
329
          <Spinner />
305
        </StyledSpinnerContainer>}
330
        </StyledSpinnerContainer>
-
 
331
      )}
306
    </React.Fragment>
332
    </React.Fragment>
307
  );
333
  )
308
};
334
}
Línea 309... Línea 335...
309
 
335