40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
/**
|
|
* External dependencies
|
|
*/
|
|
import { __ } from '@wordpress/i18n';
|
|
import {
|
|
useCheckoutContext,
|
|
usePaymentMethodDataContext,
|
|
} from '@woocommerce/base-context';
|
|
import { usePaymentMethods } from '@woocommerce/base-hooks';
|
|
|
|
/**
|
|
* Returns the submitButtonText, onSubmit interface from the checkout context,
|
|
* and an indication of submission status.
|
|
*/
|
|
export const useCheckoutSubmit = () => {
|
|
const {
|
|
onSubmit,
|
|
isCalculating,
|
|
isBeforeProcessing,
|
|
isProcessing,
|
|
isAfterProcessing,
|
|
isComplete,
|
|
hasError,
|
|
} = useCheckoutContext();
|
|
const { paymentMethods } = usePaymentMethods();
|
|
const { activePaymentMethod } = usePaymentMethodDataContext();
|
|
const paymentMethod = paymentMethods[ activePaymentMethod ] || {};
|
|
|
|
return {
|
|
submitButtonText:
|
|
paymentMethod?.placeOrderButtonLabel ||
|
|
__( 'Place Order', 'woo-gutenberg-products-block' ),
|
|
onSubmit,
|
|
isCalculating,
|
|
waitingForProcessing:
|
|
isProcessing || isAfterProcessing || isBeforeProcessing,
|
|
waitingForRedirect: isComplete && ! hasError,
|
|
};
|
|
};
|