Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type CreateChannelModalPayload = {
};

const getFederationHintKey = (licenseModule: ReturnType<typeof useHasLicenseModule>, featureToggle: boolean): TranslationKey => {
if (licenseModule === 'loading' || !licenseModule) {
if (licenseModule.isPending || !licenseModule.data) {
return 'error-this-is-a-premium-feature';
}
if (!featureToggle) {
Expand All @@ -75,7 +75,7 @@ const CreateChannelModal = ({ teamId = '', onClose, reload }: CreateChannelModal

const channelNameRegex = useMemo(() => new RegExp(`^${namesValidation}$`), [namesValidation]);
const federatedModule = useHasLicenseModule('federation');
const canUseFederation = federatedModule !== 'loading' && federatedModule && federationEnabled;
const canUseFederation = !federatedModule.isPending && federatedModule.data && federationEnabled;

const channelNameExists = useEndpoint('GET', '/v1/rooms.nameExists');
const createChannel = useEndpoint('POST', '/v1/channels.create');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const useAuditMenu = () => {
const router = useRouter();
const { t } = useTranslation();

const hasAuditLicense = useHasLicenseModule('auditing') === true;
const { data: hasAuditLicense = false } = useHasLicenseModule('auditing');

const hasAuditPermission = usePermission('can-audit') && hasAuditLicense;
const hasAuditLogPermission = usePermission('can-audit-log') && hasAuditLicense;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/contexts/CallContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const CallContextValueDefault: CallContextValue = {

export const CallContext = createContext<CallContextValue>(CallContextValueDefault);

export const useIsVoipEnterprise = (): boolean => useHasLicenseModule('voip-enterprise') === true;
export const useIsVoipEnterprise = (): boolean => useHasLicenseModule('voip-enterprise').data === true;

export const useIsCallEnabled = (): boolean => {
const { enabled } = useContext(CallContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { QuickActionsEnum, type QuickActionsActionConfig } from '../../views/roo
import { useHasLicenseModule } from '../useHasLicenseModule';

export const useOnHoldChatQuickAction = (): QuickActionsActionConfig | undefined => {
const licensed = useHasLicenseModule('livechat-enterprise') === true;
const { data: licensed = false } = useHasLicenseModule('livechat-enterprise');

return useMemo(() => {
if (!licensed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useHasLicenseModule } from '../useHasLicenseModule';
const VideoConfList = lazy(() => import('../../views/room/contextualBar/VideoConference/VideoConfList'));

export const useCallsRoomAction = () => {
const licensed = useHasLicenseModule('videoconference-enterprise') === true;
const { data: licensed = false } = useHasLicenseModule('videoconference-enterprise');
const room = useContext(RoomContext)?.room;
const federated = room ? isRoomFederated(room) : false;
const { t } = useTranslation();
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/hooks/useDevicesMenuOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type DevicesMenuOption = {
};

export const useDevicesMenuOption = (): DevicesMenuOption | null => {
const isEnterprise = useHasLicenseModule('voip-enterprise');
const { data: isEnterprise = false } = useHasLicenseModule('voip-enterprise');
const { t } = useTranslation();
const setModal = useSetModal();

Expand Down
11 changes: 4 additions & 7 deletions apps/meteor/client/hooks/useHasLicenseModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import type { LicenseModule } from '@rocket.chat/core-typings';

import { useLicenseBase } from './useLicense';

export const useHasLicenseModule = (licenseName: LicenseModule | undefined): 'loading' | boolean => {
return (
useLicenseBase({
select: (data) => !!licenseName && data.license.activeModules.includes(licenseName),
}).data ?? 'loading'
);
};
export const useHasLicenseModule = (licenseName: LicenseModule | undefined) =>
useLicenseBase({
select: (data) => !!licenseName && data.license.activeModules.includes(licenseName),
});
4 changes: 3 additions & 1 deletion apps/meteor/client/hooks/useLicense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ const invalidateQueryClientLicenses = (() => {

export const useLicenseBase = <TData = LicenseDataType>({
params,
enabled = true,
select,
}: {
params?: LicenseParams;
enabled?: boolean;
select: (data: LicenseDataType) => TData;
}) => {
const uid = useUserId();
Expand All @@ -48,7 +50,7 @@ export const useLicenseBase = <TData = LicenseDataType>({
staleTime: Infinity,
placeholderData: keepPreviousData,
select,
enabled: !!uid,
enabled: enabled && !!uid,
});
};

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/hooks/useVoipClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const useVoipClient = (): UseVoipClientResult => {
const iceServers = useWebRtcServers();
const [result, setResult] = useSafely(useState<UseVoipClientResult>({}));

const isEE = useHasLicenseModule('voip-enterprise');
const { data: isEE = false } = useHasLicenseModule('voip-enterprise');
const voipEnabled = settingVoipEnabled && voipConnectorEnabled;

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/hooks/useVoipWarningModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import TeamsVoipConfigModal from '../views/room/contextualBar/TeamsVoipConfigMod
export const useVoipWarningModal = (): (() => void) => {
const setModal = useSetModal();
const isAdmin = useRole('admin');
const hasModule = useHasLicenseModule('teams-voip') === true;
const { data: hasModule = false } = useHasLicenseModule('teams-voip');
const teamsVoipSettingsRoute = useRoute('admin-settings');

const handleClose = useEffectEvent(() => setModal(null));
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/providers/MediaCallProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const MediaCallProvider = ({ children }: { children: ReactNode }) => {
const canMakeInternalCall = usePermission('allow-internal-voice-calls');
const canMakeExternalCall = usePermission('allow-external-voice-calls');

const hasModule = useHasLicenseModule('teams-voip');
const { data: hasModule = false } = useHasLicenseModule('teams-voip');

const unauthorizedContextValue = useMemo(
() => ({
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/providers/OmnichannelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const OmnichannelProvider = ({ children }: OmnichannelProviderProps) => {

const accessible = hasAccess && omniChannelEnabled;
const iceServersSetting: any = useSetting('WebRTC_Servers');
const isEnterprise = useHasLicenseModule('livechat-enterprise') === true;
const { data: isEnterprise = false } = useHasLicenseModule('livechat-enterprise');

const getPriorities = useEndpoint('GET', '/v1/livechat/priorities');
const subscribe = useStream('notify-logged');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type CreateChannelModalPayload = {
};

const getFederationHintKey = (licenseModule: ReturnType<typeof useHasLicenseModule>, featureToggle: boolean): TranslationKey => {
if (licenseModule === 'loading' || !licenseModule) {
if (licenseModule.isPending || !licenseModule.data) {
return 'error-this-is-a-premium-feature';
}
if (!featureToggle) {
Expand All @@ -79,7 +79,7 @@ const CreateChannelModal = ({ teamId = '', mainRoom, onClose, reload }: CreateCh

const channelNameRegex = useMemo(() => new RegExp(`^${namesValidation}$`), [namesValidation]);
const federatedModule = useHasLicenseModule('federation');
const canUseFederation = federatedModule !== 'loading' && federatedModule && federationEnabled;
const canUseFederation = !federatedModule.isPending && federatedModule.data && federationEnabled;

const channelNameExists = useEndpoint('GET', '/v1/rooms.nameExists');
const createChannel = useEndpoint('POST', '/v1/channels.create');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation, useRoute, usePermission } from '@rocket.chat/ui-context
import { useHasLicenseModule } from '../../../../hooks/useHasLicenseModule';

export const useAuditItems = (): GenericMenuItemProps[] => {
const hasAuditLicense = useHasLicenseModule('auditing') === true;
const { data: hasAuditLicense = false } = useHasLicenseModule('auditing');

const hasAuditPermission = usePermission('can-audit') && hasAuditLicense;
const hasAuditLogPermission = usePermission('can-audit-log') && hasAuditLicense;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const PreferencesConversationTranscript = () => {

const { register } = useFormContext();

const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');
const alwaysSendEmailTranscript = useSetting('Livechat_transcript_send_always');
const canSendTranscriptPDF = usePermission('request-pdf-transcript');
const canSendTranscriptEmailPermission = usePermission('send-omnichannel-chat-transcript');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const DeviceManagementAdminRoute = (): ReactElement => {
const setModal = useSetModal();
const isModalOpen = !!useCurrentModal();

const hasDeviceManagement = useHasLicenseModule('device-management') as boolean;
const { data: hasDeviceManagement = false, isPending } = useHasLicenseModule('device-management');
const canViewDeviceManagement = usePermission('view-device-management');

const { shouldShowUpsell, handleManageSubscription } = useUpsellActions(hasDeviceManagement);
Expand All @@ -39,7 +39,7 @@ const DeviceManagementAdminRoute = (): ReactElement => {
}
}, [shouldShowUpsell, router, setModal, t, handleManageSubscription]);

if (isModalOpen) {
if (isModalOpen || isPending) {
return <PageSkeleton />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const EngagementDashboardRoute = (): ReactElement | null => {
const tab = useRouteParameter('tab');
const eventStats = useEndpoint('POST', '/v1/statistics.telemetry');

const hasEngagementDashboard = useHasLicenseModule('engagement-dashboard') as boolean;
const { isPending, data: hasEngagementDashboard = false } = useHasLicenseModule('engagement-dashboard');

const { shouldShowUpsell, handleManageSubscription } = useUpsellActions(hasEngagementDashboard);

Expand Down Expand Up @@ -64,7 +64,7 @@ const EngagementDashboardRoute = (): ReactElement | null => {
});
}, [shouldShowUpsell, router, tab, setModal, t, handleManageSubscription]);

if (isModalOpen) {
if (isModalOpen || isPending) {
return <PageSkeleton />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ import { useTranslation } from 'react-i18next';

import EditRolePage from './EditRolePage';
import { useRole } from './hooks/useRole';
import GenericError from '../../../components/GenericError';
import PageSkeleton from '../../../components/PageSkeleton';
import { useHasLicenseModule } from '../../../hooks/useHasLicenseModule';

const EditRolePageWithData = ({ roleId }: { roleId?: IRole['_id'] }): ReactElement => {
const { t } = useTranslation();
const role = useRole(roleId);
const context = useRouteParameter('context');
const hasCustomRolesModule = useHasLicenseModule('custom-roles');
const { isPending, isError, data: hasLicense } = useHasLicenseModule('custom-roles');

if (!role && context === 'edit') {
return <Callout type='danger'>{t('error-invalid-role')}</Callout>;
}

if (hasCustomRolesModule === 'loading') {
if (isPending) {
return <PageSkeleton />;
}

return <EditRolePage key={roleId} role={role} isEnterprise={hasCustomRolesModule} />;
if (isError) {
return <GenericError />;
}

return <EditRolePage key={roleId} role={role} isEnterprise={hasLicense} />;
};

export default EditRolePageWithData;
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ const PermissionsContextBar = (): ReactElement | null => {
const context = useRouteParameter('context');
const router = useRoute('admin-permissions');
const setModal = useSetModal();
const hasCustomRolesModule = useHasLicenseModule('custom-roles') === true;
const { isPending, data: hasCustomRolesModule = false } = useHasLicenseModule('custom-roles');

const handleCloseContextualbar = useEffectEvent(() => {
router.push({});
});

useEffect(() => {
if (isPending) {
return;
}

if (context !== 'new' || hasCustomRolesModule) {
return;
}

setModal(<CustomRoleUpsellModal onClose={() => setModal(null)} />);
handleCloseContextualbar();
}, [context, hasCustomRolesModule, handleCloseContextualbar, setModal]);
}, [isPending, context, hasCustomRolesModule, handleCloseContextualbar, setModal]);

return (
(context && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const UsersUploadsCard = ({ statistics }: UsersUploadsCardProps): ReactElement =
router.navigate('/admin/engagement');
});

const canViewEngagement = useHasLicenseModule('engagement-dashboard');
const { data: canViewEngagement = false } = useHasLicenseModule('engagement-dashboard');

return (
<Card height='full'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const AppDetails = ({ app }: AppDetailsProps) => {

const appAddon = installed ? installedAddon : addon;

const workspaceHasAddon = useHasLicenseModule(appAddon);
const { data: workspaceHasAddon = false } = useHasLicenseModule(appAddon);

const openExternalLink = useExternalLink();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const AppStatus = ({ app, showStatus = true, isAppDetailsPage, installed, ...pro
const isEnterprise = data?.isEnterprise ?? false;

const appAddon = app.addon;
const workspaceHasAddon = useHasLicenseModule(appAddon);
const { data: workspaceHasAddon = false } = useHasLicenseModule(appAddon);

const statuses = appMultiStatusProps(app, isAppDetailsPage, context || '', isEnterprise);

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/marketplace/hooks/useAppMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const useAppMenu = (app: App, isAppDetailsPage: boolean) => {
const { data } = useIsEnterprise();
const isEnterpriseLicense = !!data?.isEnterprise;

const workspaceHasMarketplaceAddon = useHasLicenseModule(app.addon);
const workspaceHasInstalledAddon = useHasLicenseModule(app.installedAddon);
const { data: workspaceHasMarketplaceAddon = false } = useHasLicenseModule(app.addon);
const { data: workspaceHasInstalledAddon = false } = useHasLicenseModule(app.installedAddon);

const [isLoading, setLoading] = useState(false);
const [requestedEndUser, setRequestedEndUser] = useState(app.requestedEndUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SidePanelOnHold = () => {
const rooms = useSidePanelRoomsListTab('onHold');
const [unreadOnly, toggleUnreadOnly] = useUnreadOnlyToggle();

const hasEEModule = useHasLicenseModule('livechat-enterprise');
const { data: hasEEModule = false } = useHasLicenseModule('livechat-enterprise');
useRedirectToDefaultTab(!hasEEModule);

if (!hasEEModule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const BusinessHoursMultiple = ({ className }: { className?: ComponentProps<typeo
control,
formState: { errors },
} = useFormContext<BusinessHoursFormData>();
const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');

const enabledField = useId();
const nameField = useId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type ContactManagerInputProps = {
};

const ContactManagerInput = ({ value: userId, onChange }: ContactManagerInputProps) => {
const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');

if (!hasLicense) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CurrentChatTagsProps = Pick<ComponentProps<typeof AutoCompleteTagsMultiple>
};

const CurrentChatTags = ({ value, handler, department, viewAll, ...props }: CurrentChatTagsProps) => {
const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');

if (!hasLicense) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const CustomFieldsAdditionalForm = ({ className }: { className?: ComponentProps<
watch,
formState: { errors },
} = useFormContext<EditCustomFieldsFormData>();
const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');

const { visibility, type } = watch();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useHasLicenseModule } from '../../../hooks/useHasLicenseModule';

export const DepartmentBusinessHours = ({ bhId }: { bhId: string | undefined }) => {
const { t } = useTranslation();
const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');
const getBusinessHour = useEndpoint('GET', '/v1/livechat/business-hour');
const { data } = useQuery({
queryKey: ['/v1/livechat/business-hour', bhId],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ComponentProps } from 'react';
import { useHasLicenseModule } from '../../../hooks/useHasLicenseModule';

export const EeNumberInput = ({ label, ...props }: { label: string } & ComponentProps<typeof NumberInput>) => {
const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');

if (!hasLicense) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ComponentProps } from 'react';
import { useHasLicenseModule } from '../../../hooks/useHasLicenseModule';

export const EeTextAreaInput = ({ label, ...props }: { label: string } & ComponentProps<typeof TextAreaInput>) => {
const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');

if (!hasLicense) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ComponentProps } from 'react';
import { useHasLicenseModule } from '../../../hooks/useHasLicenseModule';

export const EeTextInput = ({ label, ...props }: { label: string } & ComponentProps<typeof TextInput>) => {
const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');

if (!hasLicense) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useHasLicenseModule } from '../../../hooks/useHasLicenseModule';
const MaxChatsPerAgent = ({ className }: { className?: ComponentProps<typeof Field>['className'] }) => {
const { t } = useTranslation();
const { control } = useFormContext();
const hasLicense = useHasLicenseModule('livechat-enterprise');
const { data: hasLicense = false } = useHasLicenseModule('livechat-enterprise');

const maxChatsField = useId();

Expand Down
Loading
Loading