import { Accordion, AccordionItem, Box, Button, ButtonGroup, Callout, Grid, GridItem } from '@rocket.chat/fuselage'; import { useDebouncedValue, useSessionStorage } from '@rocket.chat/fuselage-hooks'; import { Page, PageScrollableContentWithShadow, PageHeaderNoShadow, PageBlockWithBorder, useInvalidateLicense, useLicenseWithCloudAnnouncement, } from '@rocket.chat/ui-client'; import { useSearchParameter, useRouter } from '@rocket.chat/ui-contexts'; import { t } from 'i18next'; import { memo, useCallback, useEffect } from 'react'; import tinykeys from 'tinykeys'; import { SubscriptionCalloutLimits } from './SubscriptionCalloutLimits'; import SubscriptionPageSkeleton from './SubscriptionPageSkeleton'; import UpgradeButton from './components/UpgradeButton'; import UpgradeToGetMore from './components/UpgradeToGetMore'; import ActiveSessionsCard from './components/cards/ActiveSessionsCard'; import ActiveSessionsPeakCard from './components/cards/ActiveSessionsPeakCard'; import AppsUsageCard from './components/cards/AppsUsageCard'; import CountMACCard from './components/cards/CountMACCard'; import CountSeatsCard from './components/cards/CountSeatsCard'; import FeaturesCard from './components/cards/FeaturesCard'; import MACCard from './components/cards/MACCard'; import PlanCard from './components/cards/PlanCard'; import SeatsCard from './components/cards/SeatsCard'; import { useCancelSubscriptionModal } from './hooks/useCancelSubscriptionModal'; import { useWorkspaceSync } from './hooks/useWorkspaceSync'; import UiKitSubscriptionLicense from './surface/UiKitSubscriptionLicense'; import { useIsEnterprise } from '../../../hooks/useIsEnterprise'; import { useRegistrationStatus } from '../../../hooks/useRegistrationStatus'; function useShowLicense() { const [showLicenseTab, setShowLicenseTab] = useSessionStorage('admin:showLicenseTab', false); useEffect(() => { const unsubscribe = tinykeys(window, { 'ArrowUp ArrowUp ArrowDown ArrowDown ArrowLeft ArrowRight ArrowLeft ArrowRight b a': () => { setShowLicenseTab((showLicenseTab) => !showLicenseTab); }, }); return () => { unsubscribe(); }; }); return showLicenseTab; } const SubscriptionPage = () => { const showLicense = useShowLicense(); const router = useRouter(); const { data: enterpriseData } = useIsEnterprise(); const { canViewRegistrationStatus } = useRegistrationStatus(); const { data: licensesData, isLoading: isLicenseLoading } = useLicenseWithCloudAnnouncement({ loadValues: true }); const syncLicenseUpdate = useWorkspaceSync(); const invalidateLicenseQuery = useInvalidateLicense(); const subscriptionSuccess = useSearchParameter('subscriptionSuccess'); const showSubscriptionCallout = useDebouncedValue(subscriptionSuccess || syncLicenseUpdate.isPending, 10000); const { license, limits, activeModules = [], cloudSyncAnnouncement } = licensesData || {}; const { isEnterprise = true } = enterpriseData || {}; const getKeyLimit = (key: 'monthlyActiveContacts' | 'activeUsers') => { const { max, value } = limits?.[key] || {}; return { max: max !== undefined && max !== -1 ? max : Infinity, value, }; }; const macLimit = getKeyLimit('monthlyActiveContacts'); const seatsLimit = getKeyLimit('activeUsers'); const { isLoading: isCancelSubscriptionLoading, open: openCancelSubscriptionModal } = useCancelSubscriptionModal(); const handleSyncLicenseUpdate = useCallback(() => { syncLicenseUpdate.mutate(undefined, { onSuccess: () => invalidateLicenseQuery(100), }); }, [invalidateLicenseQuery, syncLicenseUpdate]); useEffect(() => { if (subscriptionSuccess && syncLicenseUpdate.isIdle) { handleSyncLicenseUpdate(); return; } if (subscriptionSuccess) { router.navigate( { name: router.getRouteName()!, params: Object.fromEntries(Object.entries(router.getSearchParameters()).filter(([key]) => key !== 'subscriptionSuccess')), }, { replace: true, }, ); } }, [handleSyncLicenseUpdate, router, subscriptionSuccess, syncLicenseUpdate.isIdle]); return ( {canViewRegistrationStatus && ( )} {t(isEnterprise ? 'Manage_subscription' : 'Upgrade')} {cloudSyncAnnouncement && ( )} {(showSubscriptionCallout || syncLicenseUpdate.isPending) && ( {t('Sync_license_update_Callout')} )} {isLicenseLoading && } {!isLicenseLoading && ( <> {showLicense && (
{JSON.stringify(licensesData, null, 2)}
)} {seatsLimit.value !== undefined && ( {seatsLimit.max !== Infinity ? ( ) : ( )} )} {macLimit.value !== undefined && ( {macLimit.max !== Infinity ? ( ) : ( )} )} {!license && ( <> {limits?.marketplaceApps !== undefined && ( )} )} {Boolean(licensesData?.license?.information.cancellable) && ( )} )}
); }; export default memo(SubscriptionPage);