-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, {useState } from 'react' | ||
import { useIdleTimer } from 'react-idle-timer' | ||
import { | ||
MDBBtn, | ||
MDBModal, | ||
MDBModalDialog, | ||
MDBModalContent, | ||
MDBModalHeader, | ||
MDBModalTitle, | ||
MDBModalBody, | ||
MDBModalFooter, | ||
} from 'mdb-react-ui-kit'; | ||
|
||
export default function App() { | ||
const [timeoutModal, setTimeoutModal] = useState(false); | ||
const [state, setState] = useState('Active') | ||
|
||
const handleIdle = () => { | ||
setTimeoutModal(false) | ||
window.location.reload() | ||
} | ||
|
||
const onIdle = () => { | ||
setState('Idle') | ||
setTimeoutModal(true) | ||
} | ||
|
||
const { | ||
} = useIdleTimer({ | ||
onIdle, | ||
timeout: 3600 * 1000, | ||
crossTab: true, | ||
leaderElection: true, | ||
syncTimers: 200 | ||
}) | ||
|
||
return ( | ||
<> | ||
{state === 'Idle' && ( | ||
<MDBModal | ||
open={timeoutModal} | ||
tabIndex="-1" | ||
> | ||
<MDBModalDialog> | ||
<MDBModalContent className="message-modal-content"> | ||
<MDBModalHeader className="bg-primary text-white"> | ||
<MDBModalTitle>Session Timeout</MDBModalTitle> | ||
<MDBBtn | ||
className="btn-close btn-close-white" | ||
color="none" | ||
onClick={handleIdle} | ||
></MDBBtn> | ||
</MDBModalHeader> | ||
<MDBModalBody className='text-center'> | ||
<h5> Your login session has expired due to inactivity⌛</h5> | ||
<h5> Please login again.</h5> | ||
<h5> Don't worry, your code is saved!</h5> | ||
</MDBModalBody> | ||
|
||
<MDBModalFooter> | ||
<MDBBtn color="secondary" onClick={handleIdle}> | ||
OK | ||
</MDBBtn> | ||
</MDBModalFooter> | ||
</MDBModalContent> | ||
</MDBModalDialog> | ||
</MDBModal> | ||
)} | ||
</> | ||
) | ||
} |
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