/** * External dependencies */ import classnames from 'classnames'; import { __ } from '@wordpress/i18n'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { PanelBody, ExternalLink, ToggleControl } from '@wordpress/components'; import { ADMIN_URL, getSetting } from '@woocommerce/settings'; import ExternalLinkCard from '@woocommerce/editor-components/external-link-card'; import { innerBlockAreas } from '@woocommerce/blocks-checkout'; import { useCheckoutAddress } from '@woocommerce/base-context/hooks'; import Noninteractive from '@woocommerce/base-components/noninteractive'; import { Attributes } from '@woocommerce/blocks/checkout/types'; import { updateAttributeInSiblingBlock } from '@woocommerce/utils'; /** * Internal dependencies */ import { FormStepBlock, AdditionalFields, AdditionalFieldsContent, } from '../../form-step'; import NoShippingPlaceholder from './no-shipping-placeholder'; import Block from './block'; import './editor.scss'; type shippingAdminLink = { id: number; title: string; description: string; }; export const Edit = ( { attributes, setAttributes, clientId, }: { clientId: string; attributes: { title: string; description: string; showStepNumber: boolean; className: string; shippingCostRequiresAddress: boolean; }; setAttributes: ( attributes: Record< string, unknown > ) => void; } ): JSX.Element | null => { const globalShippingMethods = getSetting( 'globalShippingMethods' ) as shippingAdminLink[]; const activeShippingZones = getSetting( 'activeShippingZones' ) as shippingAdminLink[]; const { showShippingMethods } = useCheckoutAddress(); if ( ! showShippingMethods ) { return null; } const toggleAttribute = ( key: keyof Attributes ): void => { const newAttributes = {} as Partial< Attributes >; newAttributes[ key ] = ! ( attributes[ key ] as boolean ); setAttributes( newAttributes ); }; return ( { updateAttributeInSiblingBlock( clientId, 'shippingCostRequiresAddress', selected, 'woocommerce/checkout-shipping-method-block' ); toggleAttribute( 'shippingCostRequiresAddress' ); } } /> { globalShippingMethods.length > 0 && (

{ __( 'The following shipping integrations are active on your store.', 'woo-gutenberg-products-block' ) }

{ globalShippingMethods.map( ( method ) => { return ( ); } ) } { __( 'Manage shipping methods', 'woo-gutenberg-products-block' ) }
) } { activeShippingZones.length && (

{ __( 'You currently have the following shipping zones active.', 'woo-gutenberg-products-block' ) }

{ activeShippingZones.map( ( zone ) => { return ( ); } ) } { __( 'Manage shipping zones', 'woo-gutenberg-products-block' ) }
) }
} shippingCostRequiresAddress={ attributes.shippingCostRequiresAddress } />
); }; export const Save = (): JSX.Element => { return (
); };