Skip to content

Commit

Permalink
feat: [M3-7919] Add Fonoa tax id event notification on invalidation (l…
Browse files Browse the repository at this point in the history
…inode#10512)

Co-authored-by: Jaalah Ramos <[email protected]>
Co-authored-by: Alban Bailly <[email protected]>
  • Loading branch information
3 people authored Jun 6, 2024
1 parent 7124a92 commit d4139ad
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 53 deletions.
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-10512-added-1717103206247.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Added
---

New event `tax_id_invalid` for account tax id ([#10512](https://github.com/linode/manager/pull/10512))
21 changes: 11 additions & 10 deletions packages/api-v4/src/account/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ export const EventActionKeys = [
'database_delete',
'database_failed',
'database_low_disk_space',
'database_resize',
'database_resize_create',
'database_resize',
'database_scale',
'database_update',
'database_update_failed',
'database_update',
'database_upgrade',
'disk_create',
'disk_delete',
Expand All @@ -324,8 +324,8 @@ export const EventActionKeys = [
'domain_record_update',
'domain_record_updated',
'domain_update',
'entity_transfer_accept',
'entity_transfer_accept_recipient',
'entity_transfer_accept',
'entity_transfer_cancel',
'entity_transfer_create',
'entity_transfer_fail',
Expand Down Expand Up @@ -356,29 +356,29 @@ export const EventActionKeys = [
'linode_create',
'linode_delete',
'linode_deleteip',
'linode_migrate_datacenter_create',
'linode_migrate_datacenter',
'linode_migrate',
'linode_mutate_create',
'linode_mutate',
'linode_migrate_datacenter',
'linode_migrate_datacenter_create',
'linode_reboot',
'linode_rebuild',
'linode_resize',
'linode_resize_create',
'linode_resize_warm_create',
'linode_resize',
'linode_shutdown',
'linode_snapshot',
'linode_update',
'lish_boot',
'lke_cluster_create',
'lke_cluster_delete',
'lke_cluster_recycle',
'lke_cluster_update',
'lke_kubeconfig_regenerate',
'lke_cluster_regenerate',
'lke_cluster_update',
'lke_control_plane_acl_create',
'lke_control_plane_acl_delete',
'lke_control_plane_acl_update',
'lke_kubeconfig_regenerate',
'lke_node_create',
'lke_node_recycle',
'lke_pool_create',
Expand All @@ -402,8 +402,8 @@ export const EventActionKeys = [
'nodebalancer_update',
'oauth_client_create',
'oauth_client_delete',
'oauth_client_update',
'oauth_client_secret_reset',
'oauth_client_update',
'obj_access_key_create',
'obj_access_key_delete',
'obj_access_key_update',
Expand Down Expand Up @@ -432,6 +432,7 @@ export const EventActionKeys = [
'subnet_update',
'tag_create',
'tag_delete',
'tax_id_invalid',
'tfa_disabled',
'tfa_enabled',
'ticket_attachment_upload',
Expand All @@ -451,8 +452,8 @@ export const EventActionKeys = [
'volume_create',
'volume_delete',
'volume_detach',
'volume_migrate',
'volume_migrate_scheduled',
'volume_migrate',
'volume_resize',
'volume_update',
'vpc_create',
Expand Down
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10512-added-1716563502479.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Added
---

New tax id validation for non-US countries ([#10512](https://github.com/linode/manager/pull/10512))
18 changes: 18 additions & 0 deletions packages/manager/cypress/e2e/core/billing/billing-contact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { mockGetAccount, mockUpdateAccount } from 'support/intercepts/account';
import { accountFactory } from 'src/factories/account';
import type { Account } from '@linode/api-v4';
import { ui } from 'support/ui';
import { makeFeatureFlagData } from 'support/util/feature-flags';
import { TAX_ID_HELPER_TEXT } from 'src/features/Billing/constants';
import {
mockAppendFeatureFlags,
mockGetFeatureFlagClientstream,
} from 'support/intercepts/feature-flags';
import type { Flags } from 'src/featureFlags';

/* eslint-disable sonarjs/no-duplicate-string */
const accountData = accountFactory.build({
Expand Down Expand Up @@ -63,6 +70,14 @@ const checkAccountContactDisplay = (accountInfo: Account) => {
};

describe('Billing Contact', () => {
beforeEach(() => {
mockAppendFeatureFlags({
taxId: makeFeatureFlagData<Flags['taxId']>({
enabled: true,
}),
});
mockGetFeatureFlagClientstream();
});
it('Edit Contact Info', () => {
// mock the user's account data and confirm that it is displayed correctly upon page load
mockGetAccount(accountData).as('getAccount');
Expand Down Expand Up @@ -124,6 +139,8 @@ describe('Billing Contact', () => {
.click()
.clear()
.type(newAccountData['phone']);
cy.get('[data-qa-contact-country]').click().type('Afghanistan{enter}');
cy.findByText(TAX_ID_HELPER_TEXT).should('be.visible');
cy.get('[data-qa-contact-country]')
.click()
.type('United States{enter}');
Expand All @@ -136,6 +153,7 @@ describe('Billing Contact', () => {
.click()
.clear()
.type(newAccountData['tax_id']);
cy.findByText(TAX_ID_HELPER_TEXT).should('not.exist');
cy.get('[data-qa-save-contact-info="true"]')
.click()
.then(() => {
Expand Down
15 changes: 9 additions & 6 deletions packages/manager/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ interface TaxCollectionBanner {
regions?: TaxCollectionRegion[];
}

interface PlacementGroupsFlag {
beta: boolean;
interface BaseFeatureFlag {
enabled: boolean;
}

interface GeckoFlag {
enabled: boolean;
interface BetaFeatureFlag extends BaseFeatureFlag {
beta: boolean;
}

interface GaFeatureFlag extends BaseFeatureFlag {
ga: boolean;
}

Expand All @@ -69,7 +71,7 @@ export interface Flags {
disableLargestGbPlans: boolean;
eventMessagesV2: boolean;
gecko: boolean; // @TODO gecko: delete this after next release
gecko2: GeckoFlag;
gecko2: GaFeatureFlag;
gpuv2: gpuV2;
ipv6Sharing: boolean;
linodeCreateRefactor: boolean;
Expand All @@ -80,7 +82,7 @@ export interface Flags {
objMultiCluster: boolean;
oneClickApps: OneClickApp;
oneClickAppsDocsOverride: Record<string, Doc[]>;
placementGroups: PlacementGroupsFlag;
placementGroups: BetaFeatureFlag;
productInformationBanners: ProductInformationBannerFlag[];
promos: boolean;
promotionalOffers: PromotionalOffer[];
Expand All @@ -90,6 +92,7 @@ export interface Flags {
supportTicketSeverity: boolean;
taxBanner: TaxBanner;
taxCollectionBanner: TaxCollectionBanner;
taxId: BaseFeatureFlag;
taxes: Taxes;
tpaProviders: Provider[];
}
Expand Down
22 changes: 22 additions & 0 deletions packages/manager/src/features/Account/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useFlags } from 'src/hooks/useFlags';

import { ADMINISTRATOR, PARENT_USER } from './constants';

import type { GlobalGrantTypes, GrantLevel } from '@linode/api-v4';
Expand Down Expand Up @@ -63,3 +65,23 @@ export const getRestrictedResourceText = ({

return message;
};

/**
* Hook to determine if the Tax Id feature should be visible to the user.
* Based on the user's account capability and the feature flag.
*
* @returns {boolean} - Whether the TaxId feature is enabled for the current user.
*/
export const useIsTaxIdEnabled = (): {
isTaxIdEnabled: boolean;
} => {
const flags = useFlags();

if (!flags) {
return { isTaxIdEnabled: false };
}

const isTaxIdEnabled = Boolean(flags.taxId?.enabled);

return { isTaxIdEnabled };
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { ActionsPanel } from 'src/components/ActionsPanel/ActionsPanel';
import EnhancedSelect, { Item } from 'src/components/EnhancedSelect/Select';
import { Notice } from 'src/components/Notice/Notice';
import { TextField } from 'src/components/TextField';
import { getRestrictedResourceText } from 'src/features/Account/utils';
import {
getRestrictedResourceText,
useIsTaxIdEnabled,
} from 'src/features/Account/utils';
import { TAX_ID_HELPER_TEXT } from 'src/features/Billing/constants';
import { useRestrictedGlobalGrantCheck } from 'src/hooks/useRestrictedGlobalGrantCheck';
import { useAccount, useMutateAccount } from 'src/queries/account/account';
import { useNotificationsQuery } from 'src/queries/account/notifications';
Expand All @@ -29,6 +33,7 @@ const UpdateContactInformationForm = ({ focusEmail, onClose }: Props) => {
const { classes } = useStyles();
const emailRef = React.useRef<HTMLInputElement>();
const { data: profile } = useProfile();
const { isTaxIdEnabled } = useIsTaxIdEnabled();
const isChildUser = profile?.user_type === 'child';
const isParentUser = profile?.user_type === 'parent';
const isReadOnly =
Expand Down Expand Up @@ -166,6 +171,11 @@ const UpdateContactInformationForm = ({ focusEmail, onClose }: Props) => {
formik.setFieldValue('company', '');
}

const handleCountryChange = (item: Item<string>) => {
formik.setFieldValue('country', item.value);
formik.setFieldValue('tax_id', '');
};

return (
<form onSubmit={formik.handleSubmit}>
<Grid
Expand Down Expand Up @@ -277,7 +287,7 @@ const UpdateContactInformationForm = ({ focusEmail, onClose }: Props) => {
errorText={errorMap.country}
isClearable={false}
label="Country"
onChange={(item) => formik.setFieldValue('country', item.value)}
onChange={(item) => handleCountryChange(item)}
options={countryResults}
placeholder="Select a Country"
required
Expand Down Expand Up @@ -359,6 +369,11 @@ const UpdateContactInformationForm = ({ focusEmail, onClose }: Props) => {
</Grid>
<Grid xs={12}>
<TextField
helperText={
isTaxIdEnabled &&
formik.values.country !== 'US' &&
TAX_ID_HELPER_TEXT
}
data-qa-contact-tax-id
disabled={isReadOnly}
errorText={errorMap.tax_id}
Expand Down
2 changes: 2 additions & 0 deletions packages/manager/src/features/Billing/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const ADD_PAYMENT_METHOD = 'Add Payment Method';
export const EDIT_BILLING_CONTACT = 'Edit';
export const TAX_ID_HELPER_TEXT =
'Tax Identification Numbers (TIN) are set by the national authorities and they have different names in different countries. Enter a TIN valid for the country of your billing address. It will be validated.';
9 changes: 5 additions & 4 deletions packages/manager/src/features/Events/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export const EVENT_ACTIONS: Event['action'][] = [
'database_create',
'database_credentials_reset',
'database_delete',
'database_resize_create',
'database_resize',
'database_update_failed',
'database_update',
'database_resize',
'database_resize_create',
'disk_create',
'disk_delete',
'disk_duplicate',
Expand Down Expand Up @@ -82,12 +82,12 @@ export const EVENT_ACTIONS: Event['action'][] = [
'nodebalancer_update',
'password_reset',
'placement_group_assign',
'placement_group_became_non_compliant',
'placement_group_became_compliant',
'placement_group_became_non_compliant',
'placement_group_create',
'placement_group_delete',
'placement_group_unassign',
'placement_group_update',
'placement_group_delete',
'profile_update',
'stackscript_create',
'stackscript_delete',
Expand All @@ -97,6 +97,7 @@ export const EVENT_ACTIONS: Event['action'][] = [
'subnet_create',
'subnet_delete',
'subnet_update',
'tax_id_invalid',
'tfa_disabled',
'tfa_enabled',
'ticket_attachment_upload',
Expand Down
Loading

0 comments on commit d4139ad

Please sign in to comment.