2021-11-02 17:33:42 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2022-04-21 04:44:19 +00:00
|
|
|
import { SETTINGS_STORE_NAME, WCDataSelector } 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-04-21 04:44:19 +00:00
|
|
|
import { hasCompleteAddress, SettingsSelector } 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' );
|
2021-11-02 17:33:42 +00:00
|
|
|
const { updateAndPersistSettingsForGroup } = useDispatch(
|
|
|
|
SETTINGS_STORE_NAME
|
|
|
|
);
|
2022-04-21 04:44:19 +00:00
|
|
|
const { generalSettings, isResolving } = useSelect(
|
|
|
|
( select: WCDataSelector ) => {
|
|
|
|
const { getSettings, hasFinishedResolution } = select(
|
|
|
|
SETTINGS_STORE_NAME
|
|
|
|
) as SettingsSelector;
|
2021-11-02 17:33:42 +00:00
|
|
|
|
2022-04-21 04:44:19 +00:00
|
|
|
return {
|
|
|
|
generalSettings: getSettings( 'general' )?.general,
|
|
|
|
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
|
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
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|