From 72653e678047edc45ba46f01eb228676dc281a28 Mon Sep 17 00:00:00 2001 From: Aleksander Nicacio da Silva Date: Mon, 23 Oct 2023 15:55:29 -0300 Subject: [PATCH] chore: simplified useLicense return value (#30719) --- apps/meteor/client/hooks/useLicense.ts | 26 +++++++------------ .../client/views/admin/info/LicenseCard.tsx | 2 +- .../client/views/hooks/useUpgradeTabParams.ts | 6 ++--- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/apps/meteor/client/hooks/useLicense.ts b/apps/meteor/client/hooks/useLicense.ts index 8ba594c5b5d3..ec07e1702bed 100644 --- a/apps/meteor/client/hooks/useLicense.ts +++ b/apps/meteor/client/hooks/useLicense.ts @@ -1,13 +1,15 @@ +import type { Serialized } from '@rocket.chat/core-typings'; import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks'; import type { OperationResult } from '@rocket.chat/rest-typings'; -import { useEndpoint, usePermission, useSingleStream } from '@rocket.chat/ui-contexts'; +import { useEndpoint, useSingleStream } from '@rocket.chat/ui-contexts'; import type { UseQueryResult } from '@tanstack/react-query'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { useEffect } from 'react'; -export const useLicense = (): UseQueryResult> => { +type LicenseDataType = Awaited>['license']; + +export const useLicense = (): UseQueryResult> => { const getLicenses = useEndpoint('GET', '/v1/licenses.info'); - const canViewLicense = usePermission('view-privileged-setting'); const queryClient = useQueryClient(); @@ -23,17 +25,9 @@ export const useLicense = (): UseQueryResult notify('license', () => invalidate()), [notify, invalidate]); - return useQuery( - ['licenses', 'getLicenses'], - () => { - if (!canViewLicense) { - throw new Error('unauthorized api call'); - } - return getLicenses({}); - }, - { - staleTime: Infinity, - keepPreviousData: true, - }, - ); + return useQuery(['licenses', 'getLicenses'], () => getLicenses({}), { + staleTime: Infinity, + keepPreviousData: true, + select: (data) => data.license, + }); }; diff --git a/apps/meteor/client/views/admin/info/LicenseCard.tsx b/apps/meteor/client/views/admin/info/LicenseCard.tsx index 8aab636f4720..195121932e80 100644 --- a/apps/meteor/client/views/admin/info/LicenseCard.tsx +++ b/apps/meteor/client/views/admin/info/LicenseCard.tsx @@ -56,7 +56,7 @@ const LicenseCard = (): ReactElement => { ); } - const { activeModules } = request.data.license; + const { activeModules } = request.data; const hasEngagement = activeModules.includes('engagement-dashboard'); const hasOmnichannel = activeModules.includes('livechat-enterprise'); diff --git a/apps/meteor/client/views/hooks/useUpgradeTabParams.ts b/apps/meteor/client/views/hooks/useUpgradeTabParams.ts index 1d152b08d5b9..abfa9da251dc 100644 --- a/apps/meteor/client/views/hooks/useUpgradeTabParams.ts +++ b/apps/meteor/client/views/hooks/useUpgradeTabParams.ts @@ -13,11 +13,11 @@ export const useUpgradeTabParams = (): { tabType: UpgradeTabVariant | false; tri const { data: registrationStatusData, isSuccess: isSuccessRegistrationStatus } = useRegistrationStatus(); const registered = registrationStatusData?.registrationStatus?.workspaceRegistered ?? false; - const hasValidLicense = Boolean(licensesData?.license?.license ?? false); + const hasValidLicense = Boolean(licensesData?.license ?? false); const hadExpiredTrials = cloudWorkspaceHadTrial ?? false; - const isTrial = Boolean(licensesData?.license?.trial); - const trialEndDateStr = licensesData?.license?.license?.information?.visualExpiration; + const isTrial = Boolean(licensesData?.trial); + const trialEndDateStr = licensesData?.license?.information?.visualExpiration; const trialEndDate = trialEndDateStr ? format(new Date(trialEndDateStr), 'yyyy-MM-dd') : undefined; const upgradeTabType = getUpgradeTabType({