Skip to content

Commit

Permalink
Merge pull request #1 from 001elijah/auth
Browse files Browse the repository at this point in the history
create welcome Page
  • Loading branch information
001elijah authored Jun 16, 2023
2 parents 8c00931 + 7f749d9 commit c90543c
Show file tree
Hide file tree
Showing 19 changed files with 503 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-homework-template",
"version": "0.1.0",
"private": true,
"homepage": "https://001elijah.github.io/bc48-node-team-project-frontend/",
"homepage": "https://001elijah.github.io/bc48-node-team-project-frontend/welcome",
"dependencies": {
"@reduxjs/toolkit": "^1.9.5",
"@testing-library/jest-dom": "^5.16.3",
Expand Down
4 changes: 4 additions & 0 deletions src/assets/icons/sprite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/welcome-page-1x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/welcome-page-mob-1x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/assets/styles/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
}

@mixin mobile {
@media screen and (min-width: 375px) and (max-width: 767px) {
@media screen and (min-width: 375px) {
@content;
}
}

@mixin tablet {
@media screen and (min-width: 768px) and (max-width: 1279px) {
@media screen and (min-width: 768px) {
@content;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Navigate, Route, Routes } from 'react-router-dom';
import { HomePage } from 'pages/HomePage';
import { LoginPage } from 'pages/LoginPage';
import { RegisterPage } from 'pages/RegisterPage';
import { BoardPage } from 'pages/BoardPage';
import { WelcomePage } from 'pages/WelcomePage/WelcomePage';
import AuthPage from '../pages/AuthPage/AuthPage';

export const App = () => {
return (
<>
{/* <SharedLayout /> */}
<Routes>
<Route path="/" element={<HomePage />}>
<Route path="/login" element={<LoginPage />} />
<Route path="/register" element={<RegisterPage />} />
</Route>
<Route path="/welcome" element={<WelcomePage />} />
<Route path="auth/:id" element={<AuthPage />} />

<Route path="/" element={<HomePage />} />
<Route path="/board" element={<BoardPage />} />

<Route path="*" element={<Navigate to="/" />} />
Expand Down
15 changes: 15 additions & 0 deletions src/components/AuthForm/ButtonAuth/ButtonAuth.jsx
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,
};
21 changes: 21 additions & 0 deletions src/components/AuthForm/ButtonAuth/ButtonAuth.module.scss
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;
}
50 changes: 50 additions & 0 deletions src/components/AuthForm/Login/Login.jsx
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>
);
};
6 changes: 6 additions & 0 deletions src/components/AuthForm/Login/Login.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.error {
position: absolute;
margin: 0;
color: red;
font-size: 12px;
}
64 changes: 64 additions & 0 deletions src/components/AuthForm/Register/Register.jsx
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>
);
};
50 changes: 50 additions & 0 deletions src/components/AuthForm/schemaValidation.jsx
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'),
});
11 changes: 11 additions & 0 deletions src/components/BackdropHome/BackdropHome.jsx
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,
};
12 changes: 12 additions & 0 deletions src/components/BackdropHome/BackdropHome.module.scss
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;
}
4 changes: 1 addition & 3 deletions src/index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import-normalize; /* bring in normalize.css styles */
// @import-normalize; /* bring in normalize.css styles */
@import './assets/styles/reset';
@import './assets/styles/vars';
@import './assets/styles/mixins';
Expand Down Expand Up @@ -32,8 +32,6 @@ body {
-moz-osx-font-smoothing: grayscale;
font-weight: 400;
color: $white-text-color;

background-color: $dark-color;
}

body.no-scroll {
Expand Down
40 changes: 40 additions & 0 deletions src/pages/AuthPage/AuthPage.jsx
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;
Loading

0 comments on commit c90543c

Please sign in to comment.