Skip to content

Commit 09198c7

Browse files
angelocordonlpatmo
authored andcommitted
Move SignUpForm and LoginForm to AuthForm component
Use Authform component as a container to handle presentational logic for SignUpForm and LoginForm. Add PropTypes module and proptypes to components.
1 parent 0fa1bf8 commit 09198c7

File tree

5 files changed

+126
-10
lines changed

5 files changed

+126
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"axios": "0.19.0",
2424
"json-server": "0.15.1",
2525
"npm-run-all": "4.1.5",
26+
"prop-types": "^15.7.2",
2627
"react": "16.11.0",
2728
"react-dom": "16.11.0",
2829
"react-router-dom": "5.1.2",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { useState } from 'react';
2+
import { Box, Paper } from '@material-ui/core/';
3+
import SignUpForm from './SignUpForm';
4+
import LoginForm from './LoginForm';
5+
6+
const AuthForm = () => {
7+
const [activeSignUpForm, setActiveSignUpform] = useState(true);
8+
9+
const toggleActiveForm = event => {
10+
event.preventDefault();
11+
setActiveSignUpform(!activeSignUpForm);
12+
};
13+
14+
return (
15+
<Box component={Paper} elevetion={3} padding={3}>
16+
{activeSignUpForm && <SignUpForm toggleActiveForm={toggleActiveForm} />}
17+
{!activeSignUpForm && <LoginForm toggleActiveForm={toggleActiveForm} />}
18+
</Box>
19+
);
20+
};
21+
22+
export default AuthForm;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Box, Button, TextField } from '@material-ui/core/';
4+
5+
const LoginForm = ({ toggleActiveForm }) => {
6+
return (
7+
<Box
8+
component="form"
9+
display="flex"
10+
flexWrap="wrap"
11+
noValidate
12+
autoComplete="off"
13+
>
14+
<Box component="h1" fontSize={18}>
15+
Log in
16+
</Box>
17+
<TextField
18+
id="email"
19+
label="Email"
20+
fullWidth
21+
required
22+
variant="outlined"
23+
margin="dense"
24+
type="email"
25+
/>
26+
<TextField
27+
id="password"
28+
label="Password"
29+
fullWidth
30+
required
31+
variant="outlined"
32+
margin="dense"
33+
type="password"
34+
/>
35+
36+
<Box width="100%" marginTop={2}>
37+
<Button variant="contained" color="primary">
38+
Log in
39+
</Button>
40+
</Box>
41+
42+
<p>
43+
Need an account?{' '}
44+
<Box
45+
component="button"
46+
color="primary.main"
47+
padding={0}
48+
marginLeft={1}
49+
border={0}
50+
bgcolor="transparent"
51+
fontSize={16}
52+
onClick={toggleActiveForm}
53+
>
54+
Sign up
55+
</Box>
56+
.
57+
</p>
58+
</Box>
59+
);
60+
};
61+
62+
const { func } = PropTypes;
63+
64+
LoginForm.propTypes = {
65+
toggleActiveForm: func.isRequired,
66+
};
67+
68+
export default LoginForm;

src/components/Home/SignUpForm.js renamed to src/components/Home/AuthForms/SignUpForm.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import { Box, Button, TextField } from '@material-ui/core/';
34

4-
const SignUpForm = () => {
5+
const SignUpForm = ({ toggleActiveForm }) => {
56
return (
67
<Box
78
component="form"
@@ -10,6 +11,9 @@ const SignUpForm = () => {
1011
noValidate
1112
autoComplete="off"
1213
>
14+
<Box component="h1" fontSize={18}>
15+
Create an account
16+
</Box>
1317
<TextField
1418
id="first-name"
1519
label="First Name"
@@ -51,13 +55,36 @@ const SignUpForm = () => {
5155
type="password"
5256
/>
5357

54-
<Button variant="contained" color="primary">
55-
Sign Up
56-
</Button>
58+
<Box width="100%" marginTop={2}>
59+
<Button variant="contained" color="primary">
60+
Sign Up
61+
</Button>
62+
</Box>
5763

58-
<p>Already have an account? Log in.</p>
64+
<p>
65+
Already have an account?
66+
<Box
67+
component="button"
68+
color="primary.main"
69+
padding={0}
70+
marginLeft={1}
71+
border={0}
72+
bgcolor="transparent"
73+
fontSize={16}
74+
onClick={toggleActiveForm}
75+
>
76+
Log in
77+
</Box>
78+
.
79+
</p>
5980
</Box>
6081
);
6182
};
6283

84+
const { func } = PropTypes;
85+
86+
SignUpForm.propTypes = {
87+
toggleActiveForm: func.isRequired,
88+
};
89+
6390
export default SignUpForm;

src/components/Home/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import { Box, Grid, Paper } from '@material-ui/core/';
3-
import SignUpForm from './SignUpForm';
2+
import { Box, Grid } from '@material-ui/core/';
3+
import AuthForm from './AuthForms/AuthForm';
44

55
const Home = () => {
66
return (
@@ -24,9 +24,7 @@ const Home = () => {
2424
</Box>
2525
</Grid>
2626
<Grid item xs={12} sm={5}>
27-
<Box component={Paper} elevetion={3} padding={3}>
28-
<SignUpForm />
29-
</Box>
27+
<AuthForm />
3028
</Grid>
3129
</Grid>
3230
);

0 commit comments

Comments
 (0)