-
Notifications
You must be signed in to change notification settings - Fork 679
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
PWA-560: Fix gift card flash on error #2462
PWA-560: Fix gift card flash on error #2462
Conversation
packages/peregrine/lib/talons/CartPage/GiftCards/useGiftCards.js
Outdated
Show resolved
Hide resolved
|
Performance Test Results The following fails have been reported by WebpageTest. These numbers indicates a possible performance issue with the PR which requires further manual testing to validate. https://pr-2462.pwa-venia.com : LH Performance Expected 0.85 Actual 0.55, LH Best Practices Expected 1 Actual 0.92 |
- Refactor Talon to improve code readability
- Add test to verify that calling applyGiftCard with an error in the response will return shouldDisplayCardError true
- Resolve prettier and lint issues
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.
Good job :) And thank you for writing a test to cover the change.
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.
Looks good. One required suggestion, a couple related to memos that probably are over-opts. Nice work 👍
formApi.reset(); | ||
}, [formApi, applyCard, cartId]); | ||
|
||
const checkGiftCardBalance = useCallback(async () => { |
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.
Doesn't look like this needs to be a Promise anymore.
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.
Great catch, thank you!
@@ -197,6 +150,21 @@ export const useGiftCards = props => { | |||
setIsCartUpdating | |||
]); | |||
|
|||
const shouldDisplayCardBalance = useMemo( |
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 would expect this memo to be calculated every time, not sure this is an improvement; what was wrong with the current implementation of derived state?
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.
We went on an adventure fixing this bug, it seems the my refactoring to the rest of the talon resolved the original error, so you're correct. The useMemo
is no longer needed, I've updated the code :)
); | ||
|
||
// We should only display the last card error if the most recent action was apply or check and they had an error | ||
const shouldDisplayCardError = useMemo( |
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.
Same here; why the memos?
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.
- Remove usage of useMemo and use derived state
- Fix lint issue
You need to remove the |
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.
Jinx
QA approved |
Description
Maintain state for whether or not to show the gift card error so it can be correctly updated based on other state in the gift card talon.
Related Issue
https://jira.corp.magento.com/browse/PWA-560
Acceptance
Verification Stakeholders
@jimbo
@dhaecker
@sirugh
Specification
Verification Steps
See JIRA ticket for video of issue.
Screenshots / Screen Captures (if appropriate)
See JIRA ticket for video
Checklist