2021-11-02 17:33:42 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/settings';
|
2022-08-08 05:25:46 +00:00
|
|
|
import { TaskType } from '@woocommerce/data';
|
2021-11-02 17:33:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugins required to automate taxes.
|
|
|
|
*/
|
2023-10-25 14:39:43 +00:00
|
|
|
export const AUTOMATION_PLUGINS = [ 'woocommerce-services' ];
|
2021-11-02 17:33:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a store has a complete address given general settings.
|
|
|
|
*
|
2022-03-18 11:45:14 +00:00
|
|
|
* @param {Object} generalSettings General settings.
|
|
|
|
* @param {Object} generalSettings.woocommerce_store_address Store address.
|
2021-11-05 20:32:02 +00:00
|
|
|
* @param {Object} generalSettings.woocommerce_default_country Store default country.
|
2022-03-18 11:45:14 +00:00
|
|
|
* @param {Object} generalSettings.woocommerce_store_postcode Store postal code.
|
2021-11-02 17:33:42 +00:00
|
|
|
*/
|
2022-08-08 05:25:46 +00:00
|
|
|
export const hasCompleteAddress = (
|
|
|
|
generalSettings: Record< string, string >
|
|
|
|
): boolean => {
|
2021-11-02 17:33:42 +00:00
|
|
|
const {
|
|
|
|
woocommerce_store_address: storeAddress,
|
|
|
|
woocommerce_default_country: defaultCountry,
|
|
|
|
woocommerce_store_postcode: storePostCode,
|
|
|
|
} = generalSettings;
|
|
|
|
return Boolean( storeAddress && defaultCountry && storePostCode );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect to the core tax settings screen.
|
|
|
|
*/
|
|
|
|
export const redirectToTaxSettings = (): void => {
|
|
|
|
window.location.href = getAdminLink(
|
|
|
|
'admin.php?page=wc-settings&tab=tax§ion=standard&wc_onboarding_active_task=tax'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-11-05 20:32:02 +00:00
|
|
|
/**
|
|
|
|
* Types for child tax components.
|
|
|
|
*/
|
|
|
|
export type TaxChildProps = {
|
|
|
|
isPending: boolean;
|
|
|
|
onAutomate: () => void;
|
|
|
|
onManual: () => void;
|
|
|
|
onDisable: () => void;
|
2022-04-21 05:10:56 +00:00
|
|
|
task: TaskType;
|
2021-11-05 20:32:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a given country is supported by Avalara.
|
|
|
|
*
|
|
|
|
* @param {string} countryCode Country code.
|
|
|
|
* @return {boolean} If the country is supported.
|
|
|
|
*/
|
|
|
|
export const supportsAvalara = ( countryCode: string ): boolean => {
|
|
|
|
const countries = [
|
|
|
|
'AF',
|
|
|
|
'AL',
|
|
|
|
'DZ',
|
|
|
|
'AD',
|
|
|
|
'AO',
|
|
|
|
'AI',
|
|
|
|
'AG',
|
|
|
|
'AR',
|
|
|
|
'AM',
|
|
|
|
'AW',
|
|
|
|
'AU',
|
|
|
|
'AT',
|
|
|
|
'AZ',
|
|
|
|
'BS',
|
|
|
|
'BH',
|
|
|
|
'BD',
|
|
|
|
'BB',
|
|
|
|
'BY',
|
|
|
|
'BE',
|
|
|
|
'BZ',
|
|
|
|
'BJ',
|
|
|
|
'BM',
|
|
|
|
'BO',
|
|
|
|
'BA',
|
|
|
|
'BW',
|
|
|
|
'BR',
|
|
|
|
'BN',
|
|
|
|
'BG',
|
|
|
|
'BF',
|
|
|
|
'BI',
|
|
|
|
'KH',
|
|
|
|
'CM',
|
|
|
|
'CA',
|
|
|
|
'IC',
|
|
|
|
'CV',
|
|
|
|
'KY',
|
|
|
|
'CF',
|
|
|
|
'TD',
|
|
|
|
'CL',
|
|
|
|
'CN',
|
|
|
|
'CC',
|
|
|
|
'CO',
|
|
|
|
'KM',
|
|
|
|
'CD',
|
|
|
|
'CK',
|
|
|
|
'CR',
|
|
|
|
'CI',
|
|
|
|
'HR',
|
|
|
|
'CU',
|
|
|
|
'CW',
|
|
|
|
'CY',
|
|
|
|
'CZ',
|
|
|
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