-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OKTA 561098 : Reminder element rerender timing fix #3077
Changes from all commits
c65b8a9
d86a0b4
a1524b9
028d06d
d35ae0a
b095811
0f0a690
58f8fae
33ff33a
61187cc
ecf4ea2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,23 +42,47 @@ const ReminderPrompt: UISchemaElementComponent<{ | |
const [show, setShow] = useState<boolean>(false); | ||
const timerRef = useRef<number | undefined>(); | ||
|
||
const RESEND_TIMESTAMP_SESSION_STORAGE_KEY = 'osw-oie-resend-timestamp'; | ||
const removeResendTimestamp = () => { | ||
sessionStorage.removeItem(RESEND_TIMESTAMP_SESSION_STORAGE_KEY); | ||
}; | ||
const setResendTimestamp = (token: string) => { | ||
sessionStorage.setItem(RESEND_TIMESTAMP_SESSION_STORAGE_KEY, token); | ||
}; | ||
|
||
// eslint-disable-next-line arrow-body-style | ||
const getResendTimestamp = (): string | null => { | ||
return sessionStorage.getItem(RESEND_TIMESTAMP_SESSION_STORAGE_KEY); | ||
}; | ||
|
||
const startTimer = () => { | ||
setShow(false); | ||
const timeStamp = getResendTimestamp(); | ||
if (!timeStamp) { | ||
setResendTimestamp(Date.now().toString()); | ||
} | ||
if (timerRef) { | ||
window.clearTimeout(timerRef.current); | ||
window.clearInterval(timerRef.current); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when you omit the Based on light research, |
||
} | ||
|
||
setShow(false); | ||
|
||
const timeout = typeof customTimeout === 'number' ? customTimeout : DEFAULT_TIMEOUT_MS; | ||
|
||
timerRef.current = window.setTimeout(() => setShow(true), timeout); | ||
timerRef.current = window.setInterval(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, can you try omitting the |
||
const start = parseInt(getResendTimestamp() as string); | ||
const now = Date.now(); | ||
const timeout = typeof customTimeout === 'number' ? customTimeout : DEFAULT_TIMEOUT_MS; | ||
if (now - start >= timeout) { | ||
setShow(true); | ||
window.clearInterval(timerRef.current); | ||
removeResendTimestamp(); | ||
} | ||
}, 250); | ||
}; | ||
|
||
useEffect(() => { | ||
startTimer(); | ||
|
||
return () => { | ||
window.clearTimeout(timerRef.current); | ||
window.clearInterval(timerRef.current); | ||
removeResendTimestamp(); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for some reason setSystemTime does not exist on the jest type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to update
@types/jest
version to match the jest version. This should solve all of the type errors that we're ignoring@ts-expect-error