This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
43,159 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
defaultAddressFields, | ||
AddressFields, | ||
EnteredAddress, | ||
ShippingAddress, | ||
BillingAddress, | ||
} from '@woocommerce/settings'; | ||
import { useCallback } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
useShippingDataContext, | ||
useCheckoutContext, | ||
} from '../providers/cart-checkout'; | ||
import { useCustomerData } from './use-customer-data'; | ||
|
||
interface CheckoutAddress { | ||
shippingAddress: ShippingAddress; | ||
billingData: BillingAddress; | ||
setShippingAddress: ( data: Partial< EnteredAddress > ) => void; | ||
setBillingData: ( data: Partial< EnteredAddress > ) => void; | ||
setEmail: ( value: string ) => void; | ||
setBillingPhone: ( value: string ) => void; | ||
setShippingPhone: ( value: string ) => void; | ||
useShippingAsBilling: boolean; | ||
setUseShippingAsBilling: ( useShippingAsBilling: boolean ) => void; | ||
defaultAddressFields: AddressFields; | ||
showShippingFields: boolean; | ||
showBillingFields: boolean; | ||
} | ||
|
||
/** | ||
* Custom hook for exposing address related functionality for the checkout address form. | ||
*/ | ||
export const useCheckoutAddress = (): CheckoutAddress => { | ||
const { needsShipping } = useShippingDataContext(); | ||
const { | ||
useShippingAsBilling, | ||
setUseShippingAsBilling, | ||
} = useCheckoutContext(); | ||
const { | ||
billingData, | ||
setBillingData, | ||
shippingAddress, | ||
setShippingAddress, | ||
} = useCustomerData(); | ||
|
||
const setEmail = useCallback( | ||
( value ) => | ||
void setBillingData( { | ||
email: value, | ||
} ), | ||
[ setBillingData ] | ||
); | ||
|
||
const setBillingPhone = useCallback( | ||
( value ) => | ||
void setBillingData( { | ||
phone: value, | ||
} ), | ||
[ setBillingData ] | ||
); | ||
|
||
const setShippingPhone = useCallback( | ||
( value ) => | ||
void setShippingAddress( { | ||
phone: value, | ||
} ), | ||
[ setShippingAddress ] | ||
); | ||
|
||
return { | ||
shippingAddress, | ||
billingData, | ||
setShippingAddress, | ||
setBillingData, | ||
setEmail, | ||
setBillingPhone, | ||
setShippingPhone, | ||
defaultAddressFields, | ||
useShippingAsBilling, | ||
setUseShippingAsBilling, | ||
showShippingFields: needsShipping, | ||
showBillingFields: ! needsShipping || ! useShippingAsBilling, | ||
}; | ||
}; |
Oops, something went wrong.