mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Split the useUserInfoChange to separate hooks useCardChange and useShippingAddressChange
This commit is contained in:
parent
26668f7de7
commit
26fe36951c
3 changed files with 37 additions and 38 deletions
|
@ -1,39 +1,5 @@
|
||||||
import { useCallback } from '@wordpress/element';
|
import { useCallback } from '@wordpress/element';
|
||||||
|
|
||||||
export const useShippingAddressChange = (
|
|
||||||
fastlaneSdk,
|
|
||||||
setShippingAddress,
|
|
||||||
setWooShippingAddress
|
|
||||||
) => {
|
|
||||||
return useCallback( async () => {
|
|
||||||
if ( fastlaneSdk ) {
|
|
||||||
const { selectionChanged, selectedAddress } =
|
|
||||||
await fastlaneSdk.profile.showShippingAddressSelector();
|
|
||||||
if ( selectionChanged ) {
|
|
||||||
setShippingAddress( selectedAddress );
|
|
||||||
console.log(
|
|
||||||
'Selected shipping address changed:',
|
|
||||||
selectedAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const { address, name, phoneNumber } = selectedAddress;
|
|
||||||
|
|
||||||
setWooShippingAddress( {
|
|
||||||
first_name: name.firstName,
|
|
||||||
last_name: name.lastName,
|
|
||||||
address_1: address.addressLine1,
|
|
||||||
address_2: address.addressLine2 || '',
|
|
||||||
city: address.adminArea2,
|
|
||||||
state: address.adminArea1,
|
|
||||||
postcode: address.postalCode,
|
|
||||||
country: address.countryCode,
|
|
||||||
phone: phoneNumber.nationalNumber,
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [ fastlaneSdk, setShippingAddress, setWooShippingAddress ] );
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useCardChange = ( fastlaneSdk, setCard, setWooBillingAddress ) => {
|
export const useCardChange = ( fastlaneSdk, setCard, setWooBillingAddress ) => {
|
||||||
return useCallback( async () => {
|
return useCallback( async () => {
|
||||||
if ( fastlaneSdk ) {
|
if ( fastlaneSdk ) {
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { useCallback } from '@wordpress/element';
|
||||||
|
|
||||||
|
export const useShippingAddressChange = (
|
||||||
|
fastlaneSdk,
|
||||||
|
setShippingAddress,
|
||||||
|
setWooShippingAddress
|
||||||
|
) => {
|
||||||
|
return useCallback( async () => {
|
||||||
|
if ( fastlaneSdk ) {
|
||||||
|
const { selectionChanged, selectedAddress } =
|
||||||
|
await fastlaneSdk.profile.showShippingAddressSelector();
|
||||||
|
if ( selectionChanged ) {
|
||||||
|
setShippingAddress( selectedAddress );
|
||||||
|
console.log(
|
||||||
|
'Selected shipping address changed:',
|
||||||
|
selectedAddress
|
||||||
|
);
|
||||||
|
|
||||||
|
const { address, name, phoneNumber } = selectedAddress;
|
||||||
|
|
||||||
|
setWooShippingAddress( {
|
||||||
|
first_name: name.firstName,
|
||||||
|
last_name: name.lastName,
|
||||||
|
address_1: address.addressLine1,
|
||||||
|
address_2: address.addressLine2 || '',
|
||||||
|
city: address.adminArea2,
|
||||||
|
state: address.adminArea1,
|
||||||
|
postcode: address.postalCode,
|
||||||
|
country: address.countryCode,
|
||||||
|
phone: phoneNumber.nationalNumber,
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [ fastlaneSdk, setShippingAddress, setWooShippingAddress ] );
|
||||||
|
};
|
|
@ -8,10 +8,8 @@ import { loadPaypalScript } from '../../../ppcp-button/resources/js/modules/Help
|
||||||
// Hooks
|
// Hooks
|
||||||
import useAxoBlockManager from './hooks/useAxoBlockManager';
|
import useAxoBlockManager from './hooks/useAxoBlockManager';
|
||||||
import { useCustomerData } from './hooks/useCustomerData';
|
import { useCustomerData } from './hooks/useCustomerData';
|
||||||
import {
|
import { useShippingAddressChange } from './hooks/useShippingAddressChange';
|
||||||
useShippingAddressChange,
|
import { useCardChange } from './hooks/useCardChange';
|
||||||
useCardChange,
|
|
||||||
} from './hooks/useUserInfoChange';
|
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import { Payment } from './components/Payment';
|
import { Payment } from './components/Payment';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue