/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { useState } from '@wordpress/element'; import type { UniqueIdentifier } from '@dnd-kit/core'; import { isObject, 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'; const LocationSettingsDescription = () => ( <>

{ __( 'Pickup Locations', 'woo-gutenberg-products-block' ) }

{ __( 'Define pickup locations for your customers to choose from during checkout.', 'woo-gutenberg-products-block' ) }

{ __( 'Learn more', 'woo-gutenberg-products-block' ) } ); const StyledAddress = styled.address` color: #757575; font-style: normal; display: inline; margin-left: 12px; `; const LocationSettings = () => { const { pickupLocations, setPickupLocations, toggleLocation, updateLocation, } = useSettingsContext(); const [ editingLocation, setEditingLocation ] = useState< UniqueIdentifier >( '' ); const tableColumns = [ { name: 'name', label: __( 'Pickup Location', 'woo-gutenberg-products-block' ), width: '50%', renderCallback: ( row: SortableData ): JSX.Element => ( <> { row.name } { isObject( row.address ) && Object.values( row.address ) .filter( ( value ) => value !== '' ) .join( ', ' ) } ), }, { name: 'enabled', label: __( 'Enabled', 'woo-gutenberg-products-block' ), 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[] ); } } 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;