generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix-header.dropdown-resize
- Loading branch information
Showing
7 changed files
with
162 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
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
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
91 changes: 91 additions & 0 deletions
91
src/customizations/volto/components/theme/Unauthorized/Unauthorized.jsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* @module components/theme/Unauthorized/Unauthorized | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import { useLocation, Link, useHistory } from 'react-router-dom'; | ||
import { getBaseUrl } from '@plone/volto/helpers'; | ||
import { Container, Button } from 'semantic-ui-react'; | ||
|
||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { withServerErrorCode } from '@plone/volto/helpers/Utils/Utils'; | ||
|
||
/** | ||
* unauthorized function. | ||
* @function Unauthorized | ||
* @returns {string} Markup of the unauthorized page. | ||
*/ | ||
|
||
const Unauthorized = () => { | ||
const location = useLocation(); | ||
const pathname = location.pathname; | ||
const base_pathname = getBaseUrl(pathname); | ||
const login = `${base_pathname}/login`; | ||
const history = useHistory(); | ||
const [countdown, setCountdown] = React.useState(5); | ||
|
||
useEffect(() => { | ||
const login_with_return = login + `?return_url=${pathname}`; | ||
const timer = setTimeout(() => { | ||
return history.push(login_with_return); | ||
}, 5000); | ||
return () => clearTimeout(timer); | ||
}, [history, login, pathname]); | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
if (countdown > 0) { | ||
setCountdown(countdown - 1); | ||
} else { | ||
clearTimeout(timer); | ||
} | ||
}, 1000); | ||
// Clear timeout if the component is unmounted | ||
return () => clearTimeout(timer); | ||
}, [countdown]); | ||
|
||
return ( | ||
<Container className="view-wrapper"> | ||
<h1> | ||
<FormattedMessage id="Unauthorized" defaultMessage="Unauthorized" /> | ||
</h1> | ||
<h3> | ||
<FormattedMessage | ||
id="Forbidden, you will be redirected to the login screen in " | ||
defaultMessage="Forbidden, you will be redirected to the login screen in " | ||
/> | ||
<span id="redirect-countdown">{countdown}</span>. | ||
</h3> | ||
|
||
<p className="description"> | ||
<FormattedMessage id="Click" defaultMessage="Click" />{' '} | ||
<Link | ||
className={'ui mini compact button my-half unauthorized-buttons'} | ||
to={login} | ||
> | ||
<FormattedMessage id="Log in" defaultMessage="Log in" /> | ||
</Link> | ||
<FormattedMessage | ||
id="to get to login screen or click" | ||
defaultMessage="to get to login screen or click" | ||
/>{' '} | ||
<Button | ||
size={'mini'} | ||
compact | ||
onClick={() => history.goBack()} | ||
className={'my-half unauthorized-buttons'} | ||
> | ||
<FormattedMessage id="Get back" defaultMessage="Get back" /> | ||
</Button> | ||
<FormattedMessage | ||
id="to get to the previous location" | ||
defaultMessage="to get to the previous location" | ||
/> | ||
. | ||
</p> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default withServerErrorCode(401)(Unauthorized); |
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