From 306907fb7f8cf81043361f2c32675277f047f067 Mon Sep 17 00:00:00 2001 From: Peterson Paulo <109550332+peterpaulo-azion@users.noreply.github.com> Date: Thu, 13 Feb 2025 15:40:47 -0300 Subject: [PATCH] [UXE-6007] fix: validate account address before adding payment method (#2156) --- src/helpers/account-data.js | 36 +++++++++++++++++++ src/router/hooks/guards/accountGuard.js | 34 ++---------------- src/router/hooks/guards/billingGuard.js | 4 +++ .../add-payment-method-block/index.vue | 35 ++++++++++++++++-- .../AccountSettings/AccountSettingsView.vue | 31 ++++++++++++++-- .../Billing/Drawer/DrawerPaymentMethod.vue | 4 +-- 6 files changed, 106 insertions(+), 38 deletions(-) create mode 100644 src/helpers/account-data.js diff --git a/src/helpers/account-data.js b/src/helpers/account-data.js new file mode 100644 index 000000000..dd49376be --- /dev/null +++ b/src/helpers/account-data.js @@ -0,0 +1,36 @@ +import { getAccountInfoService, getUserInfoService } from '@/services/account-services' +import { loadAccountJobRoleService } from '@/services/account-settings-services' +import { loadContractServicePlan } from '@/services/contract-services' +import { useAccountStore } from '@/stores/account' + +export const loadUserAndAccountInfo = async () => { + const accountStore = useAccountStore() + const [accountInfo, userInfo, accountJobRole] = await Promise.all([ + getAccountInfoService(), + getUserInfoService(), + loadAccountJobRoleService() + ]) + + accountInfo.is_account_owner = userInfo.results.is_account_owner + accountInfo.client_id = userInfo.results.client_id + accountInfo.timezone = userInfo.results.timezone + accountInfo.utc_offset = userInfo.results.utc_offset + accountInfo.first_name = userInfo.results.first_name + accountInfo.last_name = userInfo.results.last_name + accountInfo.permissions = userInfo.results.permissions + accountInfo.email = userInfo.results.email + accountInfo.user_id = userInfo.results.id + accountInfo.colorTheme = accountStore.theme + accountInfo.jobRole = accountJobRole.jobRole + accountInfo.isDeveloperSupportPlan = true + + if (accountInfo.client_id) { + const { isDeveloperSupportPlan, yourServicePlan } = await loadContractServicePlan({ + clientId: accountInfo.client_id + }) + accountInfo.isDeveloperSupportPlan = isDeveloperSupportPlan + accountInfo.yourServicePlan = yourServicePlan + } + + accountStore.setAccountData(accountInfo) +} diff --git a/src/router/hooks/guards/accountGuard.js b/src/router/hooks/guards/accountGuard.js index 3d17dc7db..3d53d51a2 100644 --- a/src/router/hooks/guards/accountGuard.js +++ b/src/router/hooks/guards/accountGuard.js @@ -1,42 +1,14 @@ -import { getAccountInfoService, getUserInfoService } from '@/services/account-services' -import { loadAccountJobRoleService } from '@/services/account-settings-services' import { setRedirectRoute } from '@/helpers' +import { loadUserAndAccountInfo } from '@/helpers/account-data' /** @type {import('vue-router').NavigationGuardWithThis} */ -export async function accountGuard({ to, accountStore, tracker, loadContractServicePlan }) { +export async function accountGuard({ to, accountStore, tracker }) { const isPrivateRoute = !to.meta.isPublic const userNotIsLoggedIn = !accountStore.hasActiveUserId if (userNotIsLoggedIn) { try { - const [accountInfo, userInfo, accountJobRole] = await Promise.all([ - getAccountInfoService(), - getUserInfoService(), - loadAccountJobRoleService() - ]) - - accountInfo.is_account_owner = userInfo.results.is_account_owner - accountInfo.client_id = userInfo.results.client_id - accountInfo.timezone = userInfo.results.timezone - accountInfo.utc_offset = userInfo.results.utc_offset - accountInfo.first_name = userInfo.results.first_name - accountInfo.last_name = userInfo.results.last_name - accountInfo.permissions = userInfo.results.permissions - accountInfo.email = userInfo.results.email - accountInfo.user_id = userInfo.results.id - accountInfo.colorTheme = accountStore.theme - accountInfo.jobRole = accountJobRole.jobRole - accountInfo.isDeveloperSupportPlan = true - - if (accountInfo.client_id) { - const { isDeveloperSupportPlan, yourServicePlan } = await loadContractServicePlan({ - clientId: accountInfo.client_id - }) - accountInfo.isDeveloperSupportPlan = isDeveloperSupportPlan - accountInfo.yourServicePlan = yourServicePlan - } - - accountStore.setAccountData(accountInfo) + await loadUserAndAccountInfo() if (!isPrivateRoute) { return '/' diff --git a/src/router/hooks/guards/billingGuard.js b/src/router/hooks/guards/billingGuard.js index 76981b276..915a89c8b 100644 --- a/src/router/hooks/guards/billingGuard.js +++ b/src/router/hooks/guards/billingGuard.js @@ -21,6 +21,10 @@ export async function billingGuard({ to, accountStore }) { if (to.name === 'billing-tabs') { return true } + + if (to.name === 'account-settings') { + return true + } } else if (paymentReviewPending) { return BILLING_REDIRECT_OPTIONS } diff --git a/src/templates/add-payment-method-block/index.vue b/src/templates/add-payment-method-block/index.vue index eecff7444..a36cdf402 100644 --- a/src/templates/add-payment-method-block/index.vue +++ b/src/templates/add-payment-method-block/index.vue @@ -1,5 +1,6 @@