2021-11-02 17:33:42 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-03-01 22:36:38 +00:00
|
|
|
import { SETTINGS_STORE_NAME } from '@woocommerce/data';
|
2021-11-02 17:33:42 +00:00
|
|
|
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';
|
2022-08-08 05:25:46 +00:00
|
|
|
import { hasCompleteAddress } from '../utils';
|
2021-11-05 20:32:02 +00:00
|
|
|
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 } ) => {
|
2022-04-21 04:44:19 +00:00
|
|
|
const { createNotice } = useDispatch( 'core/notices' );
|
2022-06-21 08:37:34 +00:00
|
|
|
const { updateAndPersistSettingsForGroup } =
|
|
|
|
useDispatch( SETTINGS_STORE_NAME );
|
2022-04-25 05:49:11 +00:00
|
|
|
const { generalSettings, isResolving } = useSelect( ( select ) => {
|
2022-08-08 05:25:46 +00:00
|
|
|
const { getSettings, hasFinishedResolution } =
|
|
|
|
select( SETTINGS_STORE_NAME );
|
2021-11-02 17:33:42 +00:00
|
|
|
|
2022-04-25 05:49:11 +00:00
|
|
|
return {
|
|
|
|
generalSettings: getSettings( 'general' )?.general,
|
|
|
|
isResolving: ! hasFinishedResolution( 'getSettings', [
|
|
|
|
'general',
|
|
|
|
] ),
|
|
|
|
};
|
|
|
|
} );
|
2021-11-02 17:33:42 +00:00
|
|
|
|
|
|
|
useEffect( () => {
|
2022-08-08 05:25:46 +00:00
|
|
|
if ( isResolving || ! hasCompleteAddress( generalSettings || {} ) ) {
|
2021-11-02 17:33:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
nextStep();
|
|
|
|
}, [ isResolving ] );
|
|
|
|
|
|
|
|
if ( isResolving ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StoreLocationForm
|
2022-04-21 04:44:19 +00:00
|
|
|
onComplete={ ( values: { [ key: string ]: string } ) => {
|
2021-11-02 17:33:42 +00:00
|
|
|
const country = getCountryCode( values.countryState );
|
|
|
|
recordEvent( 'tasklist_tax_set_location', {
|
|
|
|
country,
|
|
|
|
} );
|
|
|
|
nextStep();
|
|
|
|
} }
|
|
|
|
isSettingsRequesting={ false }
|
|
|
|
settings={ generalSettings }
|
|
|
|
updateAndPersistSettingsForGroup={
|
|
|
|
updateAndPersistSettingsForGroup
|
|
|
|
}
|
2022-04-21 04:44:19 +00:00
|
|
|
createNotice={ createNotice }
|
|
|
|
isSettingsError={ false }
|
2021-11-02 17:33:42 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|