2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-10-20 16:18:13 +00:00
|
|
|
import classnames from 'classnames';
|
2021-07-22 11:03:00 +00:00
|
|
|
import { useBlockProps } from '@wordpress/block-editor';
|
|
|
|
import { useCheckoutAddress } from '@woocommerce/base-context/hooks';
|
2021-09-03 13:25:09 +00:00
|
|
|
import { innerBlockAreas } from '@woocommerce/blocks-checkout';
|
2022-12-02 11:34:27 +00:00
|
|
|
import { BlockAttributes } from '@wordpress/blocks';
|
2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
FormStepBlock,
|
|
|
|
AdditionalFields,
|
|
|
|
AdditionalFieldsContent,
|
|
|
|
} from '../../form-step';
|
|
|
|
import {
|
|
|
|
useCheckoutBlockContext,
|
|
|
|
useCheckoutBlockControlsContext,
|
|
|
|
} from '../../context';
|
|
|
|
import Block from './block';
|
2022-12-02 11:34:27 +00:00
|
|
|
import {
|
|
|
|
getBillingAddresssBlockTitle,
|
|
|
|
getBillingAddresssBlockDescription,
|
|
|
|
} from './utils';
|
2021-07-22 11:03:00 +00:00
|
|
|
|
|
|
|
export const Edit = ( {
|
|
|
|
attributes,
|
|
|
|
setAttributes,
|
|
|
|
}: {
|
|
|
|
attributes: {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
showStepNumber: boolean;
|
2021-10-20 16:18:13 +00:00
|
|
|
className: string;
|
2021-07-22 11:03:00 +00:00
|
|
|
};
|
2022-12-02 11:34:27 +00:00
|
|
|
setAttributes: ( attributes: BlockAttributes ) => void;
|
2021-07-22 11:03:00 +00:00
|
|
|
} ): JSX.Element | null => {
|
|
|
|
const {
|
|
|
|
showCompanyField,
|
|
|
|
showApartmentField,
|
|
|
|
requireCompanyField,
|
|
|
|
showPhoneField,
|
|
|
|
requirePhoneField,
|
|
|
|
} = useCheckoutBlockContext();
|
2022-06-15 09:56:52 +00:00
|
|
|
const { addressFieldControls: Controls } =
|
|
|
|
useCheckoutBlockControlsContext();
|
2022-12-02 11:34:27 +00:00
|
|
|
const { showBillingFields, forcedBillingAddress } = useCheckoutAddress();
|
2021-07-22 11:03:00 +00:00
|
|
|
|
2022-12-02 11:34:27 +00:00
|
|
|
if ( ! showBillingFields && ! forcedBillingAddress ) {
|
2021-07-22 11:03:00 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-12-02 11:34:27 +00:00
|
|
|
attributes.title = getBillingAddresssBlockTitle(
|
|
|
|
attributes.title,
|
|
|
|
forcedBillingAddress
|
|
|
|
);
|
|
|
|
attributes.description = getBillingAddresssBlockDescription(
|
|
|
|
attributes.description,
|
|
|
|
forcedBillingAddress
|
|
|
|
);
|
2021-07-22 11:03:00 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<FormStepBlock
|
|
|
|
setAttributes={ setAttributes }
|
|
|
|
attributes={ attributes }
|
2021-10-20 16:18:13 +00:00
|
|
|
className={ classnames(
|
|
|
|
'wc-block-checkout__billing-fields',
|
|
|
|
attributes?.className
|
|
|
|
) }
|
2021-07-22 11:03:00 +00:00
|
|
|
>
|
|
|
|
<Controls />
|
|
|
|
<Block
|
|
|
|
showCompanyField={ showCompanyField }
|
|
|
|
showApartmentField={ showApartmentField }
|
|
|
|
requireCompanyField={ requireCompanyField }
|
|
|
|
showPhoneField={ showPhoneField }
|
|
|
|
requirePhoneField={ requirePhoneField }
|
|
|
|
/>
|
2021-09-07 16:01:14 +00:00
|
|
|
<AdditionalFields block={ innerBlockAreas.BILLING_ADDRESS } />
|
2021-07-22 11:03:00 +00:00
|
|
|
</FormStepBlock>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<div { ...useBlockProps.save() }>
|
|
|
|
<AdditionalFieldsContent />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|