2021-11-02 17:33:42 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { SETTINGS_STORE_NAME } from '@woocommerce/data';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
import { useEffect } from '@wordpress/element';
|
|
|
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-11-05 20:32:02 +00:00
|
|
|
import { getCountryCode } from '~/dashboard/utils';
|
|
|
|
import { hasCompleteAddress, SettingsSelector, TaxChildProps } from '../utils';
|
|
|
|
import { default as StoreLocationForm } from '~/tasks/fills/steps/location';
|
2021-11-02 17:33:42 +00:00
|
|
|
|
2021-11-05 20:32:02 +00:00
|
|
|
export const StoreLocation: React.FC< {
|
|
|
|
nextStep: () => void;
|
|
|
|
} > = ( { nextStep } ) => {
|
2021-11-02 17:33:42 +00:00
|
|
|
const { updateAndPersistSettingsForGroup } = useDispatch(
|
|
|
|
SETTINGS_STORE_NAME
|
|
|
|
);
|
2021-11-05 20:32:02 +00:00
|
|
|
const { generalSettings, isResolving } = useSelect( ( select ) => {
|
|
|
|
const { getSettings, hasFinishedResolution } = select(
|
2021-11-02 17:33:42 +00:00
|
|
|
SETTINGS_STORE_NAME
|
|
|
|
) as SettingsSelector;
|
|
|
|
|
|
|
|
return {
|
|
|
|
generalSettings: getSettings( 'general' )?.general,
|
2021-11-05 20:32:02 +00:00
|
|
|
isResolving: ! hasFinishedResolution( 'getSettings', [
|
|
|
|
'general',
|
|
|
|
] ),
|
2021-11-02 17:33:42 +00:00
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
if ( isResolving || ! hasCompleteAddress( generalSettings ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nextStep();
|
|
|
|
}, [ isResolving ] );
|
|
|
|
|
|
|
|
if ( isResolving ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StoreLocationForm
|
|
|
|
onComplete={ ( values ) => {
|
|
|
|
const country = getCountryCode( values.countryState );
|
|
|
|
recordEvent( 'tasklist_tax_set_location', {
|
|
|
|
country,
|
|
|
|
} );
|
|
|
|
nextStep();
|
|
|
|
} }
|
|
|
|
isSettingsRequesting={ false }
|
|
|
|
settings={ generalSettings }
|
|
|
|
updateAndPersistSettingsForGroup={
|
|
|
|
updateAndPersistSettingsForGroup
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|