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

Commit 296ccef

Browse files
nielslangesenadir
andauthored
Rename billingData to billingAddress (#6369)
* Rename billingData to billingAddress * Add unit test to ensure billingData remains accessible * add integration tests for slots * Keep billingData in usePaymentMethodRegistration for backwards compatibility * Gate `billingData` in deprecation gate * Replace deprecation call Co-authored-by: Nadir Seghir <[email protected]>
1 parent 2f172d2 commit 296ccef

File tree

27 files changed

+206
-83
lines changed

27 files changed

+206
-83
lines changed

assets/js/base/context/hooks/cart/test/use-store-cart.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ describe( 'useStoreCart', () => {
3939
cartIsLoading: false,
4040
cartItemErrors: [],
4141
cartErrors: [],
42+
billingData: {
43+
first_name: '',
44+
last_name: '',
45+
company: '',
46+
address_1: '',
47+
address_2: '',
48+
city: '',
49+
state: '',
50+
postcode: '',
51+
country: '',
52+
email: '',
53+
phone: '',
54+
},
4255
billingAddress: {
4356
first_name: '',
4457
last_name: '',
@@ -108,6 +121,7 @@ describe( 'useStoreCart', () => {
108121
cartIsLoading: mockCartIsLoading,
109122
cartErrors: mockCartErrors,
110123
cartFees: [],
124+
billingData: {},
111125
billingAddress: {},
112126
shippingAddress: mockShippingAddress,
113127
shippingRates: [],

assets/js/base/context/hooks/cart/use-store-cart.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export const useStoreCart = (
159159
cartTotals: previewCart.totals,
160160
cartIsLoading: false,
161161
cartErrors: EMPTY_CART_ERRORS,
162+
billingData: defaultBillingAddress,
162163
billingAddress: defaultBillingAddress,
163164
shippingAddress: defaultShippingAddress,
164165
extensions: EMPTY_EXTENSIONS,
@@ -220,6 +221,7 @@ export const useStoreCart = (
220221
cartTotals,
221222
cartIsLoading,
222223
cartErrors,
224+
billingData: emptyHiddenAddressFields( billingAddress ),
223225
billingAddress: emptyHiddenAddressFields( billingAddress ),
224226
shippingAddress: emptyHiddenAddressFields( shippingAddress ),
225227
extensions: cartData.extensions,

assets/js/base/context/hooks/payment-methods/use-payment-method-interface.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const usePaymentMethodInterface = (): PaymentMethodInterface => {
6565
needsShipping,
6666
} = useShippingData();
6767
const {
68-
billingData,
68+
billingAddress,
6969
shippingAddress,
7070
setShippingAddress,
7171
} = useCustomerDataContext();
@@ -111,7 +111,8 @@ export const usePaymentMethodInterface = (): PaymentMethodInterface => {
111111
activePaymentMethod,
112112
billing: {
113113
appliedCoupons,
114-
billingData,
114+
billingAddress,
115+
billingData: billingAddress,
115116
cartTotal: currentCartTotal.current,
116117
cartTotalItems: currentCartTotals.current,
117118
currency: getCurrencyFromPriceResponse( cartTotals ),

assets/js/base/context/hooks/use-checkout-address.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import { useShippingData } from './shipping/use-shipping-data';
1919

2020
interface CheckoutAddress {
2121
shippingAddress: ShippingAddress;
22-
billingData: BillingAddress;
22+
billingAddress: BillingAddress;
2323
setShippingAddress: ( data: Partial< EnteredAddress > ) => void;
24-
setBillingData: ( data: Partial< EnteredAddress > ) => void;
24+
setBillingAddress: ( data: Partial< EnteredAddress > ) => void;
2525
setEmail: ( value: string ) => void;
2626
setBillingPhone: ( value: string ) => void;
2727
setShippingPhone: ( value: string ) => void;
@@ -42,26 +42,26 @@ export const useCheckoutAddress = (): CheckoutAddress => {
4242
setUseShippingAsBilling,
4343
} = useCheckoutContext();
4444
const {
45-
billingData,
46-
setBillingData,
45+
billingAddress,
46+
setBillingAddress,
4747
shippingAddress,
4848
setShippingAddress,
4949
} = useCustomerData();
5050

5151
const setEmail = useCallback(
5252
( value ) =>
53-
void setBillingData( {
53+
void setBillingAddress( {
5454
email: value,
5555
} ),
56-
[ setBillingData ]
56+
[ setBillingAddress ]
5757
);
5858

5959
const setBillingPhone = useCallback(
6060
( value ) =>
61-
void setBillingData( {
61+
void setBillingAddress( {
6262
phone: value,
6363
} ),
64-
[ setBillingData ]
64+
[ setBillingAddress ]
6565
);
6666

6767
const setShippingPhone = useCallback(
@@ -74,9 +74,9 @@ export const useCheckoutAddress = (): CheckoutAddress => {
7474

7575
return {
7676
shippingAddress,
77-
billingData,
77+
billingAddress,
7878
setShippingAddress,
79-
setBillingData,
79+
setBillingAddress,
8080
setEmail,
8181
setBillingPhone,
8282
setShippingPhone,

assets/js/base/context/hooks/use-customer-data.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import type { BillingAddress, ShippingAddress } from '@woocommerce/settings';
77

88
export interface CustomerDataType {
99
isInitialized: boolean;
10-
billingData: BillingAddress;
10+
billingAddress: BillingAddress;
1111
shippingAddress: ShippingAddress;
12-
setBillingData: ( data: Partial< BillingAddress > ) => void;
12+
setBillingAddress: ( data: Partial< BillingAddress > ) => void;
1313
setShippingAddress: ( data: Partial< ShippingAddress > ) => void;
1414
}
1515

@@ -24,13 +24,13 @@ export const useCustomerData = (): CustomerDataType => {
2424
isInitialized: store.hasFinishedResolution( 'getCartData' ),
2525
};
2626
} );
27-
const { setShippingAddress, setBillingData } = useDispatch( storeKey );
27+
const { setShippingAddress, setBillingAddress } = useDispatch( storeKey );
2828

2929
return {
3030
isInitialized,
31-
billingData: customerData.billingData,
31+
billingAddress: customerData.billingAddress,
3232
shippingAddress: customerData.shippingAddress,
33-
setBillingData,
33+
setBillingAddress,
3434
setShippingAddress,
3535
};
3636
};

assets/js/base/context/providers/cart-checkout/checkout-processor.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const CheckoutProcessor = () => {
4747
} = useCheckoutContext();
4848
const { hasValidationErrors } = useValidationContext();
4949
const { shippingErrorStatus } = useShippingDataContext();
50-
const { billingData, shippingAddress } = useCustomerDataContext();
50+
const { billingAddress, shippingAddress } = useCustomerDataContext();
5151
const { cartNeedsPayment, cartNeedsShipping, receiveCart } = useStoreCart();
5252
const {
5353
activePaymentMethod,
@@ -60,7 +60,7 @@ const CheckoutProcessor = () => {
6060
} = usePaymentMethodDataContext();
6161
const { setIsSuppressed } = useStoreNoticesContext();
6262
const { createErrorNotice, removeNotice } = useDispatch( 'core/notices' );
63-
const currentBillingData = useRef( billingData );
63+
const currentBillingAddress = useRef( billingAddress );
6464
const currentShippingAddress = useRef( shippingAddress );
6565
const currentRedirectUrl = useRef( redirectUrl );
6666
const [ isProcessingOrder, setIsProcessingOrder ] = useState( false );
@@ -105,10 +105,10 @@ const CheckoutProcessor = () => {
105105
] );
106106

107107
useEffect( () => {
108-
currentBillingData.current = billingData;
108+
currentBillingAddress.current = billingAddress;
109109
currentShippingAddress.current = shippingAddress;
110110
currentRedirectUrl.current = redirectUrl;
111-
}, [ billingData, shippingAddress, redirectUrl ] );
111+
}, [ billingAddress, shippingAddress, redirectUrl ] );
112112

113113
const checkValidation = useCallback( () => {
114114
if ( hasValidationErrors ) {
@@ -184,7 +184,7 @@ const CheckoutProcessor = () => {
184184

185185
const data = {
186186
billing_address: emptyHiddenAddressFields(
187-
currentBillingData.current
187+
currentBillingAddress.current
188188
),
189189
customer_note: orderNotes,
190190
create_account: shouldCreateAccount,

assets/js/base/context/providers/cart-checkout/customer/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import type { CustomerDataType } from '../../../hooks/use-customer-data';
55

6-
export const defaultBillingData: CustomerDataType[ 'billingData' ] = {
6+
export const defaultBillingAddress: CustomerDataType[ 'billingAddress' ] = {
77
first_name: '',
88
last_name: '',
99
company: '',

assets/js/base/context/providers/cart-checkout/customer/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import { createContext, useContext } from '@wordpress/element';
66
/**
77
* Internal dependencies
88
*/
9-
import { defaultBillingData, defaultShippingAddress } from './constants';
9+
import { defaultBillingAddress, defaultShippingAddress } from './constants';
1010
import {
1111
useCustomerData,
1212
CustomerDataType,
1313
} from '../../../hooks/use-customer-data';
1414

1515
const CustomerDataContext = createContext< CustomerDataType >( {
1616
isInitialized: false,
17-
billingData: defaultBillingData,
17+
billingAddress: defaultBillingAddress,
1818
shippingAddress: defaultShippingAddress,
19-
setBillingData: () => void 0,
19+
setBillingAddress: () => void 0,
2020
setShippingAddress: () => void 0,
2121
} );
2222

assets/js/base/context/providers/cart-checkout/payment-methods/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export const DEFAULT_PAYMENT_METHOD_DATA: PaymentMethodDataContextType = {
4545
error: ( errorMessage: string ) => void errorMessage,
4646
failed: ( errorMessage, paymentMethodData ) =>
4747
void [ errorMessage, paymentMethodData ],
48-
success: ( paymentMethodData, billingData ) =>
49-
void [ paymentMethodData, billingData ],
48+
success: ( paymentMethodData, billingAddress ) =>
49+
void [ paymentMethodData, billingAddress ],
5050
} ),
5151
currentStatus: {
5252
isPristine: true,

assets/js/base/context/providers/cart-checkout/payment-methods/payment-method-data-context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export const PaymentMethodDataProvider = ( {
283283
if ( successResponse && ! errorResponse ) {
284284
setPaymentStatus().success(
285285
successResponse?.meta?.paymentMethodData,
286-
successResponse?.meta?.billingData,
286+
successResponse?.meta?.billingAddress,
287287
successResponse?.meta?.shippingData
288288
);
289289
} else if ( errorResponse && isFailResponse( errorResponse ) ) {
@@ -302,7 +302,7 @@ export const PaymentMethodDataProvider = ( {
302302
setPaymentStatus().failed(
303303
errorResponse?.message,
304304
errorResponse?.meta?.paymentMethodData,
305-
errorResponse?.meta?.billingData
305+
errorResponse?.meta?.billingAddress
306306
);
307307
} else if ( errorResponse ) {
308308
if (

0 commit comments

Comments
 (0)