Skip to content

Commit

Permalink
chore: simplified useLicense return value (#30719)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva authored and hugocostadev committed Oct 26, 2023
1 parent 597d7e9 commit 62ef4d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
26 changes: 10 additions & 16 deletions apps/meteor/client/hooks/useLicense.ts
Original file line number Diff line number Diff line change
@@ -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<OperationResult<'GET', '/v1/licenses.info'>> => {
type LicenseDataType = Awaited<OperationResult<'GET', '/v1/licenses.info'>>['license'];

export const useLicense = (): UseQueryResult<Serialized<LicenseDataType>> => {
const getLicenses = useEndpoint('GET', '/v1/licenses.info');
const canViewLicense = usePermission('view-privileged-setting');

const queryClient = useQueryClient();

Expand All @@ -23,17 +25,9 @@ export const useLicense = (): UseQueryResult<OperationResult<'GET', '/v1/license

useEffect(() => 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,
});
};
2 changes: 1 addition & 1 deletion apps/meteor/client/views/admin/info/LicenseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 62ef4d4

Please sign in to comment.