Skip to content

Commit a395c81

Browse files
authored
Merge pull request #10 from oslabs-beta/fixing_login_freeze
Finishing touches on login, signup, and profile
2 parents eb5dd99 + 850bfb4 commit a395c81

File tree

9 files changed

+72
-14
lines changed

9 files changed

+72
-14
lines changed

app/components/Login.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { useContext, useState, useCallback } from 'react';
1+
/* eslint-disable jsx-a11y/label-has-associated-control */
2+
import React, { useContext, useState } from 'react';
23
import { useHistory } from 'react-router-dom';
34
import { DashboardContext } from '../context/DashboardContext';
45

@@ -7,14 +8,15 @@ const { ipcRenderer } = window.require('electron');
78
const Login = React.memo(() => {
89
const history = useHistory();
910
const { updateLandingPage, setAuth, setUser } = useContext(DashboardContext);
10-
const [, setState] = useState<{}>();
11+
const [failedAuth, setFailedAuthState] = useState<JSX.Element>(<></>);
1112

12-
const forceUpdate = useCallback(() => setState({}), []);
1313
const handleSubmit = (e: any) => {
1414
e.preventDefault();
1515
const inputFields = e.currentTarget.querySelectorAll('input');
1616
const email = inputFields[0].value;
1717
const password = inputFields[1].value;
18+
// eslint-disable-next-line no-return-assign
19+
inputFields.forEach(input => (input.value = ''));
1820
const validLogin:
1921
| boolean
2022
| string
@@ -30,7 +32,7 @@ const Login = React.memo(() => {
3032
setAuth(true);
3133
history.push('/applications');
3234
} else if (validLogin === 'awaitingApproval') history.push('/awaitingApproval');
33-
else forceUpdate();
35+
else setFailedAuthState(<p>Sorry your authentication failed please try again.</p>);
3436
};
3537

3638
return (
@@ -39,13 +41,13 @@ const Login = React.memo(() => {
3941
<h1>Welcome to Chronos!</h1>
4042
<h2>Please enter your credentials to login.</h2>
4143
<form className="form" onSubmit={handleSubmit}>
42-
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
4344
<label className="email">
4445
<input type="email" name="email" id="email" placeholder="[email protected]" />
4546
</label>
4647
<label className="password">
4748
<input type="password" name="password" id="password" placeholder="enter password" />
4849
</label>
50+
{failedAuth}
4951
<button className="link" id="submitBtn" type="submit">
5052
Login
5153
</button>

app/components/Occupied.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import PersonIcon from '@material-ui/icons/Person';
3030
import UpdateIcon from '@material-ui/icons/Update';
3131
// MODALS
3232
import AddModal from '../modals/AddModal';
33-
import AddsModal from '../modals/AddsModal';
33+
import ProfileContainer from '../containers/ProfileContainer';
3434
import ServicesModal from '../modals/ServicesModal';
3535
import Search from '../components/icons/Search';
3636

@@ -324,7 +324,7 @@ const Occupied = React.memo(() => {
324324
</Modal>
325325

326326
<Modal open={addsOpen} onClose={() => setAddsOpen(false)}>
327-
<AddsModal setOpen={setAddsOpen} />
327+
<ProfileContainer setOpen={setAddsOpen} />
328328
</Modal>
329329

330330
<Modal open={open} onClose={() => setOpen(false)}>

app/components/SignUp.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { useContext } from 'react';
1+
/* eslint-disable jsx-a11y/label-has-associated-control */
2+
import React, { useContext, useState } from 'react';
23
import { useHistory } from 'react-router-dom';
34
import { DashboardContext } from '../context/DashboardContext';
45
import '../stylesheets/Home.scss';
@@ -8,13 +9,16 @@ const { ipcRenderer } = window.require('electron');
89
const SignUp = React.memo(() => {
910
const history = useHistory();
1011
const { updateLandingPage, setAuth, setUser } = useContext(DashboardContext);
12+
const [failedSignUp, setFailedSignUp] = useState<JSX.Element>(<></>);
1113

1214
const handleSubmit = (e: any) => {
1315
e.preventDefault();
1416
const inputFields = e.currentTarget.querySelectorAll('input');
1517
const username = inputFields[0].value;
1618
const email = inputFields[1].value;
1719
const password = inputFields[2].value;
20+
// eslint-disable-next-line no-return-assign
21+
inputFields.forEach(input => (input.value = ''));
1822

1923
const validSignUp:
2024
| boolean
@@ -30,7 +34,8 @@ const SignUp = React.memo(() => {
3034
setAuth(true);
3135
history.push('/applications');
3236
} else if (validSignUp) history.push('/awaitingApproval');
33-
else window.alert('Sorry your sign up cannot be completed at this time. Please try again.');
37+
else
38+
setFailedSignUp(<p>Sorry your sign up failed. Please try a different email and password.</p>);
3439
};
3540

3641
return (
@@ -50,7 +55,7 @@ const SignUp = React.memo(() => {
5055
<label className="password">
5156
<input type="password" name="password" id="password" placeholder="enter password" />
5257
</label>
53-
58+
{failedSignUp}
5459
<button className="link" id="submitBtn" type="submit">
5560
Sign Up
5661
</button>

app/containers/ProfileContainer.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, { useContext } from 'react';
2+
import AddsModal from '../modals/AddsModal';
3+
import SetAuth from '../modals/SetAuth';
4+
import { DashboardContext } from '../context/DashboardContext';
5+
6+
interface Props {
7+
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
8+
}
9+
10+
const ProfileContainer: React.FC<Props> = React.memo(({ setOpen }) => {
11+
const { landingPage } = useContext(DashboardContext);
12+
13+
if (landingPage === 'dashBoard') return <SetAuth setOpen={setOpen} />;
14+
return <AddsModal setOpen={setOpen} />;
15+
});
16+
17+
export default ProfileContainer;

app/modals/AddsModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const AddsModal: React.FC<AddsModalProps> = React.memo(({ setOpen }) => {
3232
const listItems: Array<JSX.Element> = [];
3333
for (const pleb in usersObj) {
3434
listItems.push(
35-
<li>
35+
<li key={pleb}>
3636
<span>
3737
<div>
3838
<span className="label">Email:</span> {usersObj[pleb].email}{' '}

app/modals/SetAuth.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, { useContext } from 'react';
2+
import { DashboardContext } from '../context/DashboardContext';
3+
4+
interface Props {
5+
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
6+
}
7+
8+
const SetAuthModal: React.FC<Props> = React.memo(({ setOpen }) => {
9+
const { updateLandingPage } = useContext(DashboardContext);
10+
const handleClick = () => {
11+
updateLandingPage('createAdmin');
12+
location.replace('/');
13+
};
14+
15+
return (
16+
<div className="add-container">
17+
<div className="add-header">
18+
<div>
19+
<h2>Welcome Back</h2>
20+
</div>
21+
<form onSubmit={e => e.preventDefault()}>
22+
<br />
23+
<div />
24+
<button onClick={() => setOpen(false)}>Cancel</button>
25+
<br />
26+
<button className="link" onClick={handleClick}>
27+
Add Authentication
28+
</button>
29+
</form>
30+
</div>
31+
</div>
32+
);
33+
});
34+
35+
export default SetAuthModal;

settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"setupRequired":false,"services":[["myPostgres","SQL","postgres://zwezmnqm:[email protected]:5432/zwezmnqm","Online bookstore with that keeps track of orders and customers","Jun 28, 2020 4:58 PM"],["ToddDB","MongoDB","mongodb+srv://tdwolf6:[email protected]/Chronos?retryWrites=true&w=majority","Web app deployed on AWS","Jul 3, 2020 7:12AM"]],"mode":"dark mode","splash":true,"landingPage":"login"}
1+
{"setupRequired":false,"services":[["myPostgres","SQL","postgres://zwezmnqm:[email protected]:5432/zwezmnqm","Online bookstore with that keeps track of orders and customers","Jun 28, 2020 4:58 PM"],["ToddDB","MongoDB","mongodb+srv://tdwolf6:[email protected]/Chronos?retryWrites=true&w=majority","Web app deployed on AWS","Jul 3, 2020 7:12AM"]],"mode":"dark mode","splash":true}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"sourceMap": true,
1010
"module": "commonjs",
1111
"allowJs": true,
12-
"target": "es6",
12+
"target": "es2019",
1313
"jsx": "react",
1414
"esModuleInterop": true,
1515
"resolveJsonModule": true,

users.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)