/**
* External dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { createInterpolateElement, useState } from '@wordpress/element';
import { ADMIN_URL, getSetting } from '@woocommerce/settings';
import { CHECKOUT_PAGE_ID } from '@woocommerce/block-settings';
import {
CheckboxControl,
SelectControl,
TextControl,
ExternalLink,
Notice,
} from '@wordpress/components';
import styled from '@emotion/styled';
/**
* Internal dependencies
*/
import { SettingsCard, SettingsSection } from '../shared-components';
import { useSettingsContext } from './settings-context';
const GeneralSettingsDescription = () => (
<>
{ _x( 'General', 'Admin settings', 'woocommerce' ) }
{ __(
'Enable or disable local pickup on your store, and define costs. Local pickup is only available from the block checkout.',
'woocommerce'
) }
{ __( 'View checkout page', 'woocommerce' ) }
>
);
const StyledNotice = styled( Notice )`
margin-left: 0;
margin-right: 0;
`;
const GeneralSettings = () => {
const { settings, setSettingField, readOnlySettings } =
useSettingsContext();
const [ showCosts, setShowCosts ] = useState( !! settings.cost );
const shippingCostRequiresAddress = getSetting< boolean >(
'shippingCostRequiresAddress',
false
);
return (
{ readOnlySettings.hasLegacyPickup && (
{ createInterpolateElement(
__(
"By enabling Local Pickup with more valuable features for your store, it's recommended that you remove the legacy Local Pickup option from your shipping zones.",
'woocommerce'
),
{
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
),
}
) }
) }
{ __(
'When enabled, local pickup will appear as an option on the block based checkout.',
'woocommerce'
) }
{ shippingCostRequiresAddress ? (
<>
{ __(
'If local pickup is enabled, the "Hide shipping costs until an address is entered" setting will be ignored.',
'woocommerce'
) }
>
) : null }
}
/>
) => {
event.target.setCustomValidity(
__(
'Local pickup title is required',
'woocommerce'
)
);
} }
onInput={ (
event: React.ChangeEvent< HTMLInputElement >
) => {
event.target.setCustomValidity( '' );
} }
/>
{
setShowCosts( ! showCosts );
setSettingField( 'cost' )( '' );
} }
label={ __(
'Add a price for customers who choose local pickup',
'woocommerce'
) }
help={ __(
'By default, the local pickup shipping method is free.',
'woocommerce'
) }
/>
{ showCosts ? (
<>
>
) : null }
);
};
export default GeneralSettings;