Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

New contexts for StoreNoticesContainer and notice grouping #7711

Merged
merged 48 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7ac3419
Refactor Store Notices
mikejolley Nov 16, 2022
8102538
Move new notice code to checkout package
mikejolley Nov 17, 2022
af34c3a
Combine store and snackbars
mikejolley Nov 18, 2022
ec30631
Update noticeContexts imports
mikejolley Nov 18, 2022
f7e09fa
Remove context provider
mikejolley Nov 18, 2022
ba395cd
Update data store
mikejolley Nov 18, 2022
50e92e8
Fix 502
mikejolley Nov 18, 2022
3f0cf1a
Add new error contexts
mikejolley Nov 18, 2022
ff8032e
Force types
mikejolley Nov 18, 2022
9b70e77
Unnecessary reorder of imports
mikejolley Nov 18, 2022
6a47897
Fix global handling
mikejolley Nov 18, 2022
9b0641d
Document forceType
mikejolley Nov 21, 2022
fc95371
Optional props are undefined
mikejolley Nov 21, 2022
36ceabb
Remove function name
mikejolley Nov 21, 2022
aa00253
Missing condition
mikejolley Nov 21, 2022
56e09ce
Remove context prop
mikejolley Nov 21, 2022
0ca3044
Define ACTION_TYPES
mikejolley Nov 21, 2022
6800f95
Remove controls
mikejolley Nov 21, 2022
c5969cf
Update assets/js/base/context/event-emit/utils.ts
mikejolley Nov 21, 2022
0c44b9f
CONTACT_INFORMATION
mikejolley Nov 21, 2022
7dfa93f
Remove ref from registerContainer
mikejolley Nov 21, 2022
cce02dd
Abstract container locating methods
mikejolley Nov 21, 2022
9f068d6
pass context correctly when displaying notices
mikejolley Nov 21, 2022
ae56343
Remove debugging buttons
mikejolley Nov 21, 2022
52246c2
Update filter usage - remove useMemo so filter can work inline
mikejolley Nov 21, 2022
6b5a7de
Refactor existing error notices from the API (#7728)
mikejolley Nov 23, 2022
8bd1c40
Update store name to wc/store/store-notices
mikejolley Dec 5, 2022
dff0e7b
Fix assertResponseIsValid
mikejolley Dec 5, 2022
ff7df9b
Funnel woocommerce_rest_invalid_email_address to the correct place
mikejolley Dec 5, 2022
6686633
woocommerce_rest_missing_email_address
mikejolley Dec 5, 2022
e8465a4
Move comments around
mikejolley Dec 9, 2022
3a6b72f
Move data back into const
mikejolley Dec 9, 2022
7ee9d16
Spacing
mikejolley Dec 9, 2022
bbb456b
Remove spacing
mikejolley Dec 9, 2022
7a85d7c
Remove forced snack bar and styling
mikejolley Dec 9, 2022
b5c4504
Move notices within wrapper
mikejolley Dec 9, 2022
2df8969
Remove type
mikejolley Dec 9, 2022
e499f26
hasStoreNoticesContainer rename
mikejolley Dec 9, 2022
f442990
Group by status/context
mikejolley Dec 9, 2022
55df28e
Remove global context
mikejolley Dec 14, 2022
fcd6832
Remove white space
mikejolley Dec 14, 2022
48a0af3
remove changes to simplify diff
mikejolley Dec 14, 2022
7037d2a
white space
mikejolley Dec 14, 2022
f449d20
Move comment to typescript
mikejolley Dec 16, 2022
5558a16
List style
mikejolley Dec 16, 2022
df16431
showApplyCouponNotice docs
mikejolley Dec 16, 2022
c47265f
See if scrollIntoView exists
mikejolley Dec 16, 2022
341135f
fix notice tests
mikejolley Dec 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions assets/js/base/context/event-emit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ export enum responseTypes {
}

export enum noticeContexts {
PAYMENTS = 'wc/payment-area',
EXPRESS_PAYMENTS = 'wc/express-payment-area',
CART = 'wc/cart',
CHECKOUT = 'wc/checkout',
PAYMENTS = 'wc/checkout/payments',
EXPRESS_PAYMENTS = 'wc/checkout/express-payments',
CONTACT_INFORMATION = 'wc/checkout/contact-information',
SHIPPING_ADDRESS = 'wc/checkout/shipping-address',
BILLING_ADDRESS = 'wc/checkout/billing-address',
SHIPPING_METHODS = 'wc/checkout/shipping-methods',
CHECKOUT_ACTIONS = 'wc/checkout/checkout-actions',
}

export interface ResponseType extends Record< string, unknown > {
Expand Down
31 changes: 20 additions & 11 deletions assets/js/base/context/hooks/cart/use-store-cart-coupons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
*/
import { __, sprintf } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import {
CART_STORE_KEY as storeKey,
VALIDATION_STORE_KEY,
} from '@woocommerce/block-data';
import { CART_STORE_KEY, VALIDATION_STORE_KEY } from '@woocommerce/block-data';
import { decodeEntities } from '@wordpress/html-entities';
import type { StoreCartCoupon } from '@woocommerce/types';
import { __experimentalApplyCheckoutFilter } from '@woocommerce/blocks-checkout';

/**
* Internal dependencies
Expand All @@ -19,9 +17,6 @@ import { useStoreCart } from './use-store-cart';
* This is a custom hook for loading the Store API /cart/coupons endpoint and an
* action for adding a coupon _to_ the cart.
* See also: https://github.com/woocommerce/woocommerce-gutenberg-products-block/tree/trunk/src/RestApi/StoreApi
*
* @return {StoreCartCoupon} An object exposing data and actions from/for the
mikejolley marked this conversation as resolved.
Show resolved Hide resolved
* store api /cart/coupons endpoint.
*/
export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => {
const { cartCoupons, cartIsLoading } = useStoreCart();
Expand All @@ -35,7 +30,7 @@ export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => {
}: Pick< StoreCartCoupon, 'isApplyingCoupon' | 'isRemovingCoupon' > =
useSelect(
( select ) => {
const store = select( storeKey );
const store = select( CART_STORE_KEY );

return {
isApplyingCoupon: store.isApplyingCoupon(),
Expand All @@ -46,12 +41,19 @@ export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => {
);

const { applyCoupon, removeCoupon, receiveApplyingCoupon } =
useDispatch( storeKey );
useDispatch( CART_STORE_KEY );

const applyCouponWithNotices = ( couponCode: string ) => {
applyCoupon( couponCode )
.then( ( result ) => {
if ( result === true ) {
if (
result === true &&
__experimentalApplyCheckoutFilter( {
filterName: 'showApplyCouponNotice',
defaultValue: true,
arg: { couponCode, context },
} )
) {
createNotice(
'info',
sprintf(
Expand Down Expand Up @@ -85,7 +87,14 @@ export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => {
const removeCouponWithNotices = ( couponCode: string ) => {
removeCoupon( couponCode )
.then( ( result ) => {
if ( result === true ) {
if (
result === true &&
__experimentalApplyCheckoutFilter( {
filterName: 'showRemoveCouponNotice',
defaultValue: true,
arg: { couponCode, context },
} )
) {
createNotice(
'info',
sprintf(
Expand Down
1 change: 0 additions & 1 deletion assets/js/base/context/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from './use-store-products';
export * from './use-store-add-to-cart';
export * from './use-customer-data';
export * from './use-checkout-address';
export * from './use-checkout-notices';
export * from './use-checkout-submit';
export * from './use-checkout-extension-data';
export * from './use-validation';
55 changes: 0 additions & 55 deletions assets/js/base/context/hooks/use-checkout-notices.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import {
* Internal dependencies
*/
import { useEventEmitters, reducer as emitReducer } from './event-emit';
import type { emitterCallback } from '../../../event-emit';
import { emitterCallback, noticeContexts } from '../../../event-emit';
import { useStoreEvents } from '../../../hooks/use-store-events';
import { useCheckoutNotices } from '../../../hooks/use-checkout-notices';
import {
getExpressPaymentMethods,
getPaymentMethods,
Expand Down Expand Up @@ -134,11 +133,29 @@ export const CheckoutEventsProvider = ( {
}

const { setValidationErrors } = useDispatch( VALIDATION_STORE_KEY );
const { createErrorNotice } = useDispatch( 'core/notices' );

const { dispatchCheckoutEvent } = useStoreEvents();
const { checkoutNotices, paymentNotices, expressPaymentNotices } =
useCheckoutNotices();
useSelect( ( select ) => {
const { getNotices } = select( 'core/notices' );
const checkoutContexts = Object.values( noticeContexts ).filter(
( context ) =>
context !== noticeContexts.PAYMENTS &&
context !== noticeContexts.EXPRESS_PAYMENTS
);
const allCheckoutNotices = checkoutContexts.reduce(
( acc, context ) => {
return [ ...acc, ...getNotices( context ) ];
},
[]
);
return {
checkoutNotices: allCheckoutNotices,
paymentNotices: getNotices( noticeContexts.PAYMENTS ),
expressPaymentNotices: getNotices(
noticeContexts.EXPRESS_PAYMENTS
),
};
}, [] );

const [ observers, observerDispatch ] = useReducer( emitReducer, {} );
const currentObservers = useRef( observers );
Expand Down Expand Up @@ -186,7 +203,6 @@ export const CheckoutEventsProvider = ( {
}, [
isCheckoutBeforeProcessing,
setValidationErrors,
createErrorNotice,
__internalEmitValidateEvent,
] );

Expand Down Expand Up @@ -224,7 +240,6 @@ export const CheckoutEventsProvider = ( {
isCheckoutBeforeProcessing,
previousStatus,
previousHasError,
createErrorNotice,
checkoutNotices,
expressPaymentNotices,
paymentNotices,
Expand Down
Loading