generated from goitacademy/react-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from 001elijah/auth
create welcome Page
- Loading branch information
Showing
19 changed files
with
503 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import s from './ButtonAuth.module.scss'; | ||
|
||
export const ButtonAuth = ({ title }) => { | ||
return ( | ||
<button type="submit" className={s.button}> | ||
{title} | ||
</button> | ||
); | ||
}; | ||
|
||
ButtonAuth.propTypes = { | ||
title: PropTypes.string.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@import '../../../assets/styles/vars'; | ||
|
||
.button { | ||
min-width: 344px; | ||
width: 100%; | ||
height: 49px; | ||
margin-top: 24px; | ||
|
||
background-color: $accent-color; | ||
color: $black-text-color; | ||
|
||
text-align: center; | ||
font-weight: 500; | ||
font-size: 14px; | ||
line-height: 1.5; | ||
|
||
border: none; | ||
border-radius: 8px; | ||
|
||
cursor: pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useFormik } from 'formik'; | ||
|
||
import { ButtonAuth } from '../ButtonAuth/ButtonAuth'; | ||
import { validationSchemaLogin } from '../schemaValidation'; | ||
|
||
import y from './Login.module.scss'; | ||
|
||
export const Login = () => { | ||
const formik = useFormik({ | ||
initialValues: { | ||
email: '', | ||
password: '', | ||
}, | ||
validationSchema: validationSchemaLogin, | ||
onSubmit: values => { | ||
console.log(values); | ||
}, | ||
}); | ||
return ( | ||
<form onSubmit={formik.handleSubmit}> | ||
<label htmlFor="email"> | ||
<input | ||
id="email" | ||
name="email" | ||
type="email" | ||
onChange={formik.handleChange} | ||
value={formik.values.email} | ||
placeholder="Enter your email" | ||
/> | ||
{formik.touched.email && formik.errors.email && ( | ||
<p className={y.error}>{formik.errors.email}</p> | ||
)} | ||
</label> | ||
<label htmlFor="password"> | ||
<input | ||
id="password" | ||
name="password" | ||
type="text" | ||
onChange={formik.handleChange} | ||
value={formik.values.password} | ||
placeholder="Confirm a password" | ||
/> | ||
{formik.touched.password && formik.errors.password && ( | ||
<p className={y.error}>{formik.errors.password}</p> | ||
)} | ||
</label> | ||
<ButtonAuth title="Log In Now" /> | ||
</form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.error { | ||
position: absolute; | ||
margin: 0; | ||
color: red; | ||
font-size: 12px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useFormik } from 'formik'; | ||
|
||
import { ButtonAuth } from '../ButtonAuth/ButtonAuth'; | ||
import { validationSchemaRegister } from '../schemaValidation'; | ||
|
||
import y from '../Login/Login.module.scss'; | ||
|
||
export const Register = () => { | ||
const formik = useFormik({ | ||
initialValues: { | ||
name: '', | ||
email: '', | ||
password: '', | ||
}, | ||
validationSchema: validationSchemaRegister, | ||
onSubmit: values => { | ||
console.log(values); | ||
}, | ||
}); | ||
return ( | ||
<form onSubmit={formik.handleSubmit}> | ||
<label htmlFor="name"> | ||
<input | ||
id="name" | ||
name="name" | ||
type="text" | ||
onChange={formik.handleChange} | ||
value={formik.values.name} | ||
placeholder="Enter your name" | ||
/> | ||
{formik.touched.name && formik.errors.name && ( | ||
<p className={y.error}>{formik.errors.name}</p> | ||
)} | ||
</label> | ||
<label htmlFor="email"> | ||
<input | ||
id="email" | ||
name="email" | ||
type="email" | ||
onChange={formik.handleChange} | ||
value={formik.values.email} | ||
placeholder="Enter your email" | ||
/> | ||
{formik.touched.email && formik.errors.email && ( | ||
<p className={y.error}>{formik.errors.email}</p> | ||
)} | ||
</label> | ||
<label htmlFor="password"> | ||
<input | ||
id="password" | ||
name="password" | ||
type="text" | ||
onChange={formik.handleChange} | ||
value={formik.values.password} | ||
placeholder="Create a password" | ||
/> | ||
{formik.touched.password && formik.errors.password && ( | ||
<p className={y.error}>{formik.errors.password}</p> | ||
)} | ||
</label> | ||
<ButtonAuth title="Register Now" /> | ||
</form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as yup from 'yup'; | ||
|
||
export const validationSchemaLogin = yup.object().shape({ | ||
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 validationSchemaRegister = yup.object().shape({ | ||
name: yup | ||
.string() | ||
.matches( | ||
/^[a-zA-Z0-9]+$/, | ||
'Can only contain Latin letters, numbers and signs', | ||
) | ||
.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'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import s from './BackdropHome.module.scss'; | ||
|
||
export const BackdropHome = ({ children }) => { | ||
return <main className={s.background}>{children}</main>; | ||
}; | ||
|
||
BackdropHome.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@import '../../assets/styles/vars'; | ||
|
||
.background { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
width: 100vw; | ||
height: 100vh; | ||
|
||
background: $start-background-color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { NavLink, useParams } from 'react-router-dom'; | ||
import { Login } from 'components/AuthForm/Login/Login'; | ||
import { Register } from 'components/AuthForm/Register/Register'; | ||
import { BackdropHome } from 'components/BackdropHome/BackdropHome'; | ||
import clsx from 'clsx'; | ||
|
||
import s from './AuthPage.module.scss'; | ||
|
||
const AuthPage = () => { | ||
const { id } = useParams(); | ||
return ( | ||
<BackdropHome> | ||
<section className={s.wrap}> | ||
<ul className={s.list}> | ||
<li> | ||
<NavLink | ||
to="/auth/register" | ||
className={({ isActive }) => clsx(s.link, isActive && s.active)} | ||
> | ||
Registration | ||
</NavLink> | ||
</li> | ||
<li> | ||
<NavLink | ||
to="/auth/login" | ||
className={({ isActive }) => clsx(s.link, isActive && s.active)} | ||
> | ||
Log In | ||
</NavLink> | ||
</li> | ||
</ul> | ||
<div className={s.form}> | ||
{id === 'login' ? <Login /> : <Register />} | ||
</div> | ||
</section> | ||
</BackdropHome> | ||
); | ||
}; | ||
|
||
export default AuthPage; |
Oops, something went wrong.