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,
|
|
|
|
children,
|
2021-10-20 16:18:13 +00:00
|
|
|
className,
|
2021-07-22 11:03:00 +00:00
|
|
|
}: {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
children: JSX.Element;
|
2021-10-20 16:18:13 +00:00
|
|
|
className?: string;
|
2021-07-22 11:03:00 +00:00
|
|
|
} ): JSX.Element | null => {
|
2024-05-22 14:03:48 +00:00
|
|
|
const { showFormStepNumbers } = useCheckoutBlockContext();
|
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 {
|
2024-05-21 08:48:24 +00:00
|
|
|
showCompanyField,
|
2021-07-22 11:03:00 +00:00
|
|
|
requireCompanyField,
|
|
|
|
showApartmentField,
|
2024-05-21 08:48:24 +00:00
|
|
|
requireApartmentField,
|
2021-07-22 11:03:00 +00:00
|
|
|
showPhoneField,
|
2024-05-21 08:48:24 +00:00
|
|
|
requirePhoneField,
|
2021-07-22 11:03:00 +00:00
|
|
|
} = 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 }
|
2024-05-22 14:03:48 +00:00
|
|
|
showStepNumber={ showFormStepNumbers }
|
2021-07-22 11:03:00 +00:00
|
|
|
>
|
|
|
|
<Block
|
2024-05-21 08:48:24 +00:00
|
|
|
showCompanyField={ showCompanyField }
|
2021-07-22 11:03:00 +00:00
|
|
|
requireCompanyField={ requireCompanyField }
|
|
|
|
showApartmentField={ showApartmentField }
|
2024-05-21 08:48:24 +00:00
|
|
|
requireApartmentField={ requireApartmentField }
|
2021-07-22 11:03:00 +00:00
|
|
|
showPhoneField={ showPhoneField }
|
|
|
|
requirePhoneField={ requirePhoneField }
|
|
|
|
/>
|
|
|
|
{ children }
|
|
|
|
</FormStep>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withFilteredAttributes( attributes )( FrontendBlock );
|