Skip to content

Commit

Permalink
chore: remove upgrade page and references (#30715)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocostadev authored Nov 1, 2023
1 parent e24af45 commit 3c19109
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 529 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const useUpsellActions = (hasLicenseModule = false) => {
const { data } = useIsEnterprise();
const shouldShowUpsell = !data?.isEnterprise || !hasLicenseModule;

const handleGoFullyFeatured = useCallback(() => {
router.navigate('/admin/upgrade/go-fully-featured-registered');
const handleManageSubscription = useCallback(() => {
router.navigate('/admin/subscription');
setModal(null);
}, [router, setModal]);

Expand All @@ -25,5 +25,5 @@ export const useUpsellActions = (hasLicenseModule = false) => {
setModal(null);
}, [handleOpenLink, setModal]);

return { shouldShowUpsell, cloudWorkspaceHadTrial, handleGoFullyFeatured, handleTalkToSales };
return { shouldShowUpsell, cloudWorkspaceHadTrial, handleManageSubscription, handleTalkToSales };
};
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
import { Button, Modal, Box } from '@rocket.chat/fuselage';
import { useOutsideClick } from '@rocket.chat/fuselage-hooks';
import { useRoute, useTranslation } from '@rocket.chat/ui-contexts';
import { useRouter, useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React, { useRef } from 'react';

import { hasPermission } from '../../../../app/authorization/client';
import { useUpgradeTabParams } from '../../../views/hooks/useUpgradeTabParams';

const EnterpriseDepartmentsModal = ({ closeModal }: { closeModal: () => void }): ReactElement => {
const t = useTranslation();
const upgradeRoute = useRoute('upgrade');
const departmentsRoute = useRoute('omnichannel-departments');
const { tabType, trialEndDate } = useUpgradeTabParams();
const router = useRouter();
const ref = useRef<HTMLDivElement>(null);
const upgradeNowClick = (): void => {
tabType && upgradeRoute.push({ type: tabType }, trialEndDate ? { trialEndDate } : undefined);
const goToManageSubscriptionPage = (): void => {
router.navigate('/admin/subscription');
closeModal();
};

const onClose = (): void => {
departmentsRoute.push({});
router.navigate('/omnichannel/departments');
closeModal();
};

const isTypeUpgradeYourPlan = ['go-fully-featured', 'go-fully-featured-registered'].includes(tabType || '');

const talkToExpertLink =
'https://www.rocket.chat/sales-contact?utm_source=rocketchat_app&utm_medium=multiple_queues&utm_campaign=in_product_ctas';

const freeTrialLink =
'https://www.rocket.chat/trial-saas?utm_source=rocketchat_app&utm_medium=multiple_queues&utm_campaign=in_product_ctas';

useOutsideClick([ref], onClose);

return (
Expand All @@ -47,23 +39,18 @@ const EnterpriseDepartmentsModal = ({ closeModal }: { closeModal: () => void }):
<Box fontScale='h3' mbe={28}>
{t('Enterprise_Departments_title')}
</Box>
{isTypeUpgradeYourPlan ? t('Enterprise_Departments_description_free_trial') : t('Enterprise_Departments_description_upgrade')}
{t('Enterprise_Departments_description_upgrade')}
</Modal.Content>
<Modal.Footer>
{hasPermission('view-statistics') ? (
<Modal.FooterControllers>
<Button is='a' href={talkToExpertLink} external onClick={onClose} data-qa-id='btn-talk-to-sales'>
{t('Talk_to_an_expert')}
</Button>
{isTypeUpgradeYourPlan ? (
<Button is='a' href={freeTrialLink} external primary data-qa-id='upgrade-now'>
{t('Start_free_trial')}
</Button>
) : (
<Button onClick={upgradeNowClick} primary data-qa-id='upgrade-now'>
{t('Learn_more')}
</Button>
)}

<Button onClick={goToManageSubscriptionPage} primary data-qa-id='upgrade-now'>
{t('Learn_more')}
</Button>
</Modal.FooterControllers>
) : (
<Box display='flex' width='100%' justifyContent='space-between' alignItems='center'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,6 @@ import { renderHook } from '@testing-library/react-hooks';

import { useAdministrationItems } from './useAdministrationItems';

it('should not show upgrade item if has license and not have trial', async () => {
const { result, waitFor } = renderHook(() => useAdministrationItems(), {
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
license: {
// @ts-expect-error this is a mock
license: { activeModules: ['testModule'] },
trial: false,
},
}))
.withEndpoint('GET', '/v1/cloud.registrationStatus', () => ({
registrationStatus: {
workspaceRegistered: false,
} as any,
}))
.withPermission('view-privileged-setting')
.withPermission('manage-cloud')
.build(),
});

await waitFor(() => !!(result.all.length > 1));
expect(result.current.length).toEqual(1);

expect(result.current[0]).toEqual(
expect.objectContaining({
id: 'workspace',
}),
);
});

it('should return an upgrade item if not have license or if have a trial', async () => {
const { result, waitFor } = renderHook(() => useAdministrationItems(), {
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
// @ts-expect-error this is a mock
license: {},
}))
.withEndpoint('GET', '/v1/cloud.registrationStatus', () => ({
registrationStatus: {
workspaceRegistered: false,
} as any,
}))
.withPermission('view-privileged-setting')
.withPermission('manage-cloud')
.build(),
});

// Workspace admin is also expected to be here
await waitFor(() => result.current.length > 1);

expect(result.current[0]).toEqual(
expect.objectContaining({
id: 'showUpgradeItem',
}),
);
});

it('should return omnichannel item if has `view-livechat-manager` permission ', async () => {
const { result, waitFor } = renderHook(() => useAdministrationItems(), {
wrapper: mockAppRoot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ import {
} from '@rocket.chat/ui-contexts';
import React from 'react';

import type { UpgradeTabVariant } from '../../../../../lib/upgradeTab';
import { getUpgradeTabLabel, isFullyFeature } from '../../../../../lib/upgradeTab';
import Emoji from '../../../../components/Emoji';
import type { GenericMenuItemProps } from '../../../../components/GenericMenu/GenericMenuItem';
import { useRegistrationStatus } from '../../../../hooks/useRegistrationStatus';
import RegisterWorkspaceModal from '../../../../views/admin/cloud/modals/RegisterWorkspaceModal';
import { useUpgradeTabParams } from '../../../../views/hooks/useUpgradeTabParams';

const ADMIN_PERMISSIONS = [
'view-statistics',
Expand Down Expand Up @@ -57,11 +53,6 @@ export const useAdministrationItems = (): GenericMenuItemProps[] => {

const shouldShowAdminMenu = useAtLeastOnePermission(ADMIN_PERMISSIONS);

const { tabType, trialEndDate, isLoading } = useUpgradeTabParams();
const shouldShowEmoji = isFullyFeature(tabType);

const label = getUpgradeTabLabel(tabType);

const isAdmin = useRole('admin');
const setModal = useSetModal();

Expand All @@ -73,32 +64,17 @@ export const useAdministrationItems = (): GenericMenuItemProps[] => {
};

const adminRoute = useRoute('admin-index');
const upgradeRoute = useRoute('upgrade');
const cloudRoute = useRoute('cloud');

const omnichannel = usePermission('view-livechat-manager');

const showUpgradeItem = !isLoading && tabType;

const omnichannelItem: GenericMenuItemProps = {
id: 'omnichannel',
content: t('Omnichannel'),
icon: 'headset',
onClick: () => router.navigate('/omnichannel/current'),
};

const upgradeItem: GenericMenuItemProps = {
id: 'showUpgradeItem',
content: (
<>
{t(label)} {shouldShowEmoji && <Emoji emojiHandle=':zap:' />}
</>
),
icon: 'arrow-stack-up',
onClick: () => {
upgradeRoute.push({ type: tabType as UpgradeTabVariant }, trialEndDate ? { trialEndDate } : undefined);
},
};
const adminItem: GenericMenuItemProps = {
id: 'registration',
content: isRegistered ? t('Registration') : t('Register'),
Expand All @@ -120,10 +96,7 @@ export const useAdministrationItems = (): GenericMenuItemProps[] => {
},
};

return [
showUpgradeItem && upgradeItem,
shouldShowAdminMenu && workspaceItem,
isAdmin && adminItem,
omnichannel && omnichannelItem,
].filter(Boolean) as GenericMenuItemProps[];
return [shouldShowAdminMenu && workspaceItem, isAdmin && adminItem, omnichannel && omnichannelItem].filter(
Boolean,
) as GenericMenuItemProps[];
};
18 changes: 2 additions & 16 deletions apps/meteor/client/views/admin/AdministrationRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import PageSkeleton from '../../components/PageSkeleton';
import type { Item, SidebarDivider, SidebarItem } from '../../lib/createSidebarItems';
import { isGoRocketChatLink } from '../../lib/createSidebarItems';
import SettingsProvider from '../../providers/SettingsProvider';
import { useUpgradeTabParams } from '../hooks/useUpgradeTabParams';
import AdministrationLayout from './AdministrationLayout';
import { getAdminSidebarItems } from './sidebarItems';

Expand All @@ -28,7 +27,6 @@ type AdministrationRouterProps = {

const AdministrationRouter = ({ children }: AdministrationRouterProps): ReactElement => {
const router = useRouter();
const { tabType, trialEndDate, isLoading } = useUpgradeTabParams();

useEffect(
() =>
Expand All @@ -37,19 +35,7 @@ const AdministrationRouter = ({ children }: AdministrationRouterProps): ReactEle
return;
}

if (tabType && !isLoading) {
router.navigate(
{
name: 'upgrade',
params: { type: tabType },
search: trialEndDate ? { trialEndDate } : undefined,
},
{ replace: true },
);
return;
}

const defaultRoutePath = getAdminSidebarItems().find(firstSidebarPage)?.href ?? '/admin/info';
const defaultRoutePath = getAdminSidebarItems().find(firstSidebarPage)?.href ?? '/admin/workspace';

if (isGoRocketChatLink(defaultRoutePath)) {
window.open(defaultRoutePath, '_blank');
Expand All @@ -58,7 +44,7 @@ const AdministrationRouter = ({ children }: AdministrationRouterProps): ReactEle

router.navigate(defaultRoutePath, { replace: true });
}),
[tabType, trialEndDate, isLoading, router],
[router],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useUpsellActions } from '../../../components/GenericUpsellModal/hooks';

const CustomRoleUpsellModal = ({ onClose }: { onClose: () => void }) => {
const t = useTranslation();
const { cloudWorkspaceHadTrial, handleTalkToSales, handleGoFullyFeatured } = useUpsellActions();
const { cloudWorkspaceHadTrial, handleTalkToSales, handleManageSubscription } = useUpsellActions();

return (
<GenericUpsellModal
Expand All @@ -18,7 +18,7 @@ const CustomRoleUpsellModal = ({ onClose }: { onClose: () => void }) => {
onClose={onClose}
cancelText={t('Talk_to_an_expert')}
confirmText={cloudWorkspaceHadTrial ? t('Learn_more') : t('Start_a_free_trial')}
onConfirm={handleGoFullyFeatured}
onConfirm={handleManageSubscription}
onCancel={handleTalkToSales}
/>
);
Expand Down
10 changes: 0 additions & 10 deletions apps/meteor/client/views/admin/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { lazy } from 'react';

import type { UpgradeTabVariant } from '../../../lib/upgradeTab';
import { createRouteGroup } from '../../lib/createRouteGroup';

declare module '@rocket.chat/ui-contexts' {
Expand Down Expand Up @@ -101,10 +100,6 @@ declare module '@rocket.chat/ui-contexts' {
pathname: `/admin/engagement${`/${string}` | ''}`;
pattern: '/admin/engagement/:tab?';
};
'upgrade': {
pathname: `/admin/upgrade${`/${UpgradeTabVariant}` | ''}`;
pattern: '/admin/upgrade/:type?';
};
'moderation-console': {
pathname: `/admin/moderation${`/${string}` | ''}${`/${string}` | ''}`;
pattern: '/admin/moderation/:context?/:id?';
Expand Down Expand Up @@ -232,11 +227,6 @@ registerAdminRoute('/settings/:group?', {
component: lazy(() => import('./settings/SettingsRoute')),
});

registerAdminRoute('/upgrade/:type?', {
name: 'upgrade',
component: lazy(() => import('./upgrade/UpgradePage')),
});

registerAdminRoute('/moderation/:context?/:id?', {
name: 'moderation-console',
component: lazy(() => import('./moderation/ModerationConsoleRoute')),
Expand Down
5 changes: 0 additions & 5 deletions apps/meteor/client/views/admin/sidebar/AdminSidebarPages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import React, { memo } from 'react';
import { useSyncExternalStore } from 'use-sync-external-store/shim';

import SidebarItemsAssembler from '../../../components/Sidebar/SidebarItemsAssembler';
import { useUpgradeTabParams } from '../../hooks/useUpgradeTabParams';
import { subscribeToAdminSidebarItems, getAdminSidebarItems } from '../sidebarItems';
import UpgradeTab from './UpgradeTab';

type AdminSidebarPagesProps = {
currentPath: string;
Expand All @@ -15,11 +13,8 @@ type AdminSidebarPagesProps = {
const AdminSidebarPages: FC<AdminSidebarPagesProps> = ({ currentPath }) => {
const items = useSyncExternalStore(subscribeToAdminSidebarItems, getAdminSidebarItems);

const { tabType, trialEndDate, isLoading } = useUpgradeTabParams();

return (
<Box display='flex' flexDirection='column' flexShrink={0} pb={8}>
{!isLoading && tabType && <UpgradeTab type={tabType} currentPath={currentPath} trialEndDate={trialEndDate} />}
<SidebarItemsAssembler items={items} currentPath={currentPath} />
</Box>
);
Expand Down
37 changes: 0 additions & 37 deletions apps/meteor/client/views/admin/sidebar/UpgradeTab.tsx

This file was deleted.

Loading

0 comments on commit 3c19109

Please sign in to comment.