Created
August 7, 2020 12:41
-
-
Save Kannndev/1d80c78eb03830e353c29c2b5392505a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from 'react'; | |
import PropTypes from 'prop-types'; | |
import loader from 'images/hire-loader.gif'; | |
import { Redirect, matchPath } from 'react-router-dom'; | |
import { ROLE_INTERVIEWER } from 'containers/App/constants'; | |
function EmptyRouteComponent({ | |
loggedInUserInfo, | |
history, | |
location, | |
dispatchLoggedInUserInfo, | |
}) { | |
const userLoggedIn = | |
loggedInUserInfo && Object.entries(loggedInUserInfo).length; | |
const defaultRedirectRoute = | |
userLoggedIn && | |
loggedInUserInfo && | |
loggedInUserInfo.roles && | |
loggedInUserInfo.roles[0].name !== ROLE_INTERVIEWER | |
? '/home' | |
: '/calendar'; | |
useEffect(() => { | |
if (userLoggedIn) { | |
if ( | |
matchPath(location.pathname, { | |
path: '/', | |
exact: true, | |
strict: false, | |
}) | |
) { | |
history.push(defaultRedirectRoute); | |
} | |
} else { | |
dispatchLoggedInUserInfo(); | |
} | |
}, [loggedInUserInfo]); | |
return !userLoggedIn ? ( | |
<div | |
style={{ | |
height: '80vh', | |
display: 'flex', | |
alignItems: 'center', | |
justifyContent: 'center', | |
}} | |
> | |
<img | |
style={{ | |
border: 'solid 2px whitesmoke', | |
height: '150px', | |
}} | |
src={loader} | |
alt="" | |
/> | |
</div> | |
) : ( | |
<Redirect to={defaultRedirectRoute} /> | |
); | |
} | |
EmptyRouteComponent.propTypes = { | |
loggedInUserInfo: PropTypes.object, | |
location: PropTypes.object, | |
history: PropTypes.object, | |
dispatchLoggedInUserInfo: PropTypes.func, | |
}; | |
export default EmptyRouteComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment