2023-04-24 02:08:24 +00:00
|
|
|
/**
|
2023-05-14 20:56:47 +00:00
|
|
|
* External dependencies
|
2023-04-24 02:08:24 +00:00
|
|
|
*/
|
2023-05-14 20:56:47 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Button } from '@wordpress/components';
|
|
|
|
import { SelectControl } from '@woocommerce/components';
|
|
|
|
import { Icon, chevronDown } from '@wordpress/icons';
|
|
|
|
import { useState } from '@wordpress/element';
|
2023-04-24 02:08:24 +00:00
|
|
|
|
2023-05-14 20:56:47 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
BusinessLocationEvent,
|
|
|
|
CoreProfilerStateMachineContext,
|
|
|
|
} from '../index';
|
|
|
|
import { CountryStateOption } from '../services/country';
|
|
|
|
import { Heading } from '../components/heading/heading';
|
|
|
|
import { Navigation } from '../components/navigation/navigation';
|
2023-04-24 02:08:24 +00:00
|
|
|
export const BusinessLocation = ( {
|
|
|
|
sendEvent,
|
2023-05-14 20:56:47 +00:00
|
|
|
navigationProgress,
|
|
|
|
context,
|
2023-04-24 02:08:24 +00:00
|
|
|
}: {
|
|
|
|
sendEvent: ( event: BusinessLocationEvent ) => void;
|
2023-05-14 20:56:47 +00:00
|
|
|
navigationProgress: number;
|
2023-07-24 12:34:38 +00:00
|
|
|
context: Pick< CoreProfilerStateMachineContext, 'countries' >;
|
2023-04-24 02:08:24 +00:00
|
|
|
} ) => {
|
2023-05-14 20:56:47 +00:00
|
|
|
const [ storeCountry, setStoreCountry ] = useState< CountryStateOption >( {
|
|
|
|
key: '',
|
|
|
|
label: '',
|
|
|
|
} );
|
|
|
|
|
|
|
|
const inputLabel = __( 'Select country/region', 'woocommerce' );
|
|
|
|
|
2023-04-24 02:08:24 +00:00
|
|
|
return (
|
2023-05-16 00:56:39 +00:00
|
|
|
<div
|
|
|
|
className="woocommerce-profiler-business-location"
|
|
|
|
data-testid="core-profiler-business-location"
|
|
|
|
>
|
2023-05-14 20:56:47 +00:00
|
|
|
<Navigation percentage={ navigationProgress } />
|
|
|
|
<div className="woocommerce-profiler-page__content woocommerce-profiler-business-location__content">
|
|
|
|
<Heading
|
2023-05-22 03:21:16 +00:00
|
|
|
className="woocommerce-profiler__stepper-heading"
|
2023-05-14 20:56:47 +00:00
|
|
|
title={ __(
|
|
|
|
'Where is your business located?',
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
subTitle={ __(
|
|
|
|
"We'll use this information to help you set up payments, shipping, and taxes.",
|
|
|
|
'woocommerce'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
<SelectControl
|
|
|
|
className="woocommerce-profiler-select-control__country"
|
|
|
|
instanceId={ 1 }
|
|
|
|
placeholder={ inputLabel }
|
|
|
|
label={ storeCountry.key === '' ? inputLabel : '' }
|
|
|
|
getSearchExpression={ ( query: string ) => {
|
|
|
|
return new RegExp(
|
|
|
|
'(^' + query + '| — (' + query + '))',
|
|
|
|
'i'
|
|
|
|
);
|
|
|
|
} }
|
|
|
|
autoComplete="new-password" // disable autocomplete and autofill
|
|
|
|
options={ context.countries }
|
|
|
|
excludeSelectedOptions={ false }
|
|
|
|
help={ <Icon icon={ chevronDown } /> }
|
|
|
|
onChange={ ( results: Array< CountryStateOption > ) => {
|
|
|
|
if ( results.length ) {
|
|
|
|
setStoreCountry( results[ 0 ] );
|
|
|
|
}
|
|
|
|
} }
|
|
|
|
selected={ storeCountry ? [ storeCountry ] : [] }
|
|
|
|
showAllOnFocus
|
|
|
|
isSearchable
|
|
|
|
/>
|
2023-05-22 03:21:16 +00:00
|
|
|
<div className="woocommerce-profiler-button-container woocommerce-profiler-go-to-mystore__button-container">
|
2023-05-14 20:56:47 +00:00
|
|
|
<Button
|
2023-05-22 03:21:16 +00:00
|
|
|
className="woocommerce-profiler-button"
|
2023-05-14 20:56:47 +00:00
|
|
|
variant="primary"
|
|
|
|
disabled={ ! storeCountry.key }
|
|
|
|
onClick={ () => {
|
|
|
|
sendEvent( {
|
|
|
|
type: 'BUSINESS_LOCATION_COMPLETED',
|
|
|
|
payload: {
|
2023-05-30 07:05:38 +00:00
|
|
|
storeLocation: storeCountry.key,
|
2023-05-14 20:56:47 +00:00
|
|
|
},
|
|
|
|
} );
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ __( 'Go to my store', 'woocommerce' ) }
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-24 02:08:24 +00:00
|
|
|
);
|
|
|
|
};
|