2022-10-04 12:02:28 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2022-10-04 12:02:28 +00:00
|
|
|
import { withFilteredAttributes } from '@woocommerce/shared-hocs';
|
2023-10-23 15:57:45 +00:00
|
|
|
import { FormStep } from '@woocommerce/blocks-components';
|
2022-10-11 15:46:59 +00:00
|
|
|
import { useSelect } from '@wordpress/data';
|
2022-10-04 12:02:28 +00:00
|
|
|
import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data';
|
2022-12-09 09:50:08 +00:00
|
|
|
import { LOCAL_PICKUP_ENABLED } from '@woocommerce/block-settings';
|
2024-05-22 14:03:48 +00:00
|
|
|
import { useCheckoutBlockContext } from '@woocommerce/blocks/checkout/context';
|
|
|
|
|
2022-10-04 12:02:28 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Block from './block';
|
|
|
|
import attributes from './attributes';
|
|
|
|
|
|
|
|
const FrontendBlock = ( {
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
}: {
|
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
showStepNumber: boolean;
|
|
|
|
children: JSX.Element;
|
|
|
|
className?: string;
|
|
|
|
} ) => {
|
|
|
|
const { checkoutIsProcessing, prefersCollection } = useSelect(
|
|
|
|
( select ) => {
|
|
|
|
const checkoutStore = select( CHECKOUT_STORE_KEY );
|
|
|
|
return {
|
|
|
|
checkoutIsProcessing: checkoutStore.isProcessing(),
|
|
|
|
prefersCollection: checkoutStore.prefersCollection(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-05-22 14:03:48 +00:00
|
|
|
const { showFormStepNumbers } = useCheckoutBlockContext();
|
|
|
|
|
2022-12-09 09:50:08 +00:00
|
|
|
if ( ! prefersCollection || ! LOCAL_PICKUP_ENABLED ) {
|
2022-10-11 15:46:59 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-10-04 12:02:28 +00:00
|
|
|
return (
|
|
|
|
<FormStep
|
2022-10-11 15:46:59 +00:00
|
|
|
id="pickup-options"
|
2022-10-04 12:02:28 +00:00
|
|
|
disabled={ checkoutIsProcessing }
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx( 'wc-block-checkout__pickup-options', className ) }
|
2022-10-04 12:02:28 +00:00
|
|
|
title={ title }
|
|
|
|
description={ description }
|
2024-05-22 14:03:48 +00:00
|
|
|
showStepNumber={ showFormStepNumbers }
|
2022-10-04 12:02:28 +00:00
|
|
|
>
|
2022-10-11 15:46:59 +00:00
|
|
|
<Block />
|
2022-10-04 12:02:28 +00:00
|
|
|
{ children }
|
|
|
|
</FormStep>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withFilteredAttributes( attributes )( FrontendBlock );
|