2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-03-22 14:14:14 +00:00
|
|
|
import type { ReactElement } from 'react';
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2024-09-03 14:42:28 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-07-22 11:03:00 +00:00
|
|
|
import { Main } from '@woocommerce/base-components/sidebar-layout';
|
2023-11-03 16:30:40 +00:00
|
|
|
import { useStoreEvents } from '@woocommerce/base-context/hooks';
|
|
|
|
import { useEffect } from '@wordpress/element';
|
2024-05-22 14:03:48 +00:00
|
|
|
import { useCheckoutBlockContext } from '@woocommerce/blocks/checkout/context';
|
2021-07-22 11:03:00 +00:00
|
|
|
|
|
|
|
const FrontendBlock = ( {
|
|
|
|
children,
|
2021-10-20 16:18:13 +00:00
|
|
|
className,
|
2021-07-22 11:03:00 +00:00
|
|
|
}: {
|
2024-03-22 14:14:14 +00:00
|
|
|
children: ReactElement[];
|
2021-10-20 16:18:13 +00:00
|
|
|
className?: string;
|
2021-07-22 11:03:00 +00:00
|
|
|
} ): JSX.Element => {
|
2023-11-03 16:30:40 +00:00
|
|
|
const { dispatchCheckoutEvent } = useStoreEvents();
|
2024-05-22 14:03:48 +00:00
|
|
|
const { showFormStepNumbers } = useCheckoutBlockContext();
|
2023-11-03 16:30:40 +00:00
|
|
|
|
|
|
|
// Ignore changes to dispatchCheckoutEvent callback so this is ran on first mount only.
|
|
|
|
useEffect( () => {
|
|
|
|
dispatchCheckoutEvent( 'render-checkout-form' );
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [] );
|
|
|
|
|
2021-07-22 11:03:00 +00:00
|
|
|
return (
|
2024-05-31 03:49:36 +00:00
|
|
|
<Main className={ clsx( 'wc-block-checkout__main', className ) }>
|
2024-05-22 14:03:48 +00:00
|
|
|
<form
|
2024-09-03 14:42:28 +00:00
|
|
|
aria-label={ __( 'Checkout', 'woocommerce' ) }
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx(
|
2024-05-22 14:03:48 +00:00
|
|
|
'wc-block-components-form wc-block-checkout__form',
|
|
|
|
{
|
|
|
|
'wc-block-checkout__form--with-step-numbers':
|
|
|
|
showFormStepNumbers,
|
|
|
|
}
|
|
|
|
) }
|
|
|
|
>
|
2021-07-22 11:03:00 +00:00
|
|
|
{ children }
|
|
|
|
</form>
|
|
|
|
</Main>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FrontendBlock;
|