-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/session timeout modal (#240)
* #136: added SessionTimeout component to app * #136: added two popped-up modals before session time-out * #136: added count down timer to the popup modals * #136: added auto refresh token feature * #136: set time intervals in portal data json file * #136: updated auto-refresh token to only for project-specific tokens * #136: updated CM calls based on CM API update * #136: replaced session timeout period with actual time * #136: updated user status check via /whoami response * #136: added length validation for boot script & sliver name * #136: updated user status local storage" * #136: added FABRIC CILogon stylesheet * #136: auto change FABRIC Logo between different tiers
- Loading branch information
Showing
14 changed files
with
351 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React, { Component } from "react"; | ||
import Modal from 'react-bootstrap/Modal' | ||
import Button from 'react-bootstrap/Button' | ||
import clearLocalStorage from "../../utils/clearLocalStorage"; | ||
|
||
class SessionTimeoutModal extends Component { | ||
state = { | ||
show: true, | ||
minutes: 0, | ||
seconds: 0, | ||
} | ||
|
||
handleLogout = () => { | ||
this.setState({ show: false }); | ||
clearLocalStorage(); | ||
window.location.href = "/logout"; | ||
} | ||
|
||
handleClose = () => { | ||
this.setState({ show: false }); | ||
} | ||
|
||
componentDidMount() { | ||
let minutes = Math.floor(this.props.timeLeft / 60000); | ||
let seconds = ((this.props.timeLeft % 60000) / 1000).toFixed(0); | ||
this.setState({ minutes, seconds }) | ||
|
||
let countdownTimer = setInterval(() => { | ||
if(seconds > 0){ | ||
seconds--; | ||
} else if (minutes > 0){ | ||
minutes--; | ||
seconds = 59; | ||
} else { | ||
minutes = 0; | ||
seconds = 0; | ||
} | ||
this.setState({ minutes, seconds }) | ||
}, 1000); | ||
|
||
localStorage.setItem("countdownTimerIntervalId", countdownTimer); | ||
} | ||
|
||
parseTimeStr = (minutes, seconds) => { | ||
if (minutes > 0 && seconds > 0) { | ||
return `${minutes} minute${minutes > 1 ? "s" : ""} ${seconds} second${seconds > 1 ? "s" : ""}`; | ||
} | ||
|
||
if (minutes > 0 && seconds === 0) { | ||
return `${minutes} minute${minutes > 1 ? "s" : ""}`; | ||
} | ||
|
||
if (minutes === 0 && seconds > 1) { | ||
return `${seconds} second${seconds > 1 ? "s" : ""}`; | ||
} | ||
|
||
if (minutes === 0 && seconds === 1) { | ||
clearInterval(localStorage.getItem("countdownTimerIntervalId")); | ||
clearInterval(localStorage.getItem(`sessionTimeoutIntervalId${this.props.modalId}`)); | ||
this.handleLogout(); | ||
} | ||
} | ||
|
||
render() { | ||
let { minutes, seconds, show } = this.state; | ||
return ( | ||
<div> | ||
{ | ||
this.props.timeLeft > 0 && <Modal | ||
size="lg" | ||
show={show} | ||
onHide={this.handleClose} | ||
backdrop="static" | ||
keyboard={false} | ||
> | ||
<Modal.Header closeButton> | ||
<Modal.Title>Session Timeout</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<p id="countdownTimerModal"> | ||
The current session is about to expire in <span className="text-danger font-weight-bold"> | ||
{this.parseTimeStr(minutes, seconds)}</span>. | ||
Please save your work to prevent loss of data. | ||
</p> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button variant="secondary" onClick={this.handleClose}>Close</Button> | ||
<Button variant="primary" onClick={this.handleLogout}> | ||
Logout | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
|
||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default SessionTimeoutModal; |
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
Oops, something went wrong.