-
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
8 changed files
with
98 additions
and
5 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
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,75 @@ | ||
import { useTranslation } from 'i18n' | ||
import { declareComponentKeys } from 'i18nifty' | ||
import { useOidc } from 'oidc' | ||
import { useEffect, useState } from 'react' | ||
|
||
export function AutoLogoutCountdown() { | ||
const { isUserLoggedIn, subscribeToAutoLogoutCountdown } = useOidc() | ||
const [secondsLeft, setSecondsLeft] = useState<number | undefined>(undefined) | ||
|
||
const { t } = useTranslation({ AutoLogoutCountdown }) | ||
useEffect( | ||
() => { | ||
if (!isUserLoggedIn) { | ||
return | ||
} | ||
|
||
const { unsubscribeFromAutoLogoutCountdown } = | ||
subscribeToAutoLogoutCountdown(({ secondsLeft }) => | ||
setSecondsLeft( | ||
secondsLeft === undefined || secondsLeft > 60 | ||
? undefined | ||
: secondsLeft | ||
) | ||
) | ||
|
||
return () => { | ||
unsubscribeFromAutoLogoutCountdown() | ||
} | ||
}, | ||
// NOTE: These dependency array could very well be empty | ||
// we're just making react-hooks/exhaustive-deps happy. | ||
// Unless you're hot swapping the oidc context isUserLoggedIn | ||
// and subscribeToAutoLogoutCountdown never change for the | ||
// lifetime of the app. | ||
[isUserLoggedIn, subscribeToAutoLogoutCountdown] | ||
) | ||
|
||
if (secondsLeft === undefined) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div | ||
// Full screen overlay, blurred background | ||
style={{ | ||
position: 'fixed', | ||
top: 0, | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
backgroundColor: 'rgba(0,0,0,0.5)', | ||
backdropFilter: 'blur(10px)', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
zIndex: 1000, | ||
}} | ||
> | ||
<div style={{ textAlign: 'center' }}> | ||
<p>{t('paragraph still there')}</p> | ||
<p>{t('paragraph logged out in', { secondsLeft })}</p> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const { i18n } = declareComponentKeys< | ||
| 'paragraph still there' | ||
| { | ||
K: 'paragraph logged out in' | ||
P: { secondsLeft: number } | ||
R: string | ||
} | ||
>()({ AutoLogoutCountdown }) | ||
export type I18n = typeof i18n |
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