/* eslint-disable @wordpress/no-unsafe-wp-apis */ /** * External dependencies */ import classnames from 'classnames'; import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { PanelBody, ToggleControl, __experimentalRadio as Radio, __experimentalRadioGroup as RadioGroup, } from '@wordpress/components'; import { Icon, store, shipping } from '@wordpress/icons'; import { InspectorControls, useBlockProps, RichText, } from '@wordpress/block-editor'; import { useShippingData } from '@woocommerce/base-context/hooks'; import { innerBlockAreas } from '@woocommerce/blocks-checkout'; import type { CartShippingPackageShippingRate } from '@woocommerce/type-defs/cart'; import { useDispatch, useSelect } from '@wordpress/data'; import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data'; /** * Internal dependencies */ import { FormStepBlock, AdditionalFields, AdditionalFieldsContent, } from '../../form-step'; import { RatePrice, getLocalPickupStartingPrice, getShippingStartingPrice, } from './shared'; import './style.scss'; const LocalPickupSelector = ( { checked, rate, showPrice, showIcon, toggleText, setAttributes, }: { checked: string; rate: CartShippingPackageShippingRate; showPrice: boolean; showIcon: boolean; toggleText: string; setAttributes: ( attributes: Record< string, unknown > ) => void; } ) => { return ( { showIcon === true && ( ) } setAttributes( { localPickupText: value } ) } __unstableDisableFormats preserveWhiteSpace /> { showPrice === true && } ); }; const ShippingSelector = ( { checked, rate, showPrice, showIcon, toggleText, setAttributes, }: { checked: string; rate: CartShippingPackageShippingRate; showPrice: boolean; showIcon: boolean; toggleText: string; setAttributes: ( attributes: Record< string, unknown > ) => void; } ) => { const Price = rate === undefined ? ( { __( 'calculated with an address', 'woo-gutenberg-products-block' ) } ) : ( ); return ( { showIcon === true && ( ) } setAttributes( { shippingText: value } ) } __unstableDisableFormats preserveWhiteSpace /> { showPrice === true && Price } ); }; export const Edit = ( { attributes, setAttributes, }: { attributes: { title: string; description: string; showStepNumber: boolean; allowCreateAccount: boolean; localPickupText: string; shippingText: string; showPrice: boolean; showIcon: boolean; className: string; }; setAttributes: ( attributes: Record< string, unknown > ) => void; } ): JSX.Element => { const { setPrefersCollection } = useDispatch( CHECKOUT_STORE_KEY ); const { prefersCollection } = useSelect( ( select ) => { const checkoutStore = select( CHECKOUT_STORE_KEY ); return { prefersCollection: checkoutStore.prefersCollection(), }; } ); const { showPrice, showIcon, className, localPickupText, shippingText } = attributes; const { shippingRates } = useShippingData(); const localPickupStartingPrice = getLocalPickupStartingPrice( shippingRates[ 0 ]?.shipping_rates ); const shippingStartingPrice = getShippingStartingPrice( shippingRates[ 0 ]?.shipping_rates ); const changeView = ( method: string ) => { if ( method === 'pickup' ) { setPrefersCollection( true ); } else { setPrefersCollection( false ); } }; return (

{ __( 'Choose how this block is displayed to your customers.', 'woo-gutenberg-products-block' ) }

setAttributes( { showIcon: ! showIcon, } ) } /> setAttributes( { showPrice: ! showPrice, } ) } />
); }; export const Save = (): JSX.Element => { return (
); };