2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-10-20 16:18:13 +00:00
|
|
|
import classnames from 'classnames';
|
2021-11-04 11:03:33 +00:00
|
|
|
import { withFilteredAttributes } from '@woocommerce/shared-hocs';
|
2023-10-23 15:57:45 +00:00
|
|
|
import { FormStep } from '@woocommerce/blocks-components';
|
2021-07-22 11:03:00 +00:00
|
|
|
import { useCheckoutAddress } from '@woocommerce/base-context/hooks';
|
2022-06-10 16:33:15 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
|
|
|
import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data';
|
2021-07-22 11:03:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Block from './block';
|
|
|
|
import attributes from './attributes';
|
|
|
|
import { useCheckoutBlockContext } from '../../context';
|
2022-12-02 11:34:27 +00:00
|
|
|
import {
|
|
|
|
getBillingAddresssBlockTitle,
|
|
|
|
getBillingAddresssBlockDescription,
|
|
|
|
} from './utils';
|
2021-07-22 11:03:00 +00:00
|
|
|
|
|
|
|
const FrontendBlock = ( {
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
showStepNumber,
|
|
|
|
children,
|
2021-10-20 16:18:13 +00:00
|
|
|
className,
|
2021-07-22 11:03:00 +00:00
|
|
|
}: {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
showStepNumber: boolean;
|
|
|
|
children: JSX.Element;
|
2021-10-20 16:18:13 +00:00
|
|
|
className?: string;
|
2021-07-22 11:03:00 +00:00
|
|
|
} ): JSX.Element | null => {
|
2022-06-10 16:33:15 +00:00
|
|
|
const checkoutIsProcessing = useSelect( ( select ) =>
|
|
|
|
select( CHECKOUT_STORE_KEY ).isProcessing()
|
|
|
|
);
|
2021-07-22 11:03:00 +00:00
|
|
|
const {
|
|
|
|
requireCompanyField,
|
|
|
|
requirePhoneField,
|
|
|
|
showApartmentField,
|
|
|
|
showCompanyField,
|
|
|
|
showPhoneField,
|
|
|
|
} = useCheckoutBlockContext();
|
2023-11-15 15:22:36 +00:00
|
|
|
const { showBillingFields, forcedBillingAddress, useBillingAsShipping } =
|
|
|
|
useCheckoutAddress();
|
2021-07-22 11:03:00 +00:00
|
|
|
|
2022-12-23 15:05:56 +00:00
|
|
|
if ( ! showBillingFields && ! useBillingAsShipping ) {
|
2021-07-22 11:03:00 +00:00
|
|
|
return null;
|
|
|
|
}
|
2023-10-09 11:49:09 +00:00
|
|
|
|
2022-12-02 11:34:27 +00:00
|
|
|
title = getBillingAddresssBlockTitle( title, forcedBillingAddress );
|
|
|
|
description = getBillingAddresssBlockDescription(
|
|
|
|
description,
|
|
|
|
forcedBillingAddress
|
|
|
|
);
|
2021-07-22 11:03:00 +00:00
|
|
|
return (
|
|
|
|
<FormStep
|
|
|
|
id="billing-fields"
|
|
|
|
disabled={ checkoutIsProcessing }
|
2021-10-20 16:18:13 +00:00
|
|
|
className={ classnames(
|
|
|
|
'wc-block-checkout__billing-fields',
|
|
|
|
className
|
|
|
|
) }
|
2021-07-22 11:03:00 +00:00
|
|
|
title={ title }
|
|
|
|
description={ description }
|
|
|
|
showStepNumber={ showStepNumber }
|
|
|
|
>
|
|
|
|
<Block
|
|
|
|
requireCompanyField={ requireCompanyField }
|
|
|
|
showApartmentField={ showApartmentField }
|
|
|
|
showCompanyField={ showCompanyField }
|
|
|
|
showPhoneField={ showPhoneField }
|
|
|
|
requirePhoneField={ requirePhoneField }
|
|
|
|
/>
|
|
|
|
{ children }
|
|
|
|
</FormStep>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withFilteredAttributes( attributes )( FrontendBlock );
|