Skip to content

Commit

Permalink
Merge pull request #295 from faciledictu/fix-previous-resolving
Browse files Browse the repository at this point in the history
Fix previous conflict resolving
  • Loading branch information
dzencot authored Jul 6, 2023
2 parents e13988c + 8d9e4a7 commit 2704eaa
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 81 deletions.
8 changes: 2 additions & 6 deletions frontend/src/Pages/SignIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
import React, { useState, useRef, useEffect } from 'react';
import axios from 'axios';
import {
Alert,
Button,
Card,
Col,
Container,
Form,
Row,
Alert,
} from 'react-bootstrap';
import { object } from 'yup';

import { useFormik } from 'formik';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -93,10 +92,7 @@ function SignIn() {
id="email"
autoComplete="email"
required
isInvalid={
(formik.touched.email && t(formik.errors.email)) ||
authFailed
}
isInvalid={formik.touched.email && formik.errors.email}
ref={inputRef}
/>
<Form.Control.Feedback type="invalid">
Expand Down
41 changes: 13 additions & 28 deletions frontend/src/Pages/SignUp.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import React, { useEffect, useRef, useState } from 'react';
import React, { useEffect, useRef } from 'react';
import { useNavigate } from 'react-router-dom';
import axios from 'axios';
import { object } from 'yup';
Expand All @@ -25,7 +25,6 @@ function SignUp() {
const { t } = useTranslation();
const navigate = useNavigate();
const auth = useAuth();
const [regFailed, setRegFailed] = useState(false);

useEffect(() => {
emailRef.current.focus();
Expand Down Expand Up @@ -62,15 +61,14 @@ function SignUp() {
err.response?.status === 400 &&
Array.isArray(err.response?.data?.errs?.message)
) {
setRegFailed(true);
err.response.data.errs.message.forEach((e) => {
switch (e) {
case 'loginIsUsed':
formik.errors.login = 'signUp.validation.loginIsUsed';
formik.errors.login = 'errors.validation.loginIsUsed';
loginRef.current.select();
break;
case 'emailIsUsed':
formik.errors.email = 'signUp.validation.emailIsUsed';
formik.errors.email = 'errors.validation.emailIsUsed';
emailRef.current.select();
break;
default:
Expand Down Expand Up @@ -105,18 +103,14 @@ function SignUp() {
onBlur={formik.handleBlur}
className={`form-input bg-dark text-white ${classes.signUpInput}`}
name="email"
isInvalid={
(formik.touched.email && t(formik.errors.email)) ||
regFailed
}
id="email"
autoComplete="email"
required
isInvalid={formik.touched.email && formik.errors.email}
ref={emailRef}
/>
<Form.Control.Feedback type="invalid">
{(formik.touched.email && t(formik.errors.email)) ||
regFailed}
{t(formik.errors.email)}
</Form.Control.Feedback>
</Form.Group>

Expand All @@ -133,13 +127,11 @@ function SignUp() {
id="login"
autoComplete="username"
required
isInvalid={
(formik.touched.login && t(formik.errors.login)) ||
regFailed
}
isInvalid={formik.touched.login && formik.errors.login}
ref={loginRef}
/>
<Form.Control.Feedback type="invalid">
{formik.errors.login ? t(formik.errors.login) : regFailed}
{t(formik.errors.login)}
</Form.Control.Feedback>
</Form.Group>

Expand All @@ -158,15 +150,11 @@ function SignUp() {
autoComplete="new-password"
required
isInvalid={
(formik.touched.password &&
t(formik.errors.password)) ||
regFailed
formik.touched.password && formik.errors.password
}
/>
<Form.Control.Feedback type="invalid">
{formik.errors.password
? t(formik.errors.password)
: regFailed}
{t(formik.errors.password)}
</Form.Control.Feedback>
</Form.Group>
<Form.Group className={classes.formGroup}>
Expand All @@ -184,15 +172,12 @@ function SignUp() {
autoComplete="new-password"
required
isInvalid={
(formik.touched.confirmPassword &&
t(formik.errors.confirmPassword)) ||
regFailed
formik.touched.confirmPassword &&
formik.errors.confirmPassword
}
/>
<Form.Control.Feedback type="invalid">
{formik.errors.confirmPassword
? t(formik.errors.confirmPassword)
: t('signUp.signUpFailed')}
{t(formik.errors.confirmPassword)}
</Form.Control.Feedback>
</Form.Group>
<Button
Expand Down
12 changes: 4 additions & 8 deletions frontend/src/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,6 @@ const enLocales = {
infoBody: 'Log in to save and share.',
cancelButton: 'Cancel',
goToReplButton: 'Go to this replay',
validation: {
snippetNameMaxLength: 'No more than 20 characters',
required: `Can't be empty`,
singleWord: 'Allowed latin letters, numbers and symbols"-_"',
},

appRotes: {
pageNotFound: 'Page not found',
Expand All @@ -190,13 +185,14 @@ const enLocales = {
network: 'Network error',
validation: {
requiredField: 'Required field',
correctEmail: 'Incorrect email',
correctUsername: 'There must be no spaces in the username',
incorrectEmail: 'Incorrect email',
emailIsUsed: 'This email address is already being used',
incorrectUsername: 'There must be no spaces in the username',
loginIsUsed: 'This username is already taken',
usernameLength: 'From 3 to 16 characters',
passwordLength: 'from 8 to 30 characters',
confirmPassword: 'Passwords must be the same',
snippetNameMaxLength: 'No more than 20 characters',
required: `Can't be empty`,
singleWord: 'Allowed latin letters, numbers and symbols"-_"',
},
},
Expand Down
29 changes: 4 additions & 25 deletions frontend/src/locales/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ const ruLocales = {
signInHeader: 'Уже есть аккаунт? ',
signIn: 'Войти',
},
validation: {
requiredField: 'Обязательное поле',
correctUsername: 'В логине не должно быть пробелов',
correctEmail: 'Некорректная электронная почта',
usernameLength: 'От 3 до 16 символов',
passwordLength: 'От 8 до 30 символов',
confirmPassword: 'Пароли должны совпадать',
loginIsUsed: 'Это имя уже занято',
emailIsUsed: 'Этот адрес уже зарегистрирован',
},
},
remindPass: {
pageHeader: 'Забыли пароль?',
Expand All @@ -58,9 +48,6 @@ const ruLocales = {
signInHeader: 'Уже есть аккаунт? ',
signIn: 'Войти',
},
validation: {
correctEmail: 'Некорректный email',
},
},
signIn: {
pageHeader: 'Вход',
Expand All @@ -73,10 +60,6 @@ const ruLocales = {
signUpHeader: 'Нет аккаунта? ',
signUp: 'Создать аккаунт',
},
validation: {
requiredField: 'Обязательное поле',
correctEmail: 'Некорректная электронная почта',
},
withGithub: 'Войти с помощью Github',
},
profile: {
Expand Down Expand Up @@ -206,11 +189,6 @@ const ruLocales = {
infoBody: 'Авторизуйтесь, чтобы сохранять и делиться.',
cancelButton: 'Отмена',
goToReplButton: 'Перейти к этому реплу',
validation: {
snippetNameMaxLength: 'Не больше 20 символов',
required: 'Не может быть пустым',
singleWord: 'Допустимы буквы латинского алфавита, цифры и символы "-_"',
},
},
appRotes: {
pageNotFound: 'Страница не найдена',
Expand All @@ -220,13 +198,14 @@ const ruLocales = {
network: 'Ошибка сети',
validation: {
requiredField: 'Обязательное поле',
correctEmail: 'Некорректная электронная почта',
correctUsername: 'В логине не должно быть пробелов',
incorrectEmail: 'Некорректная электронная почта',
emailIsUsed: 'Этот адрес уже зарегистрирован',
incorrectUsername: 'В логине не должно быть пробелов',
loginIsUsed: 'Это имя уже занято',
usernameLength: 'От 3 до 16 символов',
passwordLength: 'От 8 до 30 символов',
confirmPassword: 'Пароли должны совпадать',
snippetNameMaxLength: 'Не больше 20 символов',
required: 'Не может быть пустым',
singleWord: 'Допустимы буквы латинского алфавита, цифры и символы "-_"',
},
},
Expand Down
27 changes: 13 additions & 14 deletions frontend/src/utils/validationSchemas.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
import { t } from 'i18next';
import { string } from 'yup';

export const login = () =>
string()
.trim()
.required(t('errors.validation.requiredField'))
.min(3, t('errors.validation.usernameLength'))
.max(16, t('errors.validation.usernameLength'))
.matches(/^[\w\S]*$/, t('errors.validation.correctUsername'));
.required('errors.validation.requiredField')
.min(3, 'errors.validation.usernameLength')
.max(16, 'errors.validation.usernameLength')
.matches(/^[\w\S]*$/, 'errors.validation.incorrectUsername');

export const email = () =>
string()
.trim()
.required(t('errors.validation.requiredField'))
.email(t('errors.validation.correctEmail'));
.required('errors.validation.requiredField')
.email('errors.validation.incorrectEmail');

export const password = () =>
string()
.trim()
.required(t('errors.validation.correctEmail'))
.min(8, t('errors.validation.passwordLength'))
.max(30, t('errors.validation.passwordLength'));
.required('errors.validation.requiredField')
.min(8, 'errors.validation.passwordLength')
.max(30, 'errors.validation.passwordLength');

export const confirmPassword = () =>
string()
.trim()
.test(
'confirmPassword',
t('errors.validation.confirmPassword'),
'errors.validation.confirmPassword',
(value, context) => value === context.parent.password,
);

export const replName = () =>
string()
.required(t('errors.validation.required'))
.max(20, t('errors.validation.snippetNameMaxLength'))
.matches(/^[a-zA-Z0-9_-]*$/, t('errors.validation.singleWord'));
.required('errors.validation.requiredField')
.max(20, 'errors.validation.snippetNameMaxLength')
.matches(/^[a-zA-Z0-9_-]*$/, 'errors.validation.singleWord');

0 comments on commit 2704eaa

Please sign in to comment.