Skip to content
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

Move session expiry page to own route #649

Merged
merged 3 commits into from
Mar 12, 2024

Conversation

nikkiysendoorn1
Copy link
Contributor

@nikkiysendoorn1 nikkiysendoorn1 commented Feb 20, 2024

Closes #645

@nikkiysendoorn1 nikkiysendoorn1 linked an issue Feb 20, 2024 that may be closed by this pull request
Copy link

codecov bot commented Feb 20, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 75.20%. Comparing base (16ace7e) to head (6ee53f1).

Files Patch % Lines
src/components/Summary/CosignSummary.js 0.00% 5 Missing ⚠️
src/hooks/useSessionTimeout.js 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #649      +/-   ##
==========================================
- Coverage   75.20%   75.20%   -0.01%     
==========================================
  Files         225      226       +1     
  Lines        4517     4521       +4     
  Branches     1208     1206       -2     
==========================================
+ Hits         3397     3400       +3     
- Misses       1081     1083       +2     
+ Partials       39       38       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be tests for these changes too - we use testing-library (with user-event) that should be relatively straight forward to test the behaviour of this new component.

Checks for when this component is rendered:

  • local storage is cleared
  • ...?

Please also add some storybook stories for this new component :)

src/components/Form.js Outdated Show resolved Hide resolved
src/components/SessionExpired.js Outdated Show resolved Hide resolved
src/components/SessionExpired.js Outdated Show resolved Hide resolved
src/components/SessionExpired.js Outdated Show resolved Hide resolved
src/components/SessionExpired.js Outdated Show resolved Hide resolved
src/hooks/useSessionTimeout.js Outdated Show resolved Hide resolved
src/components/Summary/CosignSummary.js Outdated Show resolved Hide resolved
src/components/SessionExpired.js Outdated Show resolved Hide resolved
src/components/Sessions/index.js Outdated Show resolved Hide resolved
src/components/Sessions/SessionExpired.stories.js Outdated Show resolved Hide resolved
Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed - please also investigate the visual regression :)

src/components/Sessions/SessionExpired.js Outdated Show resolved Hide resolved
src/components/Sessions/SessionExpired.js Outdated Show resolved Hide resolved
src/hooks/useSessionTimeout.js Outdated Show resolved Hide resolved

// register localized error messages in the default zod error map
useZodErrorMap();

const isAppointment = form.appointmentOptions?.isAppointment ?? false;
if (isAppointment && !appointmentMatch && !appointmentCancelMatch) {
if (isAppointment && !appointmentMatch && !appointmentCancelMatch && !isSessionExpiryMatch) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikkiysendoorn1 this was the root cause of jest running forever and eventually going out-of-memory on CI - the session expiry redirect ended up in this checks, which sends it back to the appointments index, which sends it back to session expirty etc., basically an infinite redirect cycle.

ideally, we'd solve this in the loader of the router instead of doing these redirects here, but currently we don't have the available form details in that context to be able to do that, so patching it like this for now.

flagNoActiveSubmission();
window.localStorage.clear();
window.sessionStorage.clear();
if (expiryDate !== null) reset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikkiysendoorn1 this one is needed for when the session expired, you go to the dedicated page, but then you click the "here" link to restart and just end up on this same page again because the session is still expired

if there's an expiry date set still, we reset the session expiry so that users can restart the flows.

await waitFor(async () => {
await screen.findByText('Your session has expired');
});
await screen.findByText('Your session has expired', undefined, {timeout: 2000});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failed because of the internal timeout being too low, so the session-will-expire-over-1000ms-and-then-render-a-different-page cycle exceeded that. Giving 1s for the rendering etc. is sufficient here.

Comment on lines +74 to +76
supportsMultipleProducts
? withValidate(() => arrayHelpers.push({productId: '', amount: 1}))
: undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noticed a prop type warning in the dev tools, it's not related to this PR but might as well fix it along the way

Comment on lines -38 to -44
const timeoutId = window.setTimeout(
() => {
if (!mounted) return;
markExpired();
},
expiryInMs - 500 // be a bit pro-active
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was causing problems because the pro-active/eager redirect to the session expiry page then caused an issue/crash saying the session was not expired yet - it was 500ms too early.

So instead of having this mechanism, I've opted to just let the component re-render through useUpdate from react-use, after which the derived expired state is used to invoke the redirect. Works better, and not so much magic-number usage.

@sergei-maertens sergei-maertens changed the title Feature/645 session expiry Move session expiry page to own route Mar 12, 2024
nikkiysendoorn1 and others added 3 commits March 12, 2024 15:41
The component is responsible for cleanup of local/session storage and
resetting the session expiry if not done so yet.

Because the component is mounted on its own route, it will cause all
other components that trigger the redirect to be unmounted and their
state will automatically be reset too, leaving only the persistent
storages like session/local storage to be cleaned up.
The expiry hook now tracks when the session will expire and performs
a redirect when the session is effectively expired, which in turn
triggers the necessary cleanup effects.

The SessionTrackerModal is a rename of the RequireSession component,
which now only has to keep track of imminent expiry of the session
so that the end-user receives a warning and can opt to extend the
session.

Usage of these components is cleaned up, which in general simplifies
state management a bit.
Should be undefined rather than false when multiple products
is not supported.
@sergei-maertens sergei-maertens force-pushed the feature/645-session-expiry branch from 6d535d6 to 6ee53f1 Compare March 12, 2024 14:46
@sergei-maertens sergei-maertens merged commit 13c5826 into main Mar 12, 2024
14 of 15 checks passed
@sergei-maertens sergei-maertens deleted the feature/645-session-expiry branch March 12, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SDK: session expiry should be its own route
2 participants