-
Notifications
You must be signed in to change notification settings - Fork 219
Capture notices from hidden block into siblings block #8390
Conversation
capturedContexts={ | ||
useBillingAsShipping | ||
? [ noticeContexts.SHIPPING_ADDRESS ] | ||
: [] | ||
} |
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 don't feel strongly about approach, another option would be to call registerContainer
from this block but I didn't test that yet.
const contexts = useMemo( | ||
() => [ context, ...capturedContexts ], | ||
[ capturedContexts, context ] | ||
); |
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.
This caused an infinite loop so that's why I added it.
The release ZIP for this PR is accessible via:
Script Dependencies ReportThe
This comment was automatically generated by the TypeScript Errors Report
assets/js/base/components/cart-checkout/shipping-calculator/index.tsx
packages/checkout/components/store-notices-container/test/index.tsx |
Size Change: +162 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
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.
Nice work, works as advertised but I had a couple of q - see inline comments
@@ -103,6 +103,11 @@ const Block = ( { | |||
<AddressFormWrapperComponent> | |||
<StoreNoticesContainer | |||
context={ noticeContexts.SHIPPING_ADDRESS } | |||
capturedContexts={ | |||
useShippingAsBilling | |||
? [ noticeContexts.BILLING_ADDRESS ] |
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.
Do we need to take into account the WC settings where a merchant can default to the shipping address or force shipping address to the customer billing address? This seems to work ok when I tested, but I'm not sure why. The logic you have here is that the error should be displayed in the billing address context, if useShippingAsBilling
is ticked. If shipping address is default, the context should be SHIPPING_ADDRESS. The notice is displayed correctly though, so I'm wondering why this works?
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.
useShippingAsBilling
takes that into account.
The logic here is that if we have the billing form hidden and its value being synced to shipping, then we also want to capture those notices and present them in the shipping step.
The logic you have here is that the error should be displayed in the billing address context, if useShippingAsBilling is ticked.
The logic I have here is that if useShippingAsBilling
is true, we want to capture the billing address errors and show them in that block (shipping address)
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.
Gotcha that makes more sense
@@ -17,11 +17,11 @@ import { getClassNameFromStatus } from './utils'; | |||
import type { StoreNotice } from './types'; | |||
|
|||
const StoreNotices = ( { | |||
context, | |||
contexts, |
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.
You'll need to update the docs here as well to reflect plural
Just noticed some TS errors
|
@@ -91,7 +91,14 @@ const Block = ( { | |||
|
|||
return ( | |||
<AddressFormWrapperComponent> | |||
<StoreNoticesContainer context={ noticeContexts.BILLING_ADDRESS } /> | |||
<StoreNoticesContainer | |||
context={ noticeContexts.BILLING_ADDRESS } |
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 prefer if we could somehow define an array of context here rather than the separate prop.
) => | ||
noticesArray.findIndex( | ||
( _notice: Notice ) => _notice.content === notice.content | ||
) === noticeIndex; |
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.
👍🏻 This makes sense.
021c521
to
a99279d
Compare
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 now, thanks for working on this 👍
* Capture notices from hidden block into siblings block * switch to using a single context * make change bwc * add tests * support context as array in StoreNotice * move filter logic to Notice component
Recently in #8182 we introduced more controlled notice handling, this included showing notices in the correct places when needed and surfacing notices up to the main block when it makes sense.
However, this introduced a problem in sibling blocks (Shipping address billing address, payment and express payment) in which an error might be returned for both, but is rendered on one of them only while the other bubbles).
This PR adds a
capturedContexts
param to the store notice provider to capture other notices.This PR also adds filtering so duplicate errors are shown once, based on the error content only.
Fixes #8387
Testing
Changelog