Skip to content

Commit 37a8c18

Browse files
Add a new Login page that get redirected to if user is not logged
1 parent 04fc70b commit 37a8c18

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

src/Routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import CreateNewEvent from './components/CreateNewEvent';
1212
import Settings from './views/pages/settings/Settings';
1313
import LandingPage from './views/pages/HomeView/LandingPage';
1414
import AuthGuard from './components/auth/AuthGuard';
15+
import LoginPage from 'src/views/pages/login';
1516

1617
const renderRoutes = () => (
1718
<Suspense fallback={<LoadingScreen />}>
1819
<Switch>
1920
<Route path="/" exact render={() => <LandingPage />} />
2021
<Route path="/register" exact render={() => <Register />} />
22+
<Route path="/login" exact render={() => <LoginPage />} />
2123
<Route
2224
path="/dashboard"
2325
exact

src/components/auth/AuthGuard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function AuthGuard({ children }) {
77
const user = getLoggedUser();
88

99
if (!user) {
10-
return <Redirect to="/" />;
10+
return <Redirect to="/login" />;
1111
}
1212

1313
return children;

src/views/pages/login/index.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { makeStyles, Typography, Button } from '@material-ui/core';
2+
import React from 'react';
3+
import { signInWithGoogle } from 'src/services/authService';
4+
import { useHistory } from 'react-router-dom';
5+
import clsx from 'clsx';
6+
7+
const useStyles = makeStyles(theme => ({
8+
root: {
9+
background:
10+
'linear-gradient(269.76deg, #180255 0.18%, #000000 53.35%, #000000 107.44%)',
11+
height: '100vh',
12+
textAlign: 'center'
13+
},
14+
container: {
15+
color: '#fff',
16+
margin: 'auto',
17+
textAlign: 'center',
18+
verticalAlign: 'center',
19+
position: 'absolute',
20+
top: '50%',
21+
left: '50%',
22+
msTransform: 'translate(-50%, -50%)',
23+
transform: 'translate(-50%, -50%)',
24+
maxWidth: 450
25+
},
26+
typography: {
27+
margin: '40px 0px 10px'
28+
},
29+
btn: {
30+
backgroundColor: '#cccccc',
31+
color: '#000',
32+
'&:hover': {
33+
backgroundColor: '#ceeeee'
34+
}
35+
},
36+
parentbtn: {
37+
backgroundColor: '#A60000',
38+
color: '#ffffff',
39+
padding: '8px 16px',
40+
fontWeight: 700,
41+
textTransform: 'capitalize',
42+
[theme.breakpoints.down('sm')]: {
43+
width: '100%'
44+
},
45+
'&:hover': {
46+
backgroundColor: 'rgba(166, 0, 0, 0.8)'
47+
}
48+
}
49+
}));
50+
51+
export default function Login() {
52+
const classes = useStyles();
53+
const history = useHistory();
54+
55+
const handleSignInWithGoogle = () => {
56+
signInWithGoogle()
57+
.then(() => {
58+
history.push('/');
59+
})
60+
.catch(e => {
61+
console.log('error', e);
62+
});
63+
};
64+
65+
return (
66+
<div className={classes.root}>
67+
<div className={classes.container}>
68+
<Typography variant="h2" className={classes.typography}>
69+
Sign In / Sign Up
70+
</Typography>
71+
<Typography style={{ marginBottom: '40px' }}>
72+
Login to Manage your events with CauseFolio
73+
</Typography>
74+
<ButtonComponent
75+
title="Sign In with Google"
76+
className={classes.btn}
77+
onClick={handleSignInWithGoogle}
78+
fullWidth
79+
icon={
80+
<img
81+
src={'https://image.flaticon.com/icons/png/32/2702/2702602.png'}
82+
style={{ marginRight: '16px' }}
83+
alt="G-Icon"
84+
/>
85+
}
86+
/>
87+
<Typography
88+
variant="caption"
89+
style={{ display: 'block', marginTop: '40px', fontSize: '10px' }}
90+
>
91+
By continuing, you agree to Code For Cause Terms of Use & Privacy
92+
policy.
93+
</Typography>
94+
</div>
95+
</div>
96+
);
97+
}
98+
99+
function ButtonComponent({ className, title, icon = '', ...rest }) {
100+
const classes = useStyles();
101+
return (
102+
<Button className={clsx(classes.btn, className)} {...rest}>
103+
{icon}
104+
{title}
105+
</Button>
106+
);
107+
}

0 commit comments

Comments
 (0)