Skip to content

feat: migrate from Notifications to Banners (M2-6946) #477

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

Merged
merged 11 commits into from
Jun 10, 2024

Conversation

farmerpaul
Copy link
Contributor

@farmerpaul farmerpaul commented Jun 10, 2024

📝 Description

🔗 Jira Ticket M2-6946

This PR replaces the NotificationCenter, useNotification hook, and related infrastructure with Banners, useBanners, adapted from the Admin App with only slight changes to align with the Web App's code structure.

Includes:

  • Redux Toolkit slice to manage global state of banners model
  • Banner base component (replaces Notification component)
    • Same as in Admin App, component is based on MUI Alert component, and styled in call to createTheme
    • Added useWindowFocus hook (copied verbatim from Admin App) required for enhanced a11y/UX
  • Banners container component (replaces NotificationCenter component)
  • Four custom banners: SuccessBanner, WarningBanner, ErrorBanner, and InfoBanner
  • useBanners hook that provides convenience functions for adding/removing banners (replaces useNotification hook)
  • useSessionBanners hook, adapted from Admin App, which removes any displayed banners upon logout
  • Tests for Banner and Banners components
    • Required adding @testing-library/user-event package and upgrading @vitejs/plugin-react to the latest version to fix a bug with executing tests that involved rendering React components

Tip

It may be easier to review this PR commit-by-commit due to the number of changes.

📸 Screenshots

Before After
Screenshot 2024-06-10 at 3 10 12 PM Screenshot 2024-06-10 at 3 13 42 PM
Screenshot 2024-06-10 at 3 04 15 PM Screenshot 2024-06-10 at 3 00 21 PM

🪤 Peer Testing

Requires yarn install

  1. Log in with a valid email but invalid password.
    Expected outcome: An error banner should render with updated styling, including a close button.
  2. Wait 5 seconds.
    Expected outcome: Banner should disappear.
  3. Repeat step 1, then press the close button before the banner disappears.
    Expected outcome: Banner should disappear.
  4. Repeat step 1, then hover mouse cursor over the banner and wait more than 5 seconds.
    Expected outcome: Banner should remain visible.
  5. Repeat step 1, then make the window/tab lose focus for more than 5 seconds. Refocus the window.
    Expected outcome: Banner should still be visible.
  6. Wait 5 seconds with the cursor not hovering over the banner.
    Expected outcome: Banner should disappear.
  7. Initiate Take Now on an activity, but log into the web app using an admin account that is different from the account selected for inputting the answers.
    Expected outcome: Error banner should should render with updated styling.
  8. Before banner disappears, log out of the Web App.
    Expected outcome: Error banner should disappear.

Based on same infrastructure used by Admin App, but refactored to follow
web app conventions. Included `useBanners` hook for handy convenience
functions.
Same as Admin App, uses MUI's Alert component. Override default theme
styling of Alert to align with Figma. Create `useWindowFocus` hook,
copied verbatim from Admin App, to uphold a11y UX.
Create `Banners` wrapper component to replace `NotificationCenter`.
Same as in Admin App, use default duration of 3.5s for success banners.
Replace instances of `NotificationCenter` with `Banners`, and
`useNotification` with `useBanners`.
Copied almost verbatim from Admin App. Required incorporating
`@testing-library/user-event` package into project, and upgrading
`@vitejs/plugin-react` to latest version, as the current version was
buggy and causing tests involving rendering React
components to fail.

Add `renderWithProviders` test utility (based on same existing utility
in Admin App) to be able to prepopulate Redux state in tests, required
by `Banners` component.

Also add `expectBanner` utility for testing presence/absense of banners,
copied from Admin App.
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-477.d15zn9do8xbzga.amplifyapp.com

Including Redux `banners` state selector in `useBanners` hook causes
infinite state update loop in React; simplified the hook so that only
the one component needing access to the `banners` array requests it.
Admin App needed the same solution; I had oversimplified the code when
migrating it from the Admin App and learned this import structure is
indeed required.
Same as Admin App, remove any displayed banners upon logout. Required
migrating `renderHookWithProviders` testing utility.
@farmerpaul farmerpaul marked this pull request as ready for review June 10, 2024 18:19
@farmerpaul farmerpaul requested a review from ChaconC June 10, 2024 18:24
Copy link
Contributor

@ChaconC ChaconC left a comment

Choose a reason for hiding this comment

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

LGTM and all tests worked, great work!

I did run into a case where the banner stayed on screen indefinitely, but that was caused by a popup from my password manager (never triggering window focus to change).

A minor comment about removing banners on success but feels ok to pre-approve.

Ensures login & signup forms do not display persistent error banners
after forms have been successfully submitted. Also add convenience
functions to `useBanners` to make removing such banners easier.
Copy link
Contributor

@sultanofcardio sultanofcardio left a comment

Choose a reason for hiding this comment

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

Works as expected

@farmerpaul farmerpaul merged commit b4c749d into dev Jun 10, 2024
@farmerpaul farmerpaul deleted the feature/M2-6946-set-up-banners-infra branch June 10, 2024 22:16
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.

3 participants