Skip to content
Snippets Groups Projects
Commit 7c61b632 authored by Iurii Lebedev's avatar Iurii Lebedev :speech_balloon:
Browse files

:art: added basic structure + LogIn/SignUp page created

parent b27d552b
No related branches found
No related tags found
1 merge request!1:art: added basic structure + LogIn/SignUp page created
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/.idea/
# PM2-FE # Quiz-Wiz FrontEnd Application
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
## Getting started In the project directory, you can run:
To make it easy for you to get started with GitLab, here's a list of recommended next steps. ### `npm start`
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
## Add your files The page will reload when you make changes.\
You may also see any lint errors in the console.
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files ### `npm test`
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
``` Launches the test runner in the interactive watch mode.\
cd existing_repo See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
git remote add origin https://gitlab.fel.cvut.cz/ovsyaver/pm2-fe.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools ### `npm run build`
- [ ] [Set up project integrations](https://gitlab.fel.cvut.cz/ovsyaver/pm2-fe/-/settings/integrations) Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
## Collaborate with your team The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy ### `npm run eject`
Use the built-in continuous integration in GitLab. **Note: this is a one-way operation. Once you `eject`, you can't go back!**
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
*** Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
# Editing this README You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
This diff is collapsed.
{
"name": "quiz-wiz",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.6.0",
"js-cookie": "^3.0.5",
"mobx": "^6.10.2",
"mobx-react-lite": "^4.0.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.18.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
import './layouts/App.css';
import {BrowserRouter} from "react-router-dom";
import NavBar from "./components/NavBar";
import AppRouter from "./components/AppRouter";
function App() {
return (
<BrowserRouter>
<NavBar/>
<AppRouter/>
</BrowserRouter>
);
}
export default App;
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
import React, {useContext} from 'react';
import {Route, Routes} from 'react-router-dom'
import {observer} from "mobx-react-lite";
import {Context} from "../index.js";
import {authRoutes, publicRoutes} from "../routes/routes";
import {Auth} from "../pages/Auth";
const AppRouter = observer(() => {
const {user} = useContext(Context)
return (
<Routes>
{user.getUser !== undefined && authRoutes.map(({path, Element}) =>
<Route key={path} path={path} component={Element} exact/>
)}
{publicRoutes.map(({path, Element}) =>
<Route key={path} path={path} element={Element} exact/>
)}
<Route path="*" element ={<Auth/>}/>
</Routes>
);
});
export default AppRouter;
\ No newline at end of file
import React from 'react';
const NavBar = () => {
return (
<div></div>
);
}
export default NavBar;
\ No newline at end of file
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
import React, {createContext, StrictMode} from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import UserStore from './stores/UserStore';
import reportWebVitals from './reportWebVitals';
export const Context = createContext(null)
const root = ReactDOM.createRoot( document.getElementById('root'))
root.render(
<StrictMode>
<Context.Provider value ={{
user: new UserStore(),
}}>
<App />
</Context.Provider>
</StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
\ No newline at end of file
export class LogUser{
constructor(username, password) {
this.username = username;
this.password = password;
}
}
\ No newline at end of file
export class RegUser{
constructor(username, password) {
this.username = username;
this.password = password;
}
}
\ No newline at end of file
import {useState, useEffect, useContext} from "react";
import UserService from '../service/user.service'
import {LogUser} from "../models/logUser";
import {RegUser} from "../models/regUser";
import {useNavigate} from "react-router-dom";
import {Context} from "../index";
import {AUTH_ROUTE, MAIN_ROUTE} from "../utils/consts";
import Cookies from 'js-cookie';
const USER_REGEX = /^[A-z][A-z0-9-_]{3,23}$/;
const PWD_REGEX = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%]).{8,24}$/;
const EMAIL_REGEX = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/
export const Auth = () => {
Cookies.set('jwtToken', null, { path: '/' });
const {user} = useContext(Context)
const navigate = useNavigate()
const [username, setUsername] = useState('');
const [usernameFocus, setUsernameFocus] = useState(false);
const [pwd, setPwd] = useState('');
const [pwdFocus, setPwdFocus] = useState(false);
const [email, setEmail] = useState('');
const [emailFocus, setEmailFocus] = useState(false);
const [confPwd, setConfPwd] = useState('');
const [confPwdFocus, setConfPwdFocus] = useState(false);
const [validUser, setValidUser] = useState(false);
const [validEmail, setValidEmail] = useState(false);
const [validPwd, setValidPwd] = useState(false);
const [validPwdMatch, setValidPwdMatch] = useState(false);
const [success, setSuccess] = useState(false);
const [errMsg, setErrMsg] = useState('');
useEffect(() => {
const userTest = USER_REGEX.test(username)
setValidUser(userTest)
}, [username])
useEffect(() => {
const pwdTest = PWD_REGEX.test(pwd)
setValidPwd(pwdTest)
const match = pwd === confPwd
setValidPwdMatch(match)
}, [pwd, confPwd])
useEffect(() => {
const emailTest = EMAIL_REGEX.test(email)
setValidEmail(emailTest)
}, [email])
useEffect(() => {
setErrMsg('');
}, [username, email, pwd, validPwdMatch])
const register = (e) => {
e.preventDefault();
UserService.register(new RegUser(username, pwd, email)).then(res=>{
try {
if (!success) {
setSuccess(true)
user.setUser(user)
navigate(AUTH_ROUTE)
}
}catch (err){
setErrMsg(res.response.data.message)
setSuccess(false)
}
})
}
const login = (e) => {
e.preventDefault();
UserService.login(new LogUser(username, pwd)).then(res=>{
try {
let data = res.data.token;
setSuccess(true)
user.setUser(user)
Cookies.set('jwtToken', data, { path: '/' });
console.log(Cookies.get('jwtToken'))
navigate(MAIN_ROUTE)
}catch (err){
setErrMsg(res.response.data.message)
setSuccess(false)
}
})
}
useEffect(() => {
let signup = document.querySelector(".signup");
let login = document.querySelector(".login");
let slider = document.querySelector(".slider");
let formSection = document.querySelector(".form-section");
signup.addEventListener("click", () => {
slider.classList.add("moveslider");
formSection.classList.add("form-section-move");
});
login.addEventListener("click", () => {
slider.classList.remove("moveslider");
formSection.classList.remove("form-section-move");
});
}, [])
return (
<div className="auth-container">
<div className="slider"></div>
<div className="slider-btn">
<button className="login">Login</button>
<button className="signup">Signup</button>
</div>
<p className="errorMsg">{errMsg}</p>
<div className="form-section">
<form className="login-box" onSubmit={login}>
<input type="username"
className="username ele"
placeholder="Username"
onChange={(e) => setUsername(e.target.value)}
onFocus={() => setUsernameFocus(true)}
onBlur={() => setUsernameFocus(false)}
required/>
<input type="password"
className="password ele"
placeholder="Password"
onChange={(e) => setPwd(e.target.value)}
onFocus={() => setPwdFocus(true)}
onBlur={() => setPwdFocus(false)}
required/>
<button className="clkbtn">Login</button>
</form>
<form className="signup-box" onSubmit={register}>
<div className = "inp">
<input type="text"
className={usernameFocus && !validUser ? "name invalidEle" : "name ele"}
placeholder="Username"
onChange={(e) => setUsername(e.target.value)}
onFocus={() => setUsernameFocus(true)}
aria-invalid={validUser ? "false" : "true"}
onBlur={() => setUsernameFocus(false)}
required/>
<p className={usernameFocus && !validUser ? "instructions" : "hide"}>
4 to 24 characters.<br />
Must begin with a letter.
Letters, numbers, underscores, hyphens allowed.
</p>
</div>
<div className = "inp">
<input type="email"
className={emailFocus && !validEmail ? "email invalidEle" : "email ele"}
placeholder="youremail@email.com"
onChange={(e) => setEmail(e.target.value)}
onFocus={() => setEmailFocus(true)}
onBlur={() => setEmailFocus(false)}
aria-invalid={validEmail ? "false" : "true"}
required/>
<p className={emailFocus && !validEmail ? "instructions" : "hide"}>
Valid email example : email@domen.com
</p>
</div>
<div className = "inp">
<input type="password"
className={pwdFocus && !validPwd ? "password invalidEle" : "password ele"}
placeholder="Password"
aria-invalid={validPwd ? "false" : "true"}
onChange={(e) => setPwd(e.target.value)}
onFocus={() => setPwdFocus(true)}
onBlur={() => setPwdFocus(false)}
required/>
<p className={pwdFocus && !validPwd ? "instructions" : "hide"}>
8 to 24 characters.<br />
Must include upper and lower letters, a number and a special character.
Allowed special characters: ! @ # $ %
</p>
</div>
<div className = "inp">
<input type="password"
className={confPwdFocus && !validPwdMatch ? "password invalidEle" : "password ele"}
placeholder="Confirm password"
aria-invalid={validPwdMatch ? "false" : "true"}
onChange={(e)=>setConfPwd(e.target.value)}
onFocus={() => setConfPwdFocus(true)}
onBlur={() => setConfPwdFocus(false)}
required/>
<p className={confPwdFocus && !validPwdMatch ? "instructions" : "hide"}>
Must match the password above
</p>
</div>
<button className="clkbtn">Signup</button>
</form>
</div>
</div>
)
}
\ No newline at end of file
import React from 'react';
export const Main = () => {
return (
<div>
MAIN PAGE TODO
</div>
);
};
\ No newline at end of file
import React from 'react';
export const Quiz = () => {
return (
<div>
QUIZ PAGE TODO
</div>
);
};
\ No newline at end of file
import React from 'react';
export const User = () => {
return (
<div>
USER PAGE TODO
</div>
);
};
\ No newline at end of file
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;
import {AUTH_ROUTE, MAIN_ROUTE, QUIZ_ROUTE, USER_ROUTE} from "../utils/consts";
import {Auth} from "../pages/Auth";
import {User} from "../pages/User";
import {Quiz} from "../pages/Quiz";
import {Main} from "../pages/Main";
export const authRoutes = [
{
path: USER_ROUTE,
Element: <User/>
},
{
path: QUIZ_ROUTE + '/:id',
Element: <Quiz/>
},
]
export const publicRoutes = [
{
path: MAIN_ROUTE,
Element: <Main/>
},
{
path: AUTH_ROUTE,
Element: <Auth/>
}
]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment