woocommerce/plugins/woocommerce-admin/client/task-lists/fills/tax/utils.ts

287 lines
3.5 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { getAdminLink } from '@woocommerce/settings';
import { TaskType } from '@woocommerce/data';
/**
* Plugins required to automate taxes.
*/
Remove dependency on Jetpack from Shipping and Tax task list items (#39992) * Remove dependency on Jetpack from WCS&T's task list item - Remove installing Jetpack-the-plugin from WooCommerce Shipping & Tax WC Home task list and recommended extensions area. - Update Jetpack auth link generation to use getJetpackAuthUrl(). - Remove references of Jetpack-the-plugin from WCS&T onboarding as the extension will now use the Jetpack Connection package for establishing a connection between WPCOM infrastructure and a Woo site. * Update WooCommerce Tax flow in WC Home task list * Inline the agreementText variable * Add missing pluginSlugs prop to <Plugins> instance for WC Tax * Fix WC Tax extension name in API response * Remove Jetpack from copy in Tax task header * Fix MD034/no-bare-urls MD linting violation * Fix experimental shipping recommendation tests * Add changelogs requested by linter * Add changefile(s) from automation for the following project(s): @woocommerce/components, woocommerce * Remove mention of Jetpack from ExperimentalShippingRecommendation * Fix text wrapping bug in WC Tax onboarding task * Add changefile(s) from automation for the following project(s): @woocommerce/components, woocommerce * Use isResolving() to detect pending auth URL fetch * Replace unused hasErrors with ref to error * Fix lint * Jetpack auth URL prefetching * Revert "Jetpack auth URL prefetching" This reverts commit 2b79000e203f99ae5ceb8c4a3e6a1d1d6fbe4dc8. * Add PrefetchJetpackAuthUrl component to remove Connect button load time * Replace URL prefetching in component with useEffect * Fix: Accept redirect URL as param instead of prop * Fix lint * Remove prefetching. Make Connect button always available * Fix ExperimentalShippingRecommendation incompatibility with new Connect behavior * Handle empty object errors in Connect * Display TOS above WooCommerce Shipping & Tax installation buttons (#40863) --------- Co-authored-by: github-actions <github-actions@github.com>
2023-10-25 14:39:43 +00:00
export const AUTOMATION_PLUGINS = [ 'woocommerce-services' ];
/**
* Check if a store has a complete address given general settings.
*
* @param {Object} generalSettings General settings.
* @param {Object} generalSettings.woocommerce_store_address Store address.
* @param {Object} generalSettings.woocommerce_default_country Store default country.
* @param {Object} generalSettings.woocommerce_store_postcode Store postal code.
*/
export const hasCompleteAddress = (
generalSettings: Record< string, string >,
requiresPostcode = true
): boolean => {
const {
woocommerce_store_address: storeAddress,
woocommerce_default_country: defaultCountry,
woocommerce_store_postcode: storePostCode,
} = generalSettings;
if ( requiresPostcode ) {
return Boolean( storeAddress && defaultCountry && storePostCode );
}
return Boolean( storeAddress && defaultCountry );
};
/**
* Redirect to the core tax settings screen.
*/
export const redirectToTaxSettings = (): void => {
window.location.href = getAdminLink(
'admin.php?page=wc-settings&tab=tax&section=standard&wc_onboarding_active_task=tax'
);
};
/**
* 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;
};
/**
* 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',
'DK',
'DJ',
'DM',
'DO',
'EC',
'EG',
'SV',
'GQ',
'ER',
'EE',
'ET',
'FK',
'FO',
'FJ',
'FI',
'FR',
'PF',
'TF',
'GA',
'GM',
'GE',
'DE',
'GH',
'GI',
'GR',
'GL',
'GD',
'GP',
'GT',
'GG',
'GN',
'GW',
'GY',
'HT',
'HN',
'HK',
'HU',
'IS',
'IN',
'ID',
'IR',
'IQ',
'IE',
'IL',
'IT',
'JM',
'JP',
'JE',
'JO',
'KZ',
'KE',
'KI',
'KP',
'KV',
'KW',
'KG',
'LA',
'LV',
'LB',
'LS',
'LR',
'LY',
'LI',
'LT',
'LU',
'MO',
'MK',
'MG',
'MW',
'MY',
'MV',
'ML',
'MT',
'MQ',
'MR',
'MU',
'MX',
'MD',
'MC',
'MN',
'ME',
'MS',
'MA',
'MZ',
'MM',
'NA',
'NR',
'NP',
'NL',
'NZ',
'NI',
'NE',
'NG',
'NU',
'NF',
'NO',
'OM',
'PK',
'PS',
'PA',
'PG',
'PY',
'PE',
'PH',
'PL',
'PT',
'QA',
'KR',
'RE',
'RO',
'RU',
'RW',
'SH',
'KN',
'LC',
'MF',
'VC',
'WS',
'SM',
'ST',
'SA',
'SN',
'RS',
'SC',
'SL',
'SG',
'SX',
'SK',
'SI',
'SB',
'SO',
'ZA',
'SD',
'ES',
'LK',
'SD',
'SR',
'SZ',
'SE',
'CH',
'SY',
'TW',
'TJ',
'TZ',
'TH',
'TL',
'TG',
'TO',
'TT',
'TN',
'TR',
'TM',
'TC',
'TV',
'UG',
'UA',
'AE',
'GB',
'US',
'UY',
'UZ',
'VU',
'VE',
'VN',
'VG',
'YE',
'ZM',
'ZW',
];
return countries.includes( countryCode );
};