From 1e1c51164d60b216010943daad16679394b45aa5 Mon Sep 17 00:00:00 2001 From: Nirbhay Date: Mon, 9 Dec 2024 17:00:05 +0530 Subject: [PATCH 1/3] update: account menu buttons --- modules/settings/assets/js/api/index.js | 9 +++++++++ .../assets/js/components/my-account-menu/index.js | 15 ++++++++++++--- modules/settings/assets/js/constants/index.js | 1 + modules/settings/module.php | 4 ++-- package-lock.json | 9 +++++---- package.json | 2 +- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/modules/settings/assets/js/api/index.js b/modules/settings/assets/js/api/index.js index 79f675b..ec0d785 100644 --- a/modules/settings/assets/js/api/index.js +++ b/modules/settings/assets/js/api/index.js @@ -127,6 +127,15 @@ class API { path: `${v1Prefix}/settings/get-settings`, }); } + + /** + * Go to connect service + * @return {Promise} redirect + */ + static async redirectToConnect() { + const link = await this.initConnect(); + window.open(link, '_self').focus(); + } } export default API; diff --git a/modules/settings/assets/js/components/my-account-menu/index.js b/modules/settings/assets/js/components/my-account-menu/index.js index 0995398..09f9f90 100644 --- a/modules/settings/assets/js/components/my-account-menu/index.js +++ b/modules/settings/assets/js/components/my-account-menu/index.js @@ -1,4 +1,4 @@ -import { ChevronDownIcon, UserIcon } from '@elementor/icons'; +import { ChevronDownIcon, UserIcon, ExternalLinkIcon } from '@elementor/icons'; import Avatar from '@elementor/ui/Avatar'; import Box from '@elementor/ui/Box'; import List from '@elementor/ui/List'; @@ -16,6 +16,8 @@ import { import { useSettings } from '@ea11y/hooks'; import { CreditCardIcon, UserArrowIcon } from '@ea11y/icons'; import { __ } from '@wordpress/i18n'; +import API from '../../api'; +import { BILLING_LINK } from '../../constants'; const MyAccountMenu = () => { const { openSidebar } = useSettings(); @@ -23,6 +25,9 @@ const MyAccountMenu = () => { variant: 'popover', popupId: 'myAccountMenu', }); + const onDeactivateAndDisconnect = () => { + API.disconnect().then(() => API.redirectToConnect()); + }; return ( <> @@ -72,17 +77,21 @@ const MyAccountMenu = () => { - + {__('Switch account', 'pojo-accessibility')} - + {__('Billing', 'pojo-accessibility')} + diff --git a/modules/settings/assets/js/constants/index.js b/modules/settings/assets/js/constants/index.js index c4169b4..3df3179 100644 --- a/modules/settings/assets/js/constants/index.js +++ b/modules/settings/assets/js/constants/index.js @@ -1,2 +1,3 @@ export const HELP_LINK = 'https://go.elementor.com/'; export const UPGRADE_LINK = 'https://go.elementor.com/'; +export const BILLING_LINK = 'https://my.elementor.com/'; diff --git a/modules/settings/module.php b/modules/settings/module.php index 588c004..c3b63c0 100644 --- a/modules/settings/module.php +++ b/modules/settings/module.php @@ -12,8 +12,8 @@ } class Module extends Module_Base { - const SETTING_PREFIX = 'a11y_'; - const SETTING_GROUP = 'a11y_settings'; + const SETTING_PREFIX = 'ea11y_'; + const SETTING_GROUP = 'ea11y_settings'; const SETTING_BASE_SLUG = 'accessibility-settings-2'; //TODO: Change this later const SETTING_CAPABILITY = 'manage_options'; diff --git a/package-lock.json b/package-lock.json index 70900e4..285cff0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "pojo-accessibility", "version": "2.1.0", "dependencies": { - "@elementor/icons": "^1.17.0", + "@elementor/icons": "^1.20.0", "@elementor/ui": "^1.21.2", "@wordpress/api-fetch": "^7.10.0", "@wordpress/core-data": "^7.10.0", @@ -2069,9 +2069,10 @@ } }, "node_modules/@elementor/icons": { - "version": "1.18.1", - "resolved": "https://registry.npmjs.org/@elementor/icons/-/icons-1.18.1.tgz", - "integrity": "sha512-/69Adp/Q0ebKQOnNKekzX3ym7CQNotBq4JXO+pqtUXbqwbL0O7k56aR81yZSVns1TMOip5+Qxbgxemth0k0FlQ==", + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@elementor/icons/-/icons-1.20.0.tgz", + "integrity": "sha512-1UgAIDO8qY7R7OjTZ+9cIMqgYtD7LAjIqVJiGmnkJMeb7sM65UebHvZiVVSZX7+jqJ1vuoLH+lmvAZlm8eqoGQ==", + "license": "GPL-3.0-or-later", "peerDependencies": { "@elementor/ui": "^1.4.61", "react": "^17.0.0 || ^18.0.0" diff --git a/package.json b/package.json index 23eb061..7604992 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "prettier": "^3.4.1" }, "dependencies": { - "@elementor/icons": "^1.17.0", + "@elementor/icons": "^1.20.0", "@elementor/ui": "^1.21.2", "@wordpress/api-fetch": "^7.10.0", "@wordpress/core-data": "^7.10.0", From dc1f5a507d8b4271c382e1cef55c07bece8a3537 Mon Sep 17 00:00:00 2001 From: Nirbhay Date: Mon, 9 Dec 2024 18:10:15 +0530 Subject: [PATCH 2/3] update: billing link --- .../settings/assets/js/components/my-account-menu/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/settings/assets/js/components/my-account-menu/index.js b/modules/settings/assets/js/components/my-account-menu/index.js index 09f9f90..9ff7039 100644 --- a/modules/settings/assets/js/components/my-account-menu/index.js +++ b/modules/settings/assets/js/components/my-account-menu/index.js @@ -28,6 +28,10 @@ const MyAccountMenu = () => { const onDeactivateAndDisconnect = () => { API.disconnect().then(() => API.redirectToConnect()); }; + + const redirectToBilling = () => { + window.open(BILLING_LINK, '_blank').focus(); + }; return ( <> @@ -83,7 +87,7 @@ const MyAccountMenu = () => { {__('Switch account', 'pojo-accessibility')} - + {__('Billing', 'pojo-accessibility')} From 5f4ccbb33a251ed7df59eac5015c3cd598353559 Mon Sep 17 00:00:00 2001 From: Nirbhay Date: Tue, 10 Dec 2024 11:27:49 +0530 Subject: [PATCH 3/3] add: error handling for switch account --- .../assets/js/components/my-account-menu/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/settings/assets/js/components/my-account-menu/index.js b/modules/settings/assets/js/components/my-account-menu/index.js index 9ff7039..4a2a814 100644 --- a/modules/settings/assets/js/components/my-account-menu/index.js +++ b/modules/settings/assets/js/components/my-account-menu/index.js @@ -13,7 +13,7 @@ import { bindTrigger, usePopupState, } from '@elementor/ui/usePopupState'; -import { useSettings } from '@ea11y/hooks'; +import { useSettings, useToastNotification } from '@ea11y/hooks'; import { CreditCardIcon, UserArrowIcon } from '@ea11y/icons'; import { __ } from '@wordpress/i18n'; import API from '../../api'; @@ -21,12 +21,21 @@ import { BILLING_LINK } from '../../constants'; const MyAccountMenu = () => { const { openSidebar } = useSettings(); + const { error } = useToastNotification(); const accountMenuState = usePopupState({ variant: 'popover', popupId: 'myAccountMenu', }); - const onDeactivateAndDisconnect = () => { - API.disconnect().then(() => API.redirectToConnect()); + const onDeactivateAndDisconnect = async () => { + try { + await API.disconnect(); + await API.redirectToConnect(); + } catch (e) { + error( + __('Failed to switch account. Please try again.', 'pojo-accessibility'), + ); + console.error(e); + } }; const redirectToBilling = () => {