Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/meteor/client/components/PlanTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useIsEnterprise } from '../hooks/useIsEnterprise';
function PlanTag(): ReactElement {
const [plans, setPlans] = useState<string[]>([]);

const isEnterprise = useIsEnterprise();
const { isEnterprise } = useIsEnterprise();
useEffect(() => {
const developmentTag = process.env.NODE_ENV === 'development' ? 'Development' : null;
const enterpriseTag = isEnterprise ? 'Enterprise' : null;
Expand Down
11 changes: 8 additions & 3 deletions apps/meteor/client/hooks/useIsEnterprise.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';

export const useIsEnterprise = (): boolean => {
export const useIsEnterprise = (): { isEnterprise: boolean; isLoading: boolean } => {
Comment thread
hugocostadev marked this conversation as resolved.
Outdated
const isEnterpriseEdition = useEndpoint('GET', '/v1/licenses.isEnterprise');
const { data } = useQuery(['licenses.isEnterprise'], () => isEnterpriseEdition(), { keepPreviousData: true });
return Boolean(data?.isEnterprise);
const { data, isLoading } = useQuery(['licenses', 'isEnterprise'], () => isEnterpriseEdition(), {
keepPreviousData: true,
refetchOnWindowFocus: false,
staleTime: Infinity,
});

return { isEnterprise: Boolean(data?.isEnterprise), isLoading };
};
32 changes: 32 additions & 0 deletions apps/meteor/client/hooks/useLicense.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { CloudRegistrationStatus, ILicense } from '@rocket.chat/core-typings';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';

export const useLicense = (): {
Comment thread
hugocostadev marked this conversation as resolved.
Outdated
licenses: ILicense[] | undefined;
registrationStatus: CloudRegistrationStatus | undefined;
isError: boolean;
isLoading: boolean;
isSuccess: boolean;
} => {
const getRegistrationStatus = useEndpoint('GET', '/v1/cloud.registrationStatus');
const getLicenses = useEndpoint('GET', '/v1/licenses.get');

const { data: registrationStatusData } = useQuery(['licenses', 'getRegistrationStatus'], () => getRegistrationStatus(), {
Comment thread
hugocostadev marked this conversation as resolved.
Outdated
refetchOnWindowFocus: false,
keepPreviousData: true,
staleTime: Infinity,
});

const { data, isError, isLoading, isSuccess } = useQuery(['licenses', 'getLicenses'], () => getLicenses(), {
staleTime: Infinity,
keepPreviousData: true,
refetchOnWindowFocus: false,
enabled: !!registrationStatusData,
});

const registrationStatus = registrationStatusData?.registrationStatus;
const licenses = data?.licenses;

return { licenses, isError, isLoading, isSuccess, registrationStatus };
};
15 changes: 15 additions & 0 deletions apps/meteor/client/providers/SettingsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Tracker } from 'meteor/tracker';
import React, { useCallback, useEffect, useMemo, useState, FunctionComponent } from 'react';

import { createReactiveSubscriptionFactory } from '../lib/createReactiveSubscriptionFactory';
import { queryClient } from '../lib/queryClient';
import { PrivateSettingsCachedCollection } from '../lib/settings/PrivateSettingsCachedCollection';
import { PublicSettingsCachedCollection } from '../lib/settings/PublicSettingsCachedCollection';

Expand Down Expand Up @@ -80,9 +81,23 @@ const SettingsProvider: FunctionComponent<SettingsProviderProps> = ({ children,
[cachedCollection],
);

const settingsChangeCallback = (changes: { _id: string }[]): void => {
changes.forEach((val) => {
switch (val._id) {
case 'Enterprise_License':
queryClient.invalidateQueries(['licenses']);
break;

default:
break;
}
});
};

const saveSettings = useMethod('saveSettings');
const dispatch = useCallback(
async (changes) => {
await settingsChangeCallback(changes);
await saveSettings(changes);
},
[saveSettings],
Expand Down
3 changes: 3 additions & 0 deletions apps/meteor/client/views/admin/cloud/PasteStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Box, Button, Scrollable, Throbber, Modal } from '@rocket.chat/fuselage'
import { useToastMessageDispatch, useEndpoint, useTranslation } from '@rocket.chat/ui-contexts';
import React, { ChangeEvent, FC, useState } from 'react';

import { queryClient } from '../../../lib/queryClient';

type PasteStepProps = {
onBackButtonClick: () => void;
onFinish: () => void;
Expand All @@ -25,6 +27,7 @@ const PasteStep: FC<PasteStepProps> = ({ onBackButtonClick, onFinish }) => {

try {
await registerManually({ cloudBlob: cloudKey });
queryClient.invalidateQueries(['licenses']);
dispatchToastMessage({ type: 'success', message: t('Cloud_register_success') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: t('Cloud_register_error') });
Expand Down
10 changes: 4 additions & 6 deletions apps/meteor/client/views/admin/info/LicenseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { useSetModal, useSetting, useTranslation } from '@rocket.chat/ui-context
import React, { ReactElement } from 'react';

import PlanTag from '../../../components/PlanTag';
import { AsyncStatePhase } from '../../../hooks/useAsyncState';
import { useEndpointData } from '../../../hooks/useEndpointData';
import { useLicense } from '../../../hooks/useLicense';
import Feature from './Feature';
import OfflineLicenseModal from './OfflineLicenseModal';

Expand All @@ -19,10 +18,9 @@ const LicenseCard = (): ReactElement => {

const isAirGapped = true;

const { value, phase, error } = useEndpointData('/v1/licenses.get');
const endpointLoading = phase === AsyncStatePhase.LOADING;
const { licenses, isError, isLoading } = useLicense();

const { modules = [] } = endpointLoading || error || !value?.licenses.length ? {} : value.licenses[0];
const { modules = [] } = isLoading || isError || !licenses?.length ? {} : licenses[0];

const hasEngagement = modules.includes('engagement-dashboard');
const hasOmnichannel = modules.includes('livechat-enterprise');
Expand Down Expand Up @@ -52,7 +50,7 @@ const LicenseCard = (): ReactElement => {
<Card.Col.Section>
<Card.Col.Title>{t('Features')}</Card.Col.Title>
<Margins block='x4'>
{endpointLoading ? (
{isLoading ? (
<>
<Skeleton width='40x' />
<Skeleton width='40x' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useEndpoint, useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import React, { ComponentProps, FormEvent, ReactElement, useState } from 'react';

import { queryClient } from '../../../lib/queryClient';

type OfflineLicenseModalProps = {
onClose: () => void;
license: string;
Expand Down Expand Up @@ -38,10 +40,11 @@ const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }: Offl

const handleApplyLicense = useMutableCallback(async () => {
setLastSetLicense(newLicense);

try {
setIsUpdating(true);
await addLicense({ license: newLicense });
queryClient.invalidateQueries(['licenses']);

dispatchToastMessage({ type: 'success', message: t('Cloud_License_applied_successfully') });
onClose();
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const EditableSettingsProvider: FunctionComponent<EditableSettingsProviderProps>
Tracker.flush();
});

const isEnterprise = useIsEnterprise();
const { isEnterprise } = useIsEnterprise();

const contextValue = useMemo<EditableSettingsContextValue>(
() => ({
Expand Down
14 changes: 3 additions & 11 deletions apps/meteor/client/views/hooks/useUpgradeTabParams.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import { useSetting, useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { useSetting } from '@rocket.chat/ui-contexts';
import { format } from 'date-fns';

import { getUpgradeTabType, UpgradeTabVariant } from '../../../lib/upgradeTab';
import { useLicense } from '../../hooks/useLicense';

export const useUpgradeTabParams = (): { tabType: UpgradeTabVariant | false; trialEndDate: string | undefined; isLoading: boolean } => {
const getRegistrationStatus = useEndpoint('GET', '/v1/cloud.registrationStatus');
const getLicenses = useEndpoint('GET', '/v1/licenses.get');
const cloudWorkspaceHadTrial = useSetting('Cloud_Workspace_Had_Trial') as boolean;

const { data: registrationStatusData } = useQuery(['registrationStatus'], () => getRegistrationStatus());
const { data: getValidLicensesData, isSuccess } = useQuery(['licenses'], () => getLicenses(), {
enabled: !!registrationStatusData,
});

const { registrationStatus } = registrationStatusData ?? {};
const { licenses } = getValidLicensesData ?? {};
const { licenses, isSuccess, registrationStatus } = useLicense();

const registered = registrationStatus?.workspaceRegistered ?? false;
const hasValidLicense = (licenses?.length ?? 0) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import React, { useCallback, useMemo, useState, ReactElement, ContextType } from

import { callbacks } from '../../../../lib/callbacks';
import { validateEmail } from '../../../../lib/emailValidator';
import { queryClient } from '../../../lib/queryClient';
import { SetupWizardContext } from '../contexts/SetupWizardContext';
import { useParameters } from '../hooks/useParameters';
import { useStepRouting } from '../hooks/useStepRouting';
Expand Down Expand Up @@ -171,6 +172,7 @@ const SetupWizardProvider = ({ children }: { children: ReactElement }): ReactEle
try {
await saveOrganizationData();
const { intentData } = await createRegistrationIntent({ resend, email });
queryClient.invalidateQueries(['licenses']);

setSetupWizardData((prevState) => ({
...prevState,
Expand Down
13 changes: 6 additions & 7 deletions apps/meteor/ee/client/sidebar/footer/SidebarFooterWatermark.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Box } from '@rocket.chat/fuselage';
import { useEndpoint, useTranslation } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { useTranslation } from '@rocket.chat/ui-contexts';
import React, { ReactElement } from 'react';

import { useIsEnterprise } from '../../../../client/hooks/useIsEnterprise';

export const SidebarFooterWatermark = (): ReactElement | null => {
const t = useTranslation();
const isEnterpriseEdition = useEndpoint('GET', '/v1/licenses.isEnterprise');
const result = useQuery(['licenses.isEnterprise'], () => isEnterpriseEdition(), {
refetchOnWindowFocus: false,
});

if (!result.isSuccess || result.isLoading || result.data.isEnterprise) {
const { isEnterprise, isLoading } = useIsEnterprise();

if (isEnterprise || isLoading) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23669,7 +23669,7 @@ __metadata:
optional: true
bin:
lessc: ./bin/lessc
checksum: 61568b56b5289fdcfe3d51baf3c13e7db7140022c0a37ef0ae343169f0de927a4b4f4272bc10c20101796e8ee79e934e024051321bba93b3ae071f734309bd98
checksum: c9b8c0e865427112c48a9cac36f14964e130577743c29d56a6d93b5812b70846b04ccaa364acf1e8d75cee3855215ec0a2d8d9de569c80e774f10b6245f39b7d
languageName: node
linkType: hard

Expand Down