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

adds the PromoBar component and a new custom hook useNotificationMessage to the PatronPage #606

Conversation

kasperbirch1
Copy link
Contributor

Link to issue

https://reload.atlassian.net/browse/DDFLSBP-84

Description

This Pull Request adds the PromoBar component and a new custom hook useNotificationMessage to the PatronPage.

The PromoBar provides visual notifications to users, while the useNotificationMessage hook is designed to manage these notifications by handling auto-scrolling and setting removal timeouts.

Screenshot of the result

Skaermoptagelse.2023-10-13.kl.14.54.27.mov

Copy link
Contributor

@spaceo spaceo left a comment

Choose a reason for hiding this comment

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

Great work!
I have a few comments

src/apps/patron-page/PatronPage.dev.tsx Outdated Show resolved Hide resolved
src/core/utils/useNotificationMessage.ts Outdated Show resolved Hide resolved
src/core/utils/useNotificationMessage.ts Outdated Show resolved Hide resolved
@kasperbirch1 kasperbirch1 requested a review from spaceo October 19, 2023 09:29
Copy link
Contributor

@spaceo spaceo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@spaceo spaceo self-requested a review October 19, 2023 09:55
Copy link
Contributor

@spaceo spaceo left a comment

Choose a reason for hiding this comment

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

Greatness. And the annoying reviewer has some more remarks

src/apps/patron-page/PatronPage.tsx Show resolved Hide resolved
src/core/utils/useNotificationMessage.tsx Outdated Show resolved Hide resolved
@kasperbirch1 kasperbirch1 requested review from spaceo and removed request for spaceo October 19, 2023 14:38
@kasperbirch1 kasperbirch1 force-pushed the DDFLSBP-84-brugerprofil-systemfeedback-mangler-pa-gem branch from 7392329 to cfd0330 Compare October 27, 2023 12:14
kasperbirch1 and others added 12 commits October 27, 2023 15:01
The `useNotificationMessage` hook manages to handle auto-scrolling to the top and setting a removal timeout for notifications. It integrates seamlessly with `promobar` and offers utility for additional use-cases.
Modified the hook to return either the `Promobar` component or 'null' as the initial item in the array. Also provided default settings for `timeout` and `scrollToTop` which can be overridden during usage.
In this commit, `NotificationComponent` has been extracted from the `useNotificationMessage` hook.

By wrapping the retrun of `NotificationComponent` in a function, we enhance the reactivity of the component, ensuring that its body (the JSX) is re-evaluated with each render. This method is beneficial as it provides a mechanism to always capture the most recent state or props, eliminating concerns about stale closures.
Centralize all `useNotificationMessage` related logic.
When the handler has been called the user should be sent to the top of
the page
@kasperbirch1 kasperbirch1 force-pushed the DDFLSBP-84-brugerprofil-systemfeedback-mangler-pa-gem branch from 0df507e to c69fb9d Compare October 27, 2023 13:01
@kasperbirch1 kasperbirch1 requested a review from spaceo October 27, 2023 13:02
- Replaced custom prop-based component identification with data-testid attributes for better test clarity and maintainability.
- Introduced afterEach cleanup in tests to ensure isolated test environments.
- Updated test descriptions for consistency and better readability.
- Simplified ComponentWithNotificationMessage by removing unnecessary props.
Changes:
1. Import 'screen' from '@testing-library/react' for improved element querying.
2. Update the expectation for the non-existence of the message before the button click to use 'screen.queryByText' instead of asserting on the wrapper's content.
3. Modify the expectation after the button is clicked to check the existence of the message using 'screen.queryByText', ensuring a more robust and readable test.
- Updated `ComponentWithNotificationMessage` to accept `timeout` and `scrollToTop` options.
- Added two new test cases:
  1. To verify message display indefinitely when timeout is removed.
  2. To ensure there's no scroll to top action when `scrollToTop` is set to false.
Copy link
Contributor

@spaceo spaceo left a comment

Choose a reason for hiding this comment

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

Great additions!
Some comments need to be clarified though before approval

@@ -240,11 +240,20 @@ export default {
defaultValue: "You used @this ebooks out of you quota of @that ebooks",
control: { type: "text" }
},
phoneInputMessageText: {
patronPagePhoneInputMessageText: {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you have refactored this data prop, what about dpl-cms then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/tests/unit/notification-message.test.tsx Show resolved Hide resolved
src/tests/unit/notification-message.test.tsx Show resolved Hide resolved
Copy link
Contributor

@spaceo spaceo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

src/tests/unit/notification-message.test.tsx Show resolved Hide resolved
@kasperbirch1 kasperbirch1 merged commit 7f8c3fd into danskernesdigitalebibliotek:develop Oct 30, 2023
9 of 10 checks passed
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