Skip to content

[ Otto Micheletti ] Projeto Bônus - Password Generator #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87,934 changes: 44,473 additions & 43,461 deletions package-lock.json

Large diffs are not rendered by default.

112 changes: 59 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
{
"name": "exercise-password-generator",
"version": "0.1.0",
"private": true,
"engines": {
"node": "16"
},
"dependencies": {
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test-coverage": "react-scripts test --coverage --watchAll=false",
"eject": "react-scripts eject",
"lint:styles": "npx stylelint '**/*.css'",
"lint": "eslint --no-inline-config --no-error-on-unmatched-pattern -c .eslintrc.json . --ext .js, .jsx"
},
"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"
]
},
"devDependencies": {
"eslint": "^7.11.0",
"eslint-config-trybe-frontend": "^1.2.2",
"eslint-plugin-sonarjs": "^0.11.0",
"prop-types": "^15.8.1",
"stylelint": "^14.3.0",
"stylelint-config-standard": "^24.0.0",
"stylelint-order": "^5.0.0"
}
}
{
"name": "exercise-password-generator",
"version": "0.1.0",
"private": true,
"engines": {
"node": "16"
},
"dependencies": {
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@mui/material": "^5.6.3",
"@reduxjs/toolkit": "^1.8.1",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"generate-password": "^1.7.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^8.0.1",
"react-scripts": "4.0.3",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test-coverage": "react-scripts test --coverage --watchAll=false",
"eject": "react-scripts eject",
"lint:styles": "npx stylelint '**/*.css'",
"lint": "eslint --no-inline-config --no-error-on-unmatched-pattern -c .eslintrc.json . --ext .js, .jsx"
},
"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"
]
},
"devDependencies": {
"eslint": "^7.11.0",
"eslint-config-trybe-frontend": "^1.2.2",
"eslint-plugin-sonarjs": "^0.11.0",
"prop-types": "^15.8.1",
"stylelint": "^14.3.0",
"stylelint-config-standard": "^24.0.0",
"stylelint-order": "^5.0.0"
}
}
25 changes: 1 addition & 24 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,11 @@
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Password Generator</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

49 changes: 31 additions & 18 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
import logo from './logo.svg';
import './App.css';
import { Box, Typography } from '@mui/material';
import PasswordLength from './components/PasswordLength';
import PasswordSettings from './components/PasswordSettings';
import GenerateButton from './components/GenerateButton';
import PasswordDisplay from './components/PasswordDisplay';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
<Box sx={{
backgroundColor: '#5e6bda',
width: '100vw',
height: '100vh',
margin: '0',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}>
<Box sx={{
width: '350px',
height: '500px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#0b0f2f',
borderRadius: '10px',
}}>
<Typography sx={{ color: 'white', marginTop: 4, fontSize: '20px' }}>Password Generator</Typography>
<PasswordDisplay />
<PasswordLength />
<PasswordSettings />
<GenerateButton />
</Box>
</Box>
);
}

Expand Down
55 changes: 55 additions & 0 deletions src/components/GenerateButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Box,Button } from '@mui/material'
import React from 'react'
import { useSelector, useDispatch } from 'react-redux';
import { changePassword } from '../reducers';
import generator from 'generate-password';

const GenerateButton = () => {
const { length, conditions: { numbers, symbols, lowercase, uppercase }, conditions } = useSelector((state) => state.password);
const dispatch = useDispatch();

const calculatePassword = () => {
const shouldCalculate = Object.values(conditions).some((condition) => condition === true);
if (shouldCalculate) {
console.log('entrou')
let password = generator.generate({
length,
numbers,
symbols,
lowercase,
uppercase,
strict: true,
})
dispatch(changePassword(password));
localStorage.setItem('password', JSON.stringify(password));
} else {
dispatch(changePassword('PLEASE, SET YOUR PASSWORD SETTINGS'));
}
}

return (
<Box>
<Button
variant="contained"
onClick={calculatePassword}
sx={{
width: '330px',
height: '50px',
marginTop: 2,
marginBottom: 2,
backgroundColor: '#5e6bda',
color: 'white',
marginTop: 2,
marginBottom: 2,
'&:hover': {
backgroundColor: '#1e223f',
}
}}
>
GENERATE PASSWORD
</Button>
</Box>
)
}

export default GenerateButton
69 changes: 69 additions & 0 deletions src/components/PasswordDisplay.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { ClickAwayListener, Tooltip, Chip } from '@mui/material'
import React, { useEffect, useState } from 'react'
import { useSelector, useDispatch } from 'react-redux';
import { changePassword } from '../reducers';

const PasswordDisplay = () => {
const { password } = useSelector((state) => state.password);
const dispatch = useDispatch();
const [open, setOpen] = useState(false);
const PWD = 'PLEASE, SET YOUR PASSWORD SETTINGS';

const verifyPwd = () => {
const pwd = JSON.parse(localStorage.getItem('password'));
if (pwd?.length > 0) {
dispatch(changePassword(pwd));
}
}

const handleTooltipOpen = ({ target }) => (
navigator.clipboard.writeText(target.innerText),
setOpen(true)
)

const handleTooltipClose = () => {
setOpen(false);
}

useEffect(() => {
verifyPwd();
}, [])

return (
<ClickAwayListener onClickAway={handleTooltipClose}>
<div>
<Tooltip
PopperProps={{
disablePortal: true,
}}
onClose={handleTooltipClose}
open={open}
title="Copied to clipboard!"
placement="top"
arrow
>
<Chip
onClick={password !== PWD ? handleTooltipOpen : handleTooltipClose}
variant="contained"
label={ password }
sx={{
width: '330px',
height: '50px',
marginTop: 5,
marginBottom: 2,
backgroundColor: '#1e223f',
color: 'white',
fontSize: '14px',
'&:hover': {
backgroundColor: '#5e6bda',
},
}}
/>

</Tooltip>
</div>
</ClickAwayListener>
)
}

export default PasswordDisplay
Loading