Skip to content

Commit

Permalink
fix(account): redirect to account in sidebars (#14352)
Browse files Browse the repository at this point in the history
ref: MANAGER-16130
Signed-off-by: Maxime Bajeux <[email protected]>
  • Loading branch information
MaximeBajeux authored Dec 4, 2024
1 parent 5a5ee1d commit cd63256
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import constants from '../../account-sidebar/UsefulLinks/constants';

const kycIndiaFeature = 'identity-documents';
const kycFraudFeature = 'procedures:fraud';
const kycFeatures = [kycIndiaFeature, kycFraudFeature]
const newAccount = 'new-account';
const accountFeatures = [kycIndiaFeature, kycFraudFeature, newAccount];

export default function AccountSidebar() {
const [menu, setMenu] = useState<SidebarMenuItem>(undefined);
Expand All @@ -38,6 +39,7 @@ export default function AccountSidebar() {
}

const isEUOrCA = ['EU', 'CA'].includes(region);
const isNewAccountAvailable = !!availability['new-account'];

menu.push({
id: 'back-to-home',
Expand All @@ -48,7 +50,7 @@ export default function AccountSidebar() {
menu.push({
id: 'my-account',
label: t('sidebar_account'),
href: navigation.getURL('dedicated', '/useraccount/dashboard'),
href: navigation.getURL(isNewAccountAvailable ? 'new-account' : 'dedicated', '/useraccount/dashboard'),
routeMatcher: new RegExp('^/useraccount'),
});

Expand All @@ -58,7 +60,7 @@ export default function AccountSidebar() {
menu.push({
id: 'my-identity-documents',
label: t('sidebar_account_identity_documents'),
href: navigation.getURL('dedicated', '/identity-documents'),
href: navigation.getURL(isNewAccountAvailable ? 'new-account' : 'dedicated', '/identity-documents'),
routeMatcher: new RegExp('^/identity-documents'),
});
}
Expand All @@ -70,7 +72,7 @@ export default function AccountSidebar() {
menu.push({
id: 'kyc-documents',
label: t('sidebar_account_kyc_documents'),
href: navigation.getURL('dedicated', '/documents'),
href: navigation.getURL(isNewAccountAvailable ? 'new-account' : 'dedicated', '/documents'),
routeMatcher: new RegExp('^/documents'),
});
}
Expand Down Expand Up @@ -119,7 +121,7 @@ export default function AccountSidebar() {
menu.push({
id: 'my-contacts',
label: t('sidebar_account_contacts'),
href: navigation.getURL('dedicated', '/contacts'),
href: navigation.getURL(isNewAccountAvailable ? 'new-account' : 'dedicated', '/contacts'),
routeMatcher: new RegExp('^/contacts'),
});
}
Expand Down Expand Up @@ -152,7 +154,7 @@ export default function AccountSidebar() {
return menu;
};

const {data: availability} = useFeatureAvailability(features.concat(kycFeatures));
const {data: availability} = useFeatureAvailability(features.concat(accountFeatures));

const buildMenu = async () =>
Promise.resolve({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const UserAccountMenu = ({
const [isKycDocumentsVisible, setIsDocumentsVisible] = useState<boolean>(
false,
);

const [isNewAccountAvailable, setIsNewAccountAvailable] = useState<boolean>(false);
const user = shell
.getPlugin('environment')
.getEnvironment()
Expand Down Expand Up @@ -70,12 +70,12 @@ const UserAccountMenu = ({
const getUrl = (key: string, hash: string) =>
shell.getPlugin('navigation').getURL(key, hash);
const ssoLink = getUrl('iam', '#/dashboard/users');
const supportLink = getUrl('dedicated', '#/useraccount/support/level');
let [supportLink, setSupportLink] = useState(getUrl('dedicated', '#/useraccount/support/level'));

const getAllLinks = useMemo(
() => async () => {
let isIdentityDocumentsAvailable = false;
const featureAvailability = await fetchFeatureAvailabilityData(['identity-documents', 'procedures:fraud']);
const featureAvailability = await fetchFeatureAvailabilityData(['new-account', 'identity-documents', 'procedures:fraud']);
if (featureAvailability['identity-documents']) {
const { status } = await reketInstance.get(`/me/procedure/identity`);
isIdentityDocumentsAvailable = ['required', 'open'].includes(status);
Expand All @@ -85,11 +85,23 @@ const UserAccountMenu = ({
setIsDocumentsVisible(['required', 'open'].includes(status));
}

setIsNewAccountAvailable(!!featureAvailability['new-account'])

if (isNewAccountAvailable) {
setSupportLink(getUrl('new-account', '#/useraccount/support/level'));
}

setAllLinks([
...links,
...links.map((link: UserLink) => {
if (['user-account-menu-profile', 'myCommunications', 'myContacts'].includes(link.key)) {
link.app = isNewAccountAvailable ? 'new-account' : 'dedicated';
}
return link;
}),
...(isIdentityDocumentsAvailable
? [
{
app: isNewAccountAvailable ? 'new-account' : 'dedicated',
key: 'myIdentityDocuments',
hash: '#/identity-documents',
i18nKey: 'user_account_menu_my_identity_documents',
Expand All @@ -99,6 +111,7 @@ const UserAccountMenu = ({
...(region === 'US'
? [
{
app: isNewAccountAvailable ? 'new-account' : 'dedicated',
key: 'myAssistanceTickets',
hash: '#/ticket',
i18nKey: 'user_account_menu_my_assistance_tickets',
Expand Down Expand Up @@ -186,7 +199,7 @@ const UserAccountMenu = ({
</div>
<div className="border-bottom pb-2 pt-2">
{allLinks.map((link: UserLink) => {
const { key, hash, i18nKey } = link;
const { app, key, hash, i18nKey } = link;
return (
<a
key={key}
Expand All @@ -195,7 +208,7 @@ const UserAccountMenu = ({
className="d-block"
aria-label={t(i18nKey)}
title={t(i18nKey)}
href={getUrl('dedicated', hash)}
href={getUrl(app, hash)}
target="_top"
>
{t(i18nKey)}
Expand All @@ -208,6 +221,7 @@ const UserAccountMenu = ({
id={'account_kyc_documents'}
onClick={() => onLinkClick(
{
app: isNewAccountAvailable ? 'new-account': 'dedicated',
key: 'account_kyc_documents',
hash: '#/documents',
i18nKey: 'sidebar_account_kyc_documents'
Expand All @@ -216,7 +230,7 @@ const UserAccountMenu = ({
className="d-block"
aria-label={sidebarTranslation.t('sidebar_account_kyc_documents')}
title={sidebarTranslation.t('sidebar_account_kyc_documents')}
href={getUrl('dedicated', '#/documents')}
href={getUrl(isNewAccountAvailable ? 'new-account': 'dedicated', '#/documents')}
target="_top"
>
{sidebarTranslation.t('sidebar_account_kyc_documents')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type UserLink = {
app: string;
key: string;
hash: string;
i18nKey: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,50 @@ export const tracking = {

export const links: UserLink[] = [
{
app: 'dedicated',
key: 'user-account-menu-profile',
hash: '#/useraccount/dashboard',
i18nKey: 'user_account_menu_profile',
trackingHit: tracking.goToProfile,
},
{
app: 'dedicated',
key: 'myInvoices',
hash: '#/billing/history',
i18nKey: 'user_account_menu_my_invoices',
trackingHit: tracking.billingBills,
},
{
app: 'dedicated',
key: 'myServices',
hash: '#/billing/autorenew',
i18nKey: 'user_account_menu_my_services',
trackingHit: tracking.myServices
},
{
app: 'dedicated',
key: 'myCommunications',
hash: '#/useraccount/emails',
i18nKey: 'user_account_menu_my_communication',
trackingHit: tracking.accountContacts,
},
{
app: 'dedicated',
key: 'myPaymentMethods',
hash: '#/billing/payment/method',
i18nKey: 'user_account_menu_my_payment_methods',
trackingHit: tracking.paymentMethod,

},
{
app: 'dedicated',
key: 'myCommands',
hash: '#/billing/orders',
i18nKey: 'user_account_menu_my_commands',
trackingHit: tracking.orders,
},
{
app: 'dedicated',
key: 'myContacts',
hash: '#/contacts/services',
i18nKey: 'user_account_menu_my_contacts',
Expand Down

0 comments on commit cd63256

Please sign in to comment.