woocommerce/plugins/woocommerce-admin/client/tasks/fills/tax/components/store-location.tsx

64 lines
1.6 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
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
*/
import { getCountryCode } from '~/dashboard/utils';
import { hasCompleteAddress } from '../utils';
import { default as StoreLocationForm } from '~/tasks/fills/steps/location';
export const StoreLocation: React.FC< {
nextStep: () => void;
} > = ( { nextStep } ) => {
2022-04-21 04:44:19 +00:00
const { createNotice } = useDispatch( 'core/notices' );
const { updateAndPersistSettingsForGroup } =
useDispatch( SETTINGS_STORE_NAME );
const { generalSettings, isResolving } = useSelect( ( select ) => {
const { getSettings, hasFinishedResolution } =
select( SETTINGS_STORE_NAME );
return {
generalSettings: getSettings( 'general' )?.general,
isResolving: ! hasFinishedResolution( 'getSettings', [
'general',
] ),
};
} );
useEffect( () => {
if ( isResolving || ! hasCompleteAddress( generalSettings || {} ) ) {
return;
}
nextStep();
}, [ isResolving ] );
if ( isResolving ) {
return null;
}
return (
<StoreLocationForm
2022-04-21 04:44:19 +00:00
onComplete={ ( values: { [ key: string ]: string } ) => {
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 }
/>
);
};