Skip to content

Commit

Permalink
Don't display a negative time
Browse files Browse the repository at this point in the history
If the remaining session time dips below 0 imediately before auto-
logout, ceil the display value to 0 to avoid showing negative
seconds left.
  • Loading branch information
jakemcdermott committed Nov 2, 2020
1 parent 3a7608c commit b82174d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions awx/ui_next/src/components/AppContainer/AppContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function AppContainer({ i18n, navRouteConfig = [], children }) {
const sessionIntervalId = useRef();
const [sessionTimeout, setSessionTimeout] = useStorage(SESSION_TIMEOUT_KEY);
const [timeoutWarning, setTimeoutWarning] = useState(false);
const [timeRemaining, setTimeRemaining] = useState(Infinity);
const [timeRemaining, setTimeRemaining] = useState(null);

const handleAboutModalOpen = () => setIsAboutModalOpen(true);
const handleAboutModalClose = () => setIsAboutModalOpen(false);
Expand Down Expand Up @@ -136,7 +136,7 @@ function AppContainer({ i18n, navRouteConfig = [], children }) {
}, [history, sessionTimeout]);

useEffect(() => {
if (timeRemaining <= 1) {
if (timeRemaining !== null && timeRemaining <= 1) {
handleLogout();
}
}, [handleLogout, timeRemaining]);
Expand Down Expand Up @@ -224,7 +224,7 @@ function AppContainer({ i18n, navRouteConfig = [], children }) {
</AlertModal>
<AlertModal
title={i18n._(t`Your session is about to expire`)}
isOpen={timeoutWarning && sessionTimeout > 0 && timeRemaining > 0}
isOpen={timeoutWarning && sessionTimeout > 0 && timeRemaining !== null}
onClose={handleLogout}
showClose={false}
variant="warning"
Expand All @@ -243,7 +243,7 @@ function AppContainer({ i18n, navRouteConfig = [], children }) {
>
{i18n._(
t`You will be logged out in ${Number(
Math.floor(timeRemaining / 1000)
Math.max(Math.floor(timeRemaining / 1000), 0)
)} seconds due to inactivity.`
)}
</AlertModal>
Expand Down

0 comments on commit b82174d

Please sign in to comment.