Skip to content

Commit

Permalink
Merge pull request #137 from VikramjeetD/redirect
Browse files Browse the repository at this point in the history
Redirect fixes
  • Loading branch information
Aviral14 authored Jun 13, 2020
2 parents 4a62b66 + 1a79698 commit d37011d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
39 changes: 20 additions & 19 deletions client/src/components/authorization/CheckLoggedIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ import { Redirect } from "react-router-dom";
import { useGetData } from "use-axios-react";
import { connect } from "react-redux";
import { verifyLogin } from "../../redux/actions/auth";
import { makeStyles } from '@material-ui/core/styles';
import LinearProgress from '@material-ui/core/LinearProgress';
import CircularProgress from '@material-ui/core/CircularProgress';
import { makeStyles } from "@material-ui/core/styles";
import LinearProgress from "@material-ui/core/LinearProgress";
import CircularProgress from "@material-ui/core/CircularProgress";

const CheckLoggedIn = ({ verifyLogin }) => {
useEffect(() => {
verifyLogin();
}, [verifyLogin]);
const [userInfo, loading] = useGetData("/api/current_user");
const useStyles = makeStyles((theme) => ({
const useStyles = makeStyles(theme => ({
root: {
width: '100%',
'& > * + *': {
marginTop: theme.spacing(2),
},
},
width: "100%",
"& > * + *": {
marginTop: theme.spacing(2)
}
}
}));

const useStylesCircular = makeStyles((theme) => ({
const useStylesCircular = makeStyles(theme => ({
root: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
'& > * + *': {
display: "flex",
alignItems: "center",
justifyContent: "center",
"& > * + *": {
marginLeft: theme.spacing(2),
marginTop: theme.spacing(2),
},
},
marginTop: theme.spacing(2)
}
}
}));
const Cclasses = useStylesCircular();
const classes = useStyles();
if (loading) {
if (loading || (localStorage.getItem("loggedIn") && !userInfo)) {
return (
<>
<div className={classes.root}>
Expand All @@ -43,7 +43,8 @@ const CheckLoggedIn = ({ verifyLogin }) => {
<div className={Cclasses.root}>
<CircularProgress />
</div>
</>/*<Redirect to='/checkloggedin'></Redirect>*/);
</> /*<Redirect to='/checkloggedin'></Redirect>*/
);
} else if (!userInfo) {
return <Redirect to='/'></Redirect>;
} else {
Expand Down
34 changes: 32 additions & 2 deletions client/src/components/routes/PrivateRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { useGetData } from "use-axios-react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { verifyLogin } from "../../redux/actions/auth";
import { makeStyles } from "@material-ui/core/styles";
import LinearProgress from "@material-ui/core/LinearProgress";
import CircularProgress from "@material-ui/core/CircularProgress";

const PrivateRoute = ({
component: Component,
Expand All @@ -13,16 +16,43 @@ const PrivateRoute = ({
...rest
}) => {
const [userInfo, loading] = useGetData("/api/current_user");
const useStyles = makeStyles(theme => ({
root: {
width: "100%",
"& > * + *": {
marginTop: theme.spacing(2)
}
}
}));

const useStylesCircular = makeStyles(theme => ({
root: {
display: "flex",
alignItems: "center",
justifyContent: "center",
"& > * + *": {
marginLeft: theme.spacing(2),
marginTop: theme.spacing(2)
}
}
}));
const Cclasses = useStylesCircular();
const classes = useStyles();
return (
<Route
{...rest}
render={props =>
!localStorage.getItem("loggedIn") ? (
<Redirect to='/'></Redirect>
) : loading ? (
// Put a cool animation here
<div>Loading...</div>
<>
<div className={classes.root}>
<LinearProgress />
</div>
<div className={Cclasses.root}>
<CircularProgress />
</div>
</>
) : !((!submitted && userInfo.submittedForm) || submitted) ? (
<Redirect to='/helform'></Redirect>
) : (
Expand Down
12 changes: 8 additions & 4 deletions client/src/components/tabs/Landing.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from "react";
import "../../styles/Landing.css";
import configuration from "../../config/constants.js";
import { useGetData } from "use-axios-react";
import { Redirect } from "react-router-dom";

export const Landing = () => {
return (
const [userInfo, loading] = useGetData("/api/current_user");
return userInfo && localStorage.getItem("loggedIn") ? (
<Redirect to='/checkloggedin'></Redirect>
) : (
<section className='landing body'>
<div className='dark-overlay'>
<div className='landing-inner'>
Expand All @@ -26,11 +32,9 @@ export const Landing = () => {
</div>
</div>
</div>
<div>
</div>
<div></div>
</section>
);
};


export default Landing;

0 comments on commit d37011d

Please sign in to comment.