Skip to content

Commit

Permalink
Revert "Revert "feat: session expired modal (#933)" (#1040)"
Browse files Browse the repository at this point in the history
This reverts commit b6a3b28.
  • Loading branch information
brrkrmn committed Dec 28, 2023
1 parent d5f2d0e commit 2484f51
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 47 deletions.
6 changes: 6 additions & 0 deletions zubhub_frontend/zubhub/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1190,5 +1190,11 @@
"text": "Get inspired by thousands of creators around the world.",
"buttonLabel": "Get Started"
}
},
"sessionExpired": {
"heading": "Session Expired",
"title": "Your session has expired",
"text": "You will be redirected to the login page.",
"buttonLabel": "ok"
}
}
6 changes: 6 additions & 0 deletions zubhub_frontend/zubhub/public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1092,5 +1092,11 @@
"text": "दुनिया भर के हजारों रचनाकारों से प्रेरणा लें।",
"buttonLabel": "शुरू हो जाओ"
}
},
"sessionExpired": {
"heading": "सत्र समाप्त",
"title": "आपका सत्र समाप्त हो गया है",
"text": "आप लॉगिन पेज पर रीडायरेक्ट किए जाएंगे।",
"buttonLabel": "ठीक है"
}
}
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: 2 additions & 1 deletion zubhub_frontend/zubhub/src/components/modals/modal.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const modalStyles = theme => ({
dialogContainer: {
'& .MuiDialog-paper': {
overflow: 'visible !important'
}
},
backdropFilter: 'blur(15px)',
},
dialogPaper: {
borderRadius: 8,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
export const sessionExpiredStyle = theme => ({
card: {
borderRadius: 12,
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
boxShadow: theme.shadows[5],
overflow: 'hidden',
width: '90%',
zIndex: 1300,
[theme.breakpoints.up('sm')]: {
width: 500,
},
},
cardHeader: {
backgroundColor: theme.palette.primary.main,
color: theme.palette.common.white,
padding: theme.spacing(1),
[theme.breakpoints.up('sm')]: {
padding: theme.spacing(1, 2),
},
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
},
cardContent: {
padding: theme.spacing(1),
[theme.breakpoints.up('sm')]: {
padding: theme.spacing(2),
},
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
},
closeButton: {
cursor: 'pointer',
color: theme.palette.common.white,
},
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: theme.palette.background.paper,
backdropFilter: 'blur(5px)',
},
textDecorationNone: {
width: '100%',
marginTop: theme.spacing(2),
},
customButtonStyle: {
backgroundColor: theme.palette.primary.main,
color: theme.palette.common.white,
'&:hover': {
backgroundColor: theme.palette.primary.main,
},
},
buttonContainer: {
display: 'flex',
justifyContent: 'center',
marginTop: theme.spacing(2),
},
errorIcon: {
fontSize: 60,
color: 'var(--primary-color1)',
},
titleStyle: {
fontSize: '1.2rem',
[theme.breakpoints.up('sm')]: {
fontSize: '1.5rem',
},
fontWeight: 600,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import clsx from 'clsx';
import { Card, CardContent, Typography, ErrorOutline } 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 CloseIcon from '@material-ui/icons/Close';
import ErrorOutlineIcon from '@material-ui/icons/ErrorOutline';

const useStyles = makeStyles(sessionExpiredStyle);

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

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

return (
<Modal open={modalOpen}>
<Card className={classes.card}>
<div className={classes.cardHeader}>
<Typography variant="h6">{t(`sessionExpired.heading`)}</Typography>
<Typography variant="button" className={classes.closeButton} onClick={handleClose}>
<CloseIcon />
</Typography>
</div>
<CardContent className={classes.cardContent}>
<div className={classes.iconWrapper}>
<ErrorOutlineIcon className={clsx(classes.icon, classes.errorIcon)} />
</div>
<Typography
variant="body1"
color="textPrimary"
className={clsx(classes.centerText, classes.titleStyle)}
>
{t(`sessionExpired.title`)}
</Typography>
<Typography
variant="body2"
className={classes.centerText}
>
{t(`sessionExpired.text`)}
</Typography>
<div className={classes.buttonContainer}>
<Link to="/login" className={classes.textDecorationNone}>
<CustomButton
variant="outlined"
size="small"
primaryButtonStyle
customButtonStyle
>
{t(`sessionExpired.buttonLabel`)}
</CustomButton>
</Link>
</div>
</CardContent>
</Card>
</Modal>
);
};

export default SessionExpiredModal;
3 changes: 2 additions & 1 deletion zubhub_frontend/zubhub/src/store/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const logout = args => {
*/
export const getAuthUser = props => {
return dispatch => {
return API.getAuthUser(props.auth.token)
return API.getAuthUser(props.auth.token)
.then(res => {
if (!res.id) {
dispatch(
Expand Down Expand Up @@ -121,6 +121,7 @@ export const getAuthUser = props => {
};
};


export const AccountStatus = args => {
return () => {
return API.getAccountStatus(args.token).catch(() => {
Expand Down
68 changes: 25 additions & 43 deletions zubhub_frontend/zubhub/src/views/PageWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,36 @@ function PageWrapper(props) {
setPrevScrollPos(currentScrollPos);
}, [prevScrollPos]);

useEffect(() => {
if (!props.auth.token) {
props.history.push('/session-expired')
}
}, [props.auth.token])

useEffect(() => {
window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, [handleScroll]);

const unprotectedRoutes = [
'/',
'/signup',
'/login',
'/password-reset',
'/projects/:id',
'/ambassadors',
'/creators/:username',
'/privacy_policy',
'/terms_of_use',
'/about',
'/challenge',
'/email-confirm',
'/password-reset-confirm',
'/session-expired'
];

const throttledFetchOptions = useMemo(
() =>
throttle(async (query, searchType) => {
Expand Down Expand Up @@ -165,19 +188,6 @@ function PageWrapper(props) {
throttledFetchOptions.cancel();
}, []);

useEffect(() => {
handleSetState({ loading: true });
fetchHero(props)
.then(() => {
if (props.auth.token) {
return props.getAuthUser(props);
}
})
.finally(() => {
handleSetState({ loading: false });
});
}, [props.auth.token]);

useEffect(() => {
handleSetState(handleProfileMenuClose());
}, [trigger]);
Expand Down Expand Up @@ -240,42 +250,14 @@ function PageWrapper(props) {
<Container className={classes.childrenContainer} maxWidth="lg">
{props.auth?.token ? <DashboardLayout>{loading ? <LoadingPage /> : props.children}</DashboardLayout> : null}
{!props.auth?.token &&
![
'/',
'/signup',
'/login',
'/projects/:id',
'/ambassadors',
'/creators/:username',
'/privacy_policy',
'/terms_of_use',
'/about',
'/challenge',
'/password-reset',
'/email-confirm',
'/password-reset-confirm'
].includes(props.match?.path) && (
!unprotectedRoutes.includes(props.match?.path) && (
<div style={{ minHeight: '80vh' }}>
<NotFoundPage />
</div>
)}
</Container>
{!props.auth?.token &&
[
'/',
'/signup',
'/login',
'/password-reset',
'/projects/:id',
'/ambassadors',
'/creators/:username',
'/privacy_policy',
'/terms_of_use',
'/about',
'/challenge',
'/email-confirm',
'/password-reset-confirm'
].includes(props.match?.path) && <div style={{ minHeight: '90vh' }}>{props.children}</div>}
unprotectedRoutes.includes(props.match?.path) && <div style={{ minHeight: '90vh' }}>{props.children}</div>}

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

0 comments on commit 2484f51

Please sign in to comment.