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';
|
2022-10-06 12:00:30 +00:00
|
|
|
import { useCheckoutAddress } from '@woocommerce/base-context/hooks';
|
2021-09-03 13:25:09 +00:00
|
|
|
import { innerBlockAreas } from '@woocommerce/blocks-checkout';
|
2022-12-07 13:39:13 +00:00
|
|
|
|
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';
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
setAttributes: ( attributes: Record< string, unknown > ) => void;
|
2022-12-02 11:34:27 +00:00
|
|
|
} ): JSX.Element | null => {
|
2021-07-22 11:03:00 +00:00
|
|
|
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 { showShippingFields } = useCheckoutAddress();
|
2022-10-06 12:00:30 +00:00
|
|
|
|
2022-12-02 11:34:27 +00:00
|
|
|
if ( ! showShippingFields ) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-10-06 12:00:30 +00:00
|
|
|
|
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__shipping-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.SHIPPING_ADDRESS } />
|
2021-07-22 11:03:00 +00:00
|
|
|
</FormStepBlock>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<div { ...useBlockProps.save() }>
|
|
|
|
<AdditionalFieldsContent />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|