Skip to content
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

session expired modal #933

Merged
merged 18 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
11 changes: 9 additions & 2 deletions zubhub_frontend/zubhub/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import ProtectedRoute from './components/protected_route/ProtectedRoute';
import ZubhubAPI from '../src/api/api';
import { updateTheme } from './theme';
import ScrollToTop from './ScrollToTop';
import SessionExpiredModal from './components/sessionExpired/sessionExpired';

const SearchResults = React.lazy(() => import('./views/search_results/SearchResults'));

const Signup = React.lazy(() => import('./views/signup/Signup'));
const Login = React.lazy(() => import('./views/login/Login'));
const PasswordReset = React.lazy(() => import('./views/password_reset/PasswordReset'));
Expand Down Expand Up @@ -492,7 +492,14 @@ function App(props) {
</PageWrapper>
)}
/>

<Route
path="/session-expired"
render={routeProps => (
<PageWrapper {...routeProps} {...props}>
<LazyImport LazyComponent={SessionExpiredModal} {...routeProps} {...props} />
</PageWrapper>
)}
/>
<Route
path="*"
render={routeProps => (
Expand Down
3 changes: 3 additions & 0 deletions zubhub_frontend/zubhub/src/assets/images/session_expired.svg
yokwejuste marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export const sessionExpiredStyle = theme => ({
card: {
width: 500,
borderRadius: 12,
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
boxShadow: theme.shadows[5],
overflow: 'hidden',
},
cardHeader: {
backgroundColor: '#f44336',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use color from theme

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This color is left. This should be our primary color red

color: '#fff',
yokwejuste marked this conversation as resolved.
Show resolved Hide resolved
padding: theme.spacing(1, 2),
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
},
cardContent: {
padding: theme.spacing(2),
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
},
closeButton: {
cursor: 'pointer',
color: '#fff',
},
iconWrapper: {
marginBottom: theme.spacing(2),
display: 'flex',
justifyContent: 'center',
},
centerText: {
textAlign: 'center',
marginBottom: theme.spacing(1),
},
modal: {
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100vw',
height: '100vh',
backgroundColor: 'rgba(255, 233, 154, 0.5)',
backdropFilter: 'blur(25px)',
},
textDecorationNone: {
width: '100%',
marginTop: theme.spacing(2),
},
customButtonStyle: {
backgroundColor: '#4CAF50',
yokwejuste marked this conversation as resolved.
Show resolved Hide resolved
color: '#fff',
'&:hover': {
backgroundColor: '#388E3C',
},
},
buttonContainer: {
display: 'flex',
justifyContent: 'center',
marginTop: theme.spacing(2),
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useState } from 'react';
import { Card, CardContent, Typography } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import { useHistory, Link } from 'react-router-dom';
import { sessionExpiredStyle } from './sessionExpired.Style';
import Modal from '../modals/Modal';
import CustomButton from '../button/Button';
import ExpiredSessionIcon from '../../assets/images/session_expired.svg';
import CloseIcon from '@material-ui/icons/Close';

const useStyles = makeStyles(sessionExpiredStyle);

const SessionExpiredModal = () => {
const classes = useStyles();
const [modalOpen, setModalOpen] = useState(true);
const history = useHistory();

const handleClose = () => {
setModalOpen(false);
history.push('/login');
};

return (
<Modal open={modalOpen} className={classes.modal}>
<Card className={classes.card}>
<div className={classes.cardHeader}>
<Typography variant="h6">Session Expired</Typography>
yokwejuste marked this conversation as resolved.
Show resolved Hide resolved
<Typography variant="button" className={classes.closeButton} onClick={handleClose}>
<CloseIcon />
</Typography>
</div>
<CardContent className={classes.cardContent}>
<div className={classes.iconWrapper}>
<img src={ExpiredSessionIcon} alt="expired session icon" className={classes.icon} />
</div>
<Typography variant="body1" className={classes.centerText}>Your session has expired</Typography>
<Typography variant="body2" className={classes.centerText}>You will be redirected to the login page</Typography>
<div className={classes.buttonContainer}>
<Link to="/login" className={classes.textDecorationNone}>
<CustomButton
variant="outlined"
size="small"
primaryButtonStyle
customButtonStyle
>
OK
yokwejuste marked this conversation as resolved.
Show resolved Hide resolved
</CustomButton>
</Link>
</div>
</CardContent>
</Card>
</Modal>
);
};

export default SessionExpiredModal;
7 changes: 5 additions & 2 deletions zubhub_frontend/zubhub/src/store/actions/authActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ZubhubAPI from '../../api';
import { toast } from 'react-toastify';
import sessionExpiredModal from '../../components/sessionExpired/sessionExpired';

const API = new ZubhubAPI();

Expand Down Expand Up @@ -80,7 +81,8 @@ export const logout = args => {
*/
export const getAuthUser = props => {
return dispatch => {
return API.getAuthUser(props.auth.token)
return API.getAuthUser('props.auth.token')
// return API.getAuthUser(props.auth.token)
.then(res => {
if (!res.id) {
dispatch(
Expand All @@ -90,7 +92,7 @@ export const getAuthUser = props => {
t: props.t,
}),
).then(() => {
props.history.push('/account-status');
props.history.push('/session-expired');
yokwejuste marked this conversation as resolved.
Show resolved Hide resolved
});
throw new Error(props.t('pageWrapper.errors.unexpected'));
} else {
Expand All @@ -113,6 +115,7 @@ export const getAuthUser = props => {
};
};


export const AccountStatus = args => {
return () => {
return API.getAccountStatus(args.token).catch(() => {
Expand Down
6 changes: 4 additions & 2 deletions zubhub_frontend/zubhub/src/views/PageWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ function PageWrapper(props) {
'/challenge',
'/password-reset',
'/email-confirm',
'/password-reset-confirm'
'/password-reset-confirm',
'/session-expired'
].includes(props.match?.path) && (
<div style={{ minHeight: '80vh' }}>
<NotFoundPage />
Expand All @@ -274,7 +275,8 @@ function PageWrapper(props) {
'/about',
'/challenge',
'/email-confirm',
'/password-reset-confirm'
'/password-reset-confirm',
'/session-expired'
].includes(props.match?.path) && <div style={{ minHeight: '90vh' }}>{props.children}</div>}

<footer className={clsx('footer-distributed', classes.footerStyle)}>
Expand Down