/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import type { UniqueIdentifier } from '@dnd-kit/core';
import { isBoolean } from '@woocommerce/types';
import { ToggleControl, Button, ExternalLink } from '@wordpress/components';
import styled from '@emotion/styled';
/**
* Internal dependencies
*/
import {
SettingsSection,
SortableTable,
SortableData,
} from '../shared-components';
import EditLocation from './edit-location';
import type { SortablePickupLocation } from './types';
import { useSettingsContext } from './settings-context';
import { getUserFriendlyAddress } from './utils';
const LocationSettingsDescription = () => (
<>
{ __( 'Pickup locations', 'woocommerce' ) }
{ __(
'Define pickup locations for your customers to choose from during checkout.',
'woocommerce'
) }
{ __( 'Learn more', 'woocommerce' ) }
>
);
const StyledAddress = styled.address`
color: #757575;
font-style: normal;
display: inline;
margin-left: 12px;
`;
const LocationSettings = () => {
const {
pickupLocations,
setPickupLocations,
toggleLocation,
updateLocation,
readOnlySettings,
} = useSettingsContext();
const [ editingLocation, setEditingLocation ] =
useState< UniqueIdentifier >( '' );
const tableColumns = [
{
name: 'name',
label: __( 'Pickup location', 'woocommerce' ),
width: '50%',
renderCallback: ( row: SortableData ): JSX.Element => (
<>
{ row.name }
{ getUserFriendlyAddress( row.address ) }
>
),
},
{
name: 'enabled',
label: __( 'Enabled', 'woocommerce' ),
align: 'right',
renderCallback: ( row: SortableData ): JSX.Element => (
toggleLocation( row.id ) }
/>
),
},
{
name: 'edit',
label: '',
align: 'center',
width: '1%',
renderCallback: ( row: SortableData ): JSX.Element => (
),
},
];
const FooterContent = (): JSX.Element => (
);
return (
{
setPickupLocations( newData as SortablePickupLocation[] );
} }
placeholder={ __(
'When you add a pickup location, it will appear here.',
'woocommerce'
) }
footerContent={ FooterContent }
/>
{ editingLocation && (
{
return id === editingLocation;
} ) || null
}
editingLocation={ editingLocation }
onSave={ ( values ) => {
updateLocation(
editingLocation,
values as SortablePickupLocation
);
} }
onClose={ () => setEditingLocation( '' ) }
onDelete={ () => {
updateLocation( editingLocation, null );
setEditingLocation( '' );
} }
/>
) }
);
};
export default LocationSettings;