import clsx from 'clsx'; import PaymentCard from './payment-card'; import ExternalInfo from './external-info'; import { __experimentalHeading as Heading, __experimentalSpacer as Spacer, __experimentalText as Text, Button, Card, CardBody, CheckboxControl, ExternalLink, Flex, __experimentalInputControl as InputControl, SelectControl, Spinner, } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; import React, { useState } from 'react'; import { dispatch, select } from '@wordpress/data'; import { useSettings } from 'data/settings/hooks'; import { settingsStore } from 'data/settings'; // Shouldn't import from index to keep label-purchase decoupled from shipping-settings. import { getPaperSizes } from 'components/label-purchase/label/utils'; import { getStoreOrigin } from 'utils/location'; import { SETTINGS_KEYS } from './constants'; import { createInterpolateElement } from '@wordpress/element'; export const LabelsSettingsComponent = () => { const [ isLoading, setIsLoading ] = useState( false ); const paperSizes = getPaperSizes( getStoreOrigin().country ); const { labelSize, emailReceiptEnabled, rememberServiceEnabled, rememberPackageEnabled, checkoutAddressValidation, taxIdentifiers, storeOwnerUsername, storeOwnerLogin, storeOwnerEmail, automaticallyOpenPrintDialog, rememberLastUsedShippingDate, returnToSenderDefault, scanformEnabled, } = useSettings(); const maybeConfirmExit = ( isChanged: boolean ) => { if ( isChanged ) { window.onbeforeunload = function () { return true; }; } else { window.onbeforeunload = null; } }; const updateFormData = ( formInputKey: string ) => async ( formInputvalue: boolean | string | undefined ) => { await dispatch( settingsStore ).updateFormData( formInputKey, formInputvalue ?? null ); maybeConfirmExit( true ); }; const getLabelSizeOptions = () => { const sizes = []; sizes.push( { disabled: true, label: __( 'Select an Option', 'woocommerce-shipping' ), value: '', } ); paperSizes.map( ( size ) => { return sizes.push( { label: size.name, value: size.key, } ); } ); return sizes; }; const saveButtonHandler = async () => { setIsLoading( true ); const storeConfig = select( settingsStore ).getConfigSettings(); const saveResult = await dispatch( settingsStore ).saveSettings( { payload: storeConfig, } ); if ( saveResult && 'result' in saveResult && // @ts-ignore saveResult.result.success ) { // @ts-ignore dispatch wants a descriptor object dispatch( 'core/notices' ).createSuccessNotice( __( 'WooCommerce Shipping settings have been saved.', 'woocommerce-shipping' ) ); } setIsLoading( false ); maybeConfirmExit( false ); }; const className = clsx( 'wcshipping-settings__card', { loading: isLoading, } ); return ( { isLoading && ( ) } { __( 'Shipping Labels', 'woocommerce-shipping' ) } { __( 'Print shipping labels right from your WooCommerce dashboard and instantly save on shipping.', 'woocommerce-shipping' ) }

{ __( 'Select label size', 'woocommerce-shipping' ) }

{ __( 'Preferences', 'woocommerce-shipping' ) }

{ __( 'Tax identifiers', 'woocommerce-shipping' ) }

Import One-Stop Shop (IOSS) number to include it on customs forms when shipping to applicable EU countries.', 'woocommerce-shipping' ), { a: ( { __( 'Import One-Stop Shop (IOSS)', 'woocommerce-shipping' ) } ), } ) } onChange={ updateFormData( SETTINGS_KEYS.TAX_IDENTIFIER_IOSS ) } value={ taxIdentifiers?.ioss ?? '' } // Opt in to the new size for consistency with other form fields. __next40pxDefaultSize={ true } /> VOEC number (VAT On E-Commerce) number to include it on customs forms when shipping to Norway.', 'woocommerce-shipping' ), { a: ( { __( 'VOEC number (VAT On E-Commerce)', 'woocommerce-shipping' ) } ), } ) } onChange={ updateFormData( SETTINGS_KEYS.TAX_IDENTIFIER_VOEC ) } value={ taxIdentifiers?.voec ?? '' } // Opt in to the new size for consistency with other form fields. __next40pxDefaultSize={ true } /> PVA number number to include it on customs forms when shipping to the United Kingdom of Great Britain and Northern Ireland.', 'woocommerce-shipping' ), { a: ( { __( 'PVA number (Postponed VAT Accounting)', 'woocommerce-shipping' ) } ), } ) } onChange={ updateFormData( SETTINGS_KEYS.TAX_IDENTIFIER_PVA ) } value={ taxIdentifiers?.pva ?? '' } // Opt in to the new size for consistency with other form fields. __next40pxDefaultSize={ true } />
); };