2022-06-28 05:53:03 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { SETTINGS_STORE_NAME } from '@woocommerce/data';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2022-06-30 06:45:52 +00:00
|
|
|
import { useEffect, useState } from '@wordpress/element';
|
2022-06-28 05:53:03 +00:00
|
|
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { getCountryCode } from '~/dashboard/utils';
|
2022-08-08 05:25:46 +00:00
|
|
|
import { hasCompleteAddress } from '../../tax/utils';
|
2022-06-28 05:53:03 +00:00
|
|
|
import { default as StoreLocationForm } from '~/tasks/fills/steps/location';
|
|
|
|
|
|
|
|
export const StoreLocation: React.FC< {
|
|
|
|
nextStep: () => void;
|
2022-06-30 06:45:52 +00:00
|
|
|
onLocationComplete: () => void;
|
|
|
|
} > = ( { nextStep, onLocationComplete } ) => {
|
2022-06-28 05:53:03 +00:00
|
|
|
const { createNotice } = useDispatch( 'core/notices' );
|
|
|
|
const { updateAndPersistSettingsForGroup } =
|
|
|
|
useDispatch( SETTINGS_STORE_NAME );
|
|
|
|
const { generalSettings, isResolving } = useSelect( ( select ) => {
|
2022-08-08 05:25:46 +00:00
|
|
|
const { getSettings, hasFinishedResolution } =
|
|
|
|
select( SETTINGS_STORE_NAME );
|
2022-06-28 05:53:03 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
generalSettings: getSettings( 'general' )?.general,
|
|
|
|
isResolving: ! hasFinishedResolution( 'getSettings', [
|
|
|
|
'general',
|
|
|
|
] ),
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
useEffect( () => {
|
2022-08-08 05:25:46 +00:00
|
|
|
if ( isResolving || ! hasCompleteAddress( generalSettings || {} ) ) {
|
2022-06-28 05:53:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-30 06:45:52 +00:00
|
|
|
onLocationComplete();
|
|
|
|
}, [ generalSettings, onLocationComplete, isResolving ] );
|
2022-06-28 05:53:03 +00:00
|
|
|
|
|
|
|
if ( isResolving ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StoreLocationForm
|
|
|
|
onComplete={ ( values: { [ key: string ]: string } ) => {
|
|
|
|
const country = getCountryCode( values.countryState );
|
|
|
|
recordEvent( 'tasklist_shipping_recommendation_set_location', {
|
|
|
|
country,
|
|
|
|
} );
|
|
|
|
nextStep();
|
|
|
|
} }
|
|
|
|
isSettingsRequesting={ false }
|
|
|
|
settings={ generalSettings }
|
|
|
|
updateAndPersistSettingsForGroup={
|
|
|
|
updateAndPersistSettingsForGroup
|
|
|
|
}
|
|
|
|
createNotice={ createNotice }
|
|
|
|
isSettingsError={ false }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|