Skip to content

Commit

Permalink
Merge pull request #60 from 001elijah/auth
Browse files Browse the repository at this point in the history
fix valid name
  • Loading branch information
001elijah authored Jun 29, 2023
2 parents bc14551 + d27e620 commit 15b73ba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 37 deletions.
5 changes: 2 additions & 3 deletions src/components/ModalEditProfile/ModalEditProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import { Notify } from 'notiflix';

import { ButtonAuth } from '../ButtonAuth/ButtonAuth';
import { validationSchemaEditProfile } from '../SchemaValidation/schemaValidation';
import { validationSchemaRegister } from '../SchemaValidation/schemaValidation';
import { updateUser } from 'redux/Auth/authOperations';
import {
selectorTheme,
Expand Down Expand Up @@ -36,9 +36,8 @@ export const ModalEditProfile = ({ onClose }) => {
userName: name,
email: email,
password: '',
// avatarUrl: avatar,
},
validationSchema: validationSchemaEditProfile,
validationSchema: validationSchemaRegister,
onSubmit: values => {
onClose();

Expand Down
39 changes: 5 additions & 34 deletions src/components/SchemaValidation/schemaValidation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,10 @@ export const validationSchemaRegister = yup.object().shape({
userName: yup
.string()
.matches(
/^[a-zA-Z0-9_]+( [a-zA-Z0-9_]+)?$/,
'Only letters, numbers, underscores, and spaces are allowed',
)
.min(2, 'Minimum length 2 characters')
.max(32, 'Maximum length 32 characters')
.required('Name required'),
email: yup
.string()
.matches(
/^[\w.%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
'Invalid email address. Example: [email protected]',
)
.required('Email required'),
password: yup
.string()
.matches(/^\S*$/, 'Must not contain spaces')
.matches(
/^[a-zA-Z0-9!"@#$%^&*()]+$/,
'Can only contain Latin letters, numbers, and signs',
)
.min(8, 'Minimum length 8 characters')
.max(64, 'Maximum length 64 characters')
.required('Password required'),
});

export const validationSchemaEditProfile = yup.object().shape({
userName: yup
.string()
.matches(
/^[a-zA-Z0-9_]+( [a-zA-Z0-9_]+)?$/,
'Only letters, numbers, underscores, and spaces are allowed',
)
/^[a-zA-Z0-9]+([-_ ][a-zA-Z0-9]+)*$/,
// 'Only letters, numbers, underscores, spaces, hyphens, and dashes are allowed between words',
'Invalid name'
)
.min(2, 'Minimum length 2 characters')
.max(32, 'Maximum length 32 characters')
.required('Name required'),
Expand All @@ -76,5 +48,4 @@ export const validationSchemaEditProfile = yup.object().shape({
.min(8, 'Minimum length 8 characters')
.max(64, 'Maximum length 64 characters')
.required('Password required'),
avatarUrl: yup.string(),
});
});
1 change: 1 addition & 0 deletions src/redux/Auth/authOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const updateUser = createAsyncThunk(

return data;
} catch (error) {
Notify.failure('Invalid editing');
return rejectWithValue(error.message);
}
},
Expand Down

0 comments on commit 15b73ba

Please sign in to comment.