From 0e52007dd811d4845fc4048e12c5ff517ad985a3 Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Tue, 9 Jun 2026 23:02:06 -0300 Subject: [PATCH 1/2] refactor: remove unnecessary ReactElement type annotations in RoomAvatarEditor and UserAvatarEditor components (#40825) --- apps/meteor/client/components/avatar/RoomAvatarEditor.tsx | 3 +-- .../components/avatar/UserAvatarEditor/UserAvatarEditor.tsx | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/meteor/client/components/avatar/RoomAvatarEditor.tsx b/apps/meteor/client/components/avatar/RoomAvatarEditor.tsx index 2160f70aee56f..086c2af03735a 100644 --- a/apps/meteor/client/components/avatar/RoomAvatarEditor.tsx +++ b/apps/meteor/client/components/avatar/RoomAvatarEditor.tsx @@ -5,7 +5,6 @@ import { Box, Button, ButtonGroup } from '@rocket.chat/fuselage'; import { useStableCallback } from '@rocket.chat/fuselage-hooks'; import { RoomAvatar } from '@rocket.chat/ui-avatar'; import { useToastMessageDispatch } from '@rocket.chat/ui-contexts'; -import type { ReactElement } from 'react'; import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; @@ -20,7 +19,7 @@ type RoomAvatarEditorProps = { onChangeAvatar: (url: string | null) => void; }; -const RoomAvatarEditor = ({ disabled = false, room, roomAvatar, onChangeAvatar }: RoomAvatarEditorProps): ReactElement => { +const RoomAvatarEditor = ({ disabled = false, room, roomAvatar, onChangeAvatar }: RoomAvatarEditorProps) => { const { t } = useTranslation(); const dispatchToastMessage = useToastMessageDispatch(); diff --git a/apps/meteor/client/components/avatar/UserAvatarEditor/UserAvatarEditor.tsx b/apps/meteor/client/components/avatar/UserAvatarEditor/UserAvatarEditor.tsx index 9694a3ad4f549..194a8f4de910b 100644 --- a/apps/meteor/client/components/avatar/UserAvatarEditor/UserAvatarEditor.tsx +++ b/apps/meteor/client/components/avatar/UserAvatarEditor/UserAvatarEditor.tsx @@ -3,7 +3,7 @@ import { Box, Button, Avatar, IconButton } from '@rocket.chat/fuselage'; import { Field, FieldLabel, FieldRow, FieldError, TextInput } from '@rocket.chat/fuselage-forms'; import { UserAvatar } from '@rocket.chat/ui-avatar'; import { useToastMessageDispatch, useSetting } from '@rocket.chat/ui-contexts'; -import type { ReactElement, ChangeEvent } from 'react'; +import type { ChangeEvent } from 'react'; import { useState, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; @@ -23,7 +23,7 @@ type UserAvatarEditorProps = { name: IUser['name']; }; -function UserAvatarEditor({ currentUsername, username, setAvatarObj, name, disabled, etag }: UserAvatarEditorProps): ReactElement { +function UserAvatarEditor({ currentUsername, username, setAvatarObj, name, disabled, etag }: UserAvatarEditorProps) { const { t } = useTranslation(); const useFullNameForDefaultAvatar = useSetting('UI_Use_Name_Avatar'); const rotateImages = useSetting('FileUpload_RotateImages'); From d6b2293392f88f04b55553ce1421ed2747189634 Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Wed, 10 Jun 2026 00:56:09 -0300 Subject: [PATCH 2/2] refactor: Odd React hooks (#40865) --- .../components/message/MessageCollapsible.tsx | 6 +- .../content/attachments/DefaultAttachment.tsx | 5 +- .../{useLoadImage.tsx => useLoadImage.ts} | 0 ...f.spec.tsx => useOpenEncryptedPdf.spec.ts} | 0 ...ncryptedPdf.tsx => useOpenEncryptedPdf.ts} | 0 ...rror.spec.tsx => useReloadOnError.spec.ts} | 0 ...eReloadOnError.tsx => useReloadOnError.ts} | 0 ....tsx => useToggleReactionMutation.spec.ts} | 0 .../content/urlPreviews/UrlPreview.tsx | 5 +- .../components/message/hooks/useCollapse.ts | 9 + .../components/message/hooks/useCollapse.tsx | 11 - ...utation.tsx => useMarkAsUnreadMutation.ts} | 2 +- ...x => useReadReceiptsDetailsAction.spec.ts} | 0 ...ageAction.tsx => useUnpinMessageAction.ts} | 0 ...omAction.tsx => useVideoCallRoomAction.ts} | 0 ...s.spec.tsx => useAppSlashCommands.spec.ts} | 0 .../client/hooks/useIdleDetection.spec.ts | 223 ++++++++++++++++++ .../client/hooks/useIdleDetection.spec.tsx | 219 ----------------- ...eRoomIcon.spec.tsx => useRoomIcon.spec.ts} | 0 ...s.spec.tsx => useUserCustomFields.spec.ts} | 0 ...sx => useEncryptedRoomDescription.spec.ts} | 0 ...ion.tsx => useEncryptedRoomDescription.ts} | 0 ...reateNewItems.tsx => useCreateNewItems.ts} | 0 ...eCreateNewMenu.tsx => useCreateNewMenu.ts} | 0 ....spec.tsx => useGroupingListItems.spec.ts} | 0 ...spec.tsx => useGrouppingListItems.spec.ts} | 0 ...nu.spec.tsx => useMarketPlaceMenu.spec.ts} | 0 .../hooks/{useSortMenu.tsx => useSortMenu.ts} | 0 ...tems.spec.tsx => useSortModeItems.spec.ts} | 0 ...tems.spec.tsx => useViewModeItems.spec.ts} | 0 ...eUserMenu.spec.tsx => useUserMenu.spec.ts} | 0 ...spec.tsx => useAdministrationMenu.spec.ts} | 2 +- ...ationMenu.tsx => useAdministrationMenu.ts} | 0 ...tsx => useLDAPAndCrowdCollisionWarning.ts} | 0 ...ing.tsx => useEmailVerificationWarning.ts} | 0 ...play.spec.tsx => useUnreadDisplay.spec.ts} | 0 ...RemoveWebDAVAccountIntegrationMutation.ts} | 0 ...s.spec.tsx => useAttributeOptions.spec.ts} | 0 ...al.spec.tsx => useDeleteRoomModal.spec.ts} | 0 ...oomItems.spec.tsx => useRoomItems.spec.ts} | 0 ...mingData.tsx => useExampleIncomingData.ts} | 0 ...tsx => useCancelSubscriptionModal.spec.ts} | 2 +- .../views/admin/users/useShowVoipExtension.ts | 3 + .../admin/users/useShowVoipExtension.tsx | 7 - ...eatureBullets.tsx => useFeatureBullets.ts} | 0 .../{useArchiveRoom.tsx => useArchiveRoom.ts} | 0 ...berList.spec.tsx => useMemberList.spec.ts} | 0 ...play.spec.tsx => useUnreadDisplay.spec.ts} | 0 ...useContactsList.tsx => useContactsList.ts} | 0 ...etadata.tsx => useCustomFieldsMetadata.ts} | 0 ...RoomInfo.tsx => useOmnichannelRoomInfo.ts} | 0 ...usePriorityInfo.tsx => usePriorityInfo.ts} | 0 .../hooks/{useSlaInfo.tsx => useSlaInfo.ts} | 0 .../{useSlaPolicies.tsx => useSlaPolicies.ts} | 0 .../{useVisitorInfo.tsx => useVisitorInfo.ts} | 0 ...sOverMacLimit.tsx => useIsOverMacLimit.ts} | 0 ...rMacLimit.tsx => useIsRoomOverMacLimit.ts} | 0 ...nu.tsx => useOmnichannelPrioritiesMenu.ts} | 6 +- ...useChartContext.tsx => useChartContext.ts} | 0 ...eAgentsSection.tsx => useAgentsSection.ts} | 0 ...nnelsSection.tsx => useChannelsSection.ts} | 0 ...aultDownload.tsx => useDefaultDownload.ts} | 0 ...tsSection.tsx => useDepartmentsSection.ts} | 0 ...eStatusSection.tsx => useStatusSection.ts} | 0 .../{useTagsSection.tsx => useTagsSection.ts} | 0 .../{useFieldError.tsx => useFieldError.ts} | 0 .../{useMessageBody.tsx => useMessageBody.ts} | 0 ....spec.tsx => useVideoConfOpenCall.spec.ts} | 0 ...useBanUser.spec.tsx => useBanUser.spec.ts} | 0 ...oomMutation.tsx => useOpenRoomMutation.ts} | 2 +- ...ion.spec.tsx => useRoomInvitation.spec.ts} | 0 ...oomInvitation.tsx => useRoomInvitation.ts} | 0 ...x => useRoomRejectInvitationModal.spec.ts} | 0 ...nbanUser.spec.tsx => useUnbanUser.spec.ts} | 0 ...eAddUserAction.tsx => useAddUserAction.ts} | 0 ...eBanUserAction.tsx => useBanUserAction.ts} | 0 ...pec.tsx => useUserMediaCallAction.spec.ts} | 0 ...eoCallAction.tsx => useVideoCallAction.ts} | 0 ...oggleAutoJoin.tsx => useToggleAutoJoin.ts} | 0 packages/i18n/src/locales/en.i18n.json | 1 + packages/mock-providers/package.json | 4 +- ...useSetting.spec.tsx => useSetting.spec.ts} | 0 ...eSettings.spec.tsx => useSettings.spec.ts} | 0 ...sence.spec.tsx => useUserPresence.spec.ts} | 0 ...eMenuAction.tsx => useHandleMenuAction.ts} | 0 .../{useWizard.spec.tsx => useWizard.spec.ts} | 56 ++--- .../Wizard/{useWizard.tsx => useWizard.ts} | 18 +- ...eWizardContext.tsx => useWizardContext.ts} | 0 .../{useWizardSteps.tsx => useWizardSteps.ts} | 4 +- ...iew.spec.tsx => useFeaturePreview.spec.ts} | 0 ...> usePreferenceFeaturePreviewList.spec.ts} | 4 +- .../src/components/Keypad/useKeypad.tsx | 45 ---- packages/ui-voip/src/components/index.ts | 1 - ...res.tsx => usePeekMediaSessionFeatures.ts} | 0 ...on.spec.tsx => useMediaCallAction.spec.ts} | 0 .../src/views/MediaCallWidget/OngoingCall.tsx | 33 ++- 96 files changed, 327 insertions(+), 341 deletions(-) rename apps/meteor/client/components/message/content/attachments/file/hooks/{useLoadImage.tsx => useLoadImage.ts} (100%) rename apps/meteor/client/components/message/content/attachments/file/hooks/{useOpenEncryptedPdf.spec.tsx => useOpenEncryptedPdf.spec.ts} (100%) rename apps/meteor/client/components/message/content/attachments/file/hooks/{useOpenEncryptedPdf.tsx => useOpenEncryptedPdf.ts} (100%) rename apps/meteor/client/components/message/content/attachments/file/hooks/{useReloadOnError.spec.tsx => useReloadOnError.spec.ts} (100%) rename apps/meteor/client/components/message/content/attachments/file/hooks/{useReloadOnError.tsx => useReloadOnError.ts} (100%) rename apps/meteor/client/components/message/content/reactions/{useToggleReactionMutation.spec.tsx => useToggleReactionMutation.spec.ts} (100%) create mode 100644 apps/meteor/client/components/message/hooks/useCollapse.ts delete mode 100644 apps/meteor/client/components/message/hooks/useCollapse.tsx rename apps/meteor/client/components/message/hooks/{useMarkAsUnreadMutation.tsx => useMarkAsUnreadMutation.ts} (93%) rename apps/meteor/client/components/message/toolbar/{useReadReceiptsDetailsAction.spec.tsx => useReadReceiptsDetailsAction.spec.ts} (100%) rename apps/meteor/client/components/message/toolbar/{useUnpinMessageAction.tsx => useUnpinMessageAction.ts} (100%) rename apps/meteor/client/hooks/roomActions/{useVideoCallRoomAction.tsx => useVideoCallRoomAction.ts} (100%) rename apps/meteor/client/hooks/{useAppSlashCommands.spec.tsx => useAppSlashCommands.spec.ts} (100%) create mode 100644 apps/meteor/client/hooks/useIdleDetection.spec.ts delete mode 100644 apps/meteor/client/hooks/useIdleDetection.spec.tsx rename apps/meteor/client/hooks/{useRoomIcon.spec.tsx => useRoomIcon.spec.ts} (100%) rename apps/meteor/client/hooks/{useUserCustomFields.spec.tsx => useUserCustomFields.spec.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/actions/{useEncryptedRoomDescription.spec.tsx => useEncryptedRoomDescription.spec.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/actions/{useEncryptedRoomDescription.tsx => useEncryptedRoomDescription.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/hooks/{useCreateNewItems.tsx => useCreateNewItems.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/hooks/{useCreateNewMenu.tsx => useCreateNewMenu.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/hooks/{useGroupingListItems.spec.tsx => useGroupingListItems.spec.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/hooks/{useGrouppingListItems.spec.tsx => useGrouppingListItems.spec.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/hooks/{useMarketPlaceMenu.spec.tsx => useMarketPlaceMenu.spec.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/hooks/{useSortMenu.tsx => useSortMenu.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/hooks/{useSortModeItems.spec.tsx => useSortModeItems.spec.ts} (100%) rename apps/meteor/client/navbar/NavBarPagesGroup/hooks/{useViewModeItems.spec.tsx => useViewModeItems.spec.ts} (100%) rename apps/meteor/client/navbar/NavBarSettingsToolbar/UserMenu/hooks/{useUserMenu.spec.tsx => useUserMenu.spec.ts} (100%) rename apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/{useAdministrationMenu.spec.tsx => useAdministrationMenu.spec.ts} (97%) rename apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/{useAdministrationMenu.tsx => useAdministrationMenu.ts} (100%) rename apps/meteor/client/providers/AuthenticationProvider/hooks/{useLDAPAndCrowdCollisionWarning.tsx => useLDAPAndCrowdCollisionWarning.ts} (100%) rename apps/meteor/client/providers/UserProvider/hooks/{useEmailVerificationWarning.tsx => useEmailVerificationWarning.ts} (100%) rename apps/meteor/client/sidebar/hooks/{useUnreadDisplay.spec.tsx => useUnreadDisplay.spec.ts} (100%) rename apps/meteor/client/views/account/integrations/hooks/{useRemoveWebDAVAccountIntegrationMutation.tsx => useRemoveWebDAVAccountIntegrationMutation.ts} (100%) rename apps/meteor/client/views/admin/ABAC/hooks/{useAttributeOptions.spec.tsx => useAttributeOptions.spec.ts} (100%) rename apps/meteor/client/views/admin/ABAC/hooks/{useDeleteRoomModal.spec.tsx => useDeleteRoomModal.spec.ts} (100%) rename apps/meteor/client/views/admin/ABAC/hooks/{useRoomItems.spec.tsx => useRoomItems.spec.ts} (100%) rename apps/meteor/client/views/admin/integrations/hooks/{useExampleIncomingData.tsx => useExampleIncomingData.ts} (100%) rename apps/meteor/client/views/admin/subscription/hooks/{useCancelSubscriptionModal.spec.tsx => useCancelSubscriptionModal.spec.ts} (98%) create mode 100644 apps/meteor/client/views/admin/users/useShowVoipExtension.ts delete mode 100644 apps/meteor/client/views/admin/users/useShowVoipExtension.tsx rename apps/meteor/client/views/admin/workspace/VersionCard/hooks/{useFeatureBullets.tsx => useFeatureBullets.ts} (100%) rename apps/meteor/client/views/hooks/roomActions/{useArchiveRoom.tsx => useArchiveRoom.ts} (100%) rename apps/meteor/client/views/hooks/{useMemberList.spec.tsx => useMemberList.spec.ts} (100%) rename apps/meteor/client/views/navigation/sidebar/hooks/{useUnreadDisplay.spec.tsx => useUnreadDisplay.spec.ts} (100%) rename apps/meteor/client/views/omnichannel/components/AutoCompleteContact/{useContactsList.tsx => useContactsList.ts} (100%) rename apps/meteor/client/views/omnichannel/directory/hooks/{useCustomFieldsMetadata.tsx => useCustomFieldsMetadata.ts} (100%) rename apps/meteor/client/views/omnichannel/directory/hooks/{useOmnichannelRoomInfo.tsx => useOmnichannelRoomInfo.ts} (100%) rename apps/meteor/client/views/omnichannel/directory/hooks/{usePriorityInfo.tsx => usePriorityInfo.ts} (100%) rename apps/meteor/client/views/omnichannel/directory/hooks/{useSlaInfo.tsx => useSlaInfo.ts} (100%) rename apps/meteor/client/views/omnichannel/directory/hooks/{useSlaPolicies.tsx => useSlaPolicies.ts} (100%) rename apps/meteor/client/views/omnichannel/directory/hooks/{useVisitorInfo.tsx => useVisitorInfo.ts} (100%) rename apps/meteor/client/views/omnichannel/hooks/{useIsOverMacLimit.tsx => useIsOverMacLimit.ts} (100%) rename apps/meteor/client/views/omnichannel/hooks/{useIsRoomOverMacLimit.tsx => useIsRoomOverMacLimit.ts} (100%) rename apps/meteor/client/views/omnichannel/hooks/{useOmnichannelPrioritiesMenu.tsx => useOmnichannelPrioritiesMenu.ts} (94%) rename apps/meteor/client/views/omnichannel/realTimeMonitoring/charts/{useChartContext.tsx => useChartContext.ts} (100%) rename apps/meteor/client/views/omnichannel/reports/hooks/{useAgentsSection.tsx => useAgentsSection.ts} (100%) rename apps/meteor/client/views/omnichannel/reports/hooks/{useChannelsSection.tsx => useChannelsSection.ts} (100%) rename apps/meteor/client/views/omnichannel/reports/hooks/{useDefaultDownload.tsx => useDefaultDownload.ts} (100%) rename apps/meteor/client/views/omnichannel/reports/hooks/{useDepartmentsSection.tsx => useDepartmentsSection.ts} (100%) rename apps/meteor/client/views/omnichannel/reports/hooks/{useStatusSection.tsx => useStatusSection.ts} (100%) rename apps/meteor/client/views/omnichannel/reports/hooks/{useTagsSection.tsx => useTagsSection.ts} (100%) rename apps/meteor/client/views/omnichannel/triggers/hooks/{useFieldError.tsx => useFieldError.ts} (100%) rename apps/meteor/client/views/room/MessageList/hooks/{useMessageBody.tsx => useMessageBody.ts} (100%) rename apps/meteor/client/views/room/contextualBar/VideoConference/hooks/{useVideoConfOpenCall.spec.tsx => useVideoConfOpenCall.spec.ts} (100%) rename apps/meteor/client/views/room/hooks/{useBanUser.spec.tsx => useBanUser.spec.ts} (100%) rename apps/meteor/client/views/room/hooks/{useOpenRoomMutation.tsx => useOpenRoomMutation.ts} (93%) rename apps/meteor/client/views/room/hooks/{useRoomInvitation.spec.tsx => useRoomInvitation.spec.ts} (100%) rename apps/meteor/client/views/room/hooks/{useRoomInvitation.tsx => useRoomInvitation.ts} (100%) rename apps/meteor/client/views/room/hooks/{useRoomRejectInvitationModal.spec.tsx => useRoomRejectInvitationModal.spec.ts} (100%) rename apps/meteor/client/views/room/hooks/{useUnbanUser.spec.tsx => useUnbanUser.spec.ts} (100%) rename apps/meteor/client/views/room/hooks/useUserInfoActions/actions/{useAddUserAction.tsx => useAddUserAction.ts} (100%) rename apps/meteor/client/views/room/hooks/useUserInfoActions/actions/{useBanUserAction.tsx => useBanUserAction.ts} (100%) rename apps/meteor/client/views/room/hooks/useUserInfoActions/actions/{useUserMediaCallAction.spec.tsx => useUserMediaCallAction.spec.ts} (100%) rename apps/meteor/client/views/room/hooks/useUserInfoActions/actions/{useVideoCallAction.tsx => useVideoCallAction.ts} (100%) rename apps/meteor/client/views/teams/contextualBar/channels/hooks/{useToggleAutoJoin.tsx => useToggleAutoJoin.ts} (100%) rename packages/mock-providers/src/tests/{useSetting.spec.tsx => useSetting.spec.ts} (100%) rename packages/mock-providers/src/tests/{useSettings.spec.tsx => useSettings.spec.ts} (100%) rename packages/mock-providers/src/tests/{useUserPresence.spec.tsx => useUserPresence.spec.ts} (100%) rename packages/ui-client/src/components/GenericMenu/hooks/{useHandleMenuAction.tsx => useHandleMenuAction.ts} (100%) rename packages/ui-client/src/components/Wizard/{useWizard.spec.tsx => useWizard.spec.ts} (68%) rename packages/ui-client/src/components/Wizard/{useWizard.tsx => useWizard.ts} (83%) rename packages/ui-client/src/components/Wizard/{useWizardContext.tsx => useWizardContext.ts} (100%) rename packages/ui-client/src/components/Wizard/{useWizardSteps.tsx => useWizardSteps.ts} (85%) rename packages/ui-client/src/hooks/{useFeaturePreview.spec.tsx => useFeaturePreview.spec.ts} (100%) rename packages/ui-client/src/hooks/{usePreferenceFeaturePreviewList.spec.tsx => usePreferenceFeaturePreviewList.spec.ts} (97%) delete mode 100644 packages/ui-voip/src/components/Keypad/useKeypad.tsx rename packages/ui-voip/src/context/{usePeekMediaSessionFeatures.tsx => usePeekMediaSessionFeatures.ts} (100%) rename packages/ui-voip/src/hooks/{useMediaCallAction.spec.tsx => useMediaCallAction.spec.ts} (100%) diff --git a/apps/meteor/client/components/message/MessageCollapsible.tsx b/apps/meteor/client/components/message/MessageCollapsible.tsx index a350cb10262cd..0970fced37ca9 100644 --- a/apps/meteor/client/components/message/MessageCollapsible.tsx +++ b/apps/meteor/client/components/message/MessageCollapsible.tsx @@ -3,6 +3,7 @@ import type { ReactNode } from 'react'; import AttachmentDownload from './content/attachments/structure/AttachmentDownload'; import AttachmentSize from './content/attachments/structure/AttachmentSize'; +import CollapsibleContent from './content/collapsible/CollapsibleContent'; import { useCollapse } from './hooks/useCollapse'; type MessageCollapsibleProps = { @@ -15,7 +16,7 @@ type MessageCollapsibleProps = { }; const MessageCollapsible = ({ children, title, hasDownload, link, size, isCollapsed }: MessageCollapsibleProps) => { - const [collapsed, collapse] = useCollapse(isCollapsed); + const [collapsed, toggleCollapse] = useCollapse(isCollapsed); return ( <> @@ -23,7 +24,8 @@ const MessageCollapsible = ({ children, title, hasDownload, link, size, isCollap {title} - {size && } {collapse} + {size && }{' '} + {hasDownload && link && } {!collapsed && children} diff --git a/apps/meteor/client/components/message/content/attachments/DefaultAttachment.tsx b/apps/meteor/client/components/message/content/attachments/DefaultAttachment.tsx index fcf7d33ca70ca..2d6ae957f7209 100644 --- a/apps/meteor/client/components/message/content/attachments/DefaultAttachment.tsx +++ b/apps/meteor/client/components/message/content/attachments/DefaultAttachment.tsx @@ -16,6 +16,7 @@ import AttachmentThumb from './structure/AttachmentThumb'; import AttachmentTitle from './structure/AttachmentTitle'; import MarkdownText from '../../../MarkdownText'; import { useCollapse } from '../../hooks/useCollapse'; +import CollapsibleContent from '../collapsible/CollapsibleContent'; const applyMarkdownIfRequires = ( list: MessageAttachmentDefault['mrkdwn_in'] = ['text', 'pretext'], @@ -27,7 +28,7 @@ const applyMarkdownIfRequires = ( type DefaultAttachmentProps = MessageAttachmentDefault; const DefaultAttachment = (attachment: DefaultAttachmentProps) => { - const [collapsed, collapse] = useCollapse(!!attachment.collapsed); + const [collapsed, toggleCollapse] = useCollapse(!!attachment.collapsed); return ( { > {attachment.title} {' '} - {collapse} + )} {!collapsed && ( diff --git a/apps/meteor/client/components/message/content/attachments/file/hooks/useLoadImage.tsx b/apps/meteor/client/components/message/content/attachments/file/hooks/useLoadImage.ts similarity index 100% rename from apps/meteor/client/components/message/content/attachments/file/hooks/useLoadImage.tsx rename to apps/meteor/client/components/message/content/attachments/file/hooks/useLoadImage.ts diff --git a/apps/meteor/client/components/message/content/attachments/file/hooks/useOpenEncryptedPdf.spec.tsx b/apps/meteor/client/components/message/content/attachments/file/hooks/useOpenEncryptedPdf.spec.ts similarity index 100% rename from apps/meteor/client/components/message/content/attachments/file/hooks/useOpenEncryptedPdf.spec.tsx rename to apps/meteor/client/components/message/content/attachments/file/hooks/useOpenEncryptedPdf.spec.ts diff --git a/apps/meteor/client/components/message/content/attachments/file/hooks/useOpenEncryptedPdf.tsx b/apps/meteor/client/components/message/content/attachments/file/hooks/useOpenEncryptedPdf.ts similarity index 100% rename from apps/meteor/client/components/message/content/attachments/file/hooks/useOpenEncryptedPdf.tsx rename to apps/meteor/client/components/message/content/attachments/file/hooks/useOpenEncryptedPdf.ts diff --git a/apps/meteor/client/components/message/content/attachments/file/hooks/useReloadOnError.spec.tsx b/apps/meteor/client/components/message/content/attachments/file/hooks/useReloadOnError.spec.ts similarity index 100% rename from apps/meteor/client/components/message/content/attachments/file/hooks/useReloadOnError.spec.tsx rename to apps/meteor/client/components/message/content/attachments/file/hooks/useReloadOnError.spec.ts diff --git a/apps/meteor/client/components/message/content/attachments/file/hooks/useReloadOnError.tsx b/apps/meteor/client/components/message/content/attachments/file/hooks/useReloadOnError.ts similarity index 100% rename from apps/meteor/client/components/message/content/attachments/file/hooks/useReloadOnError.tsx rename to apps/meteor/client/components/message/content/attachments/file/hooks/useReloadOnError.ts diff --git a/apps/meteor/client/components/message/content/reactions/useToggleReactionMutation.spec.tsx b/apps/meteor/client/components/message/content/reactions/useToggleReactionMutation.spec.ts similarity index 100% rename from apps/meteor/client/components/message/content/reactions/useToggleReactionMutation.spec.tsx rename to apps/meteor/client/components/message/content/reactions/useToggleReactionMutation.spec.ts diff --git a/apps/meteor/client/components/message/content/urlPreviews/UrlPreview.tsx b/apps/meteor/client/components/message/content/urlPreviews/UrlPreview.tsx index ef57acb12bba3..dd5da1eb9a7dc 100644 --- a/apps/meteor/client/components/message/content/urlPreviews/UrlPreview.tsx +++ b/apps/meteor/client/components/message/content/urlPreviews/UrlPreview.tsx @@ -5,16 +5,17 @@ import { useTranslation } from 'react-i18next'; import type { UrlPreviewMetadata } from './UrlPreviewMetadata'; import UrlPreviewResolver from './UrlPreviewResolver'; import { useCollapse } from '../../hooks/useCollapse'; +import CollapsibleContent from '../collapsible/CollapsibleContent'; const UrlPreview = (props: UrlPreviewMetadata) => { const autoLoadMedia = useAttachmentAutoLoadEmbedMedia(); - const [collapsed, collapse] = useCollapse(!autoLoadMedia); + const [collapsed, toggleCollapse] = useCollapse(!autoLoadMedia); const { t } = useTranslation(); return ( <> - {t('Link_Preview')} {collapse} + {t('Link_Preview')} {!collapsed && } diff --git a/apps/meteor/client/components/message/hooks/useCollapse.ts b/apps/meteor/client/components/message/hooks/useCollapse.ts new file mode 100644 index 0000000000000..2dd422f37b93c --- /dev/null +++ b/apps/meteor/client/components/message/hooks/useCollapse.ts @@ -0,0 +1,9 @@ +import { useToggle } from '@rocket.chat/fuselage-hooks'; +import { useAttachmentIsCollapsedByDefault } from '@rocket.chat/ui-contexts'; +import { useCallback } from 'react'; + +export const useCollapse = (attachmentCollapsed?: boolean) => { + const collapseByDefault = useAttachmentIsCollapsedByDefault(); + const [collapsed, toggleCollapsed] = useToggle(collapseByDefault || attachmentCollapsed); + return [collapsed, useCallback(() => toggleCollapsed(), [toggleCollapsed])] as const; +}; diff --git a/apps/meteor/client/components/message/hooks/useCollapse.tsx b/apps/meteor/client/components/message/hooks/useCollapse.tsx deleted file mode 100644 index 25598d551e6cb..0000000000000 --- a/apps/meteor/client/components/message/hooks/useCollapse.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { useToggle } from '@rocket.chat/fuselage-hooks'; -import { useAttachmentIsCollapsedByDefault } from '@rocket.chat/ui-contexts'; -import type { ReactNode } from 'react'; - -import CollapsibleContent from '../content/collapsible/CollapsibleContent'; - -export const useCollapse = (attachmentCollapsed?: boolean): [collapsed: boolean, node: ReactNode] => { - const collpaseByDefault = useAttachmentIsCollapsedByDefault(); - const [collapsed, toogleCollapsed] = useToggle(collpaseByDefault || attachmentCollapsed); - return [collapsed, ]; -}; diff --git a/apps/meteor/client/components/message/hooks/useMarkAsUnreadMutation.tsx b/apps/meteor/client/components/message/hooks/useMarkAsUnreadMutation.ts similarity index 93% rename from apps/meteor/client/components/message/hooks/useMarkAsUnreadMutation.tsx rename to apps/meteor/client/components/message/hooks/useMarkAsUnreadMutation.ts index a8d2c0e4f9ba6..17d7b10fddce8 100644 --- a/apps/meteor/client/components/message/hooks/useMarkAsUnreadMutation.tsx +++ b/apps/meteor/client/components/message/hooks/useMarkAsUnreadMutation.ts @@ -18,7 +18,7 @@ export const useMarkAsUnreadMutation = () => { roomId: string; subscription: ISubscription; }) => { - await LegacyRoomManager.close(subscription.t + subscription.name); + LegacyRoomManager.close(subscription.t + subscription.name); if ('message' in props) { const { message } = props; await unreadMessages({ firstUnreadMessage: { _id: message._id } }); diff --git a/apps/meteor/client/components/message/toolbar/useReadReceiptsDetailsAction.spec.tsx b/apps/meteor/client/components/message/toolbar/useReadReceiptsDetailsAction.spec.ts similarity index 100% rename from apps/meteor/client/components/message/toolbar/useReadReceiptsDetailsAction.spec.tsx rename to apps/meteor/client/components/message/toolbar/useReadReceiptsDetailsAction.spec.ts diff --git a/apps/meteor/client/components/message/toolbar/useUnpinMessageAction.tsx b/apps/meteor/client/components/message/toolbar/useUnpinMessageAction.ts similarity index 100% rename from apps/meteor/client/components/message/toolbar/useUnpinMessageAction.tsx rename to apps/meteor/client/components/message/toolbar/useUnpinMessageAction.ts diff --git a/apps/meteor/client/hooks/roomActions/useVideoCallRoomAction.tsx b/apps/meteor/client/hooks/roomActions/useVideoCallRoomAction.ts similarity index 100% rename from apps/meteor/client/hooks/roomActions/useVideoCallRoomAction.tsx rename to apps/meteor/client/hooks/roomActions/useVideoCallRoomAction.ts diff --git a/apps/meteor/client/hooks/useAppSlashCommands.spec.tsx b/apps/meteor/client/hooks/useAppSlashCommands.spec.ts similarity index 100% rename from apps/meteor/client/hooks/useAppSlashCommands.spec.tsx rename to apps/meteor/client/hooks/useAppSlashCommands.spec.ts diff --git a/apps/meteor/client/hooks/useIdleDetection.spec.ts b/apps/meteor/client/hooks/useIdleDetection.spec.ts new file mode 100644 index 0000000000000..22c33bf51c072 --- /dev/null +++ b/apps/meteor/client/hooks/useIdleDetection.spec.ts @@ -0,0 +1,223 @@ +import { faker } from '@faker-js/faker'; +import { renderHook, fireEvent } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { act } from 'react'; + +import { useIdleDetection, DEFAULT_IDLE_DETECTION_OPTIONS } from './useIdleDetection'; + +describe('useIdleDetection', () => { + const idleCallback = jest.fn(); + const activeCallback = jest.fn(); + const changeCallback = jest.fn(); + + // userEvent does not trigger when using `jest.useFakeTimers()` + // because userEvent relies on timers to trigger events + // Setting delay to null ensures the interaction is triggered immediately + // removing this dependency + const user = userEvent.setup({ delay: null }); + + beforeAll(() => { + jest.useFakeTimers(); + }); + + afterAll(() => { + jest.useRealTimers(); + }); + + describe.each([ + ...[60_000, 30_000, 300_000, 3_000_000].flatMap((time) => + [DEFAULT_IDLE_DETECTION_OPTIONS.id, faker.string.uuid()].flatMap((id) => + [false, true].flatMap((awayOnWindowBlur) => ({ + ...DEFAULT_IDLE_DETECTION_OPTIONS, + id, + awayOnWindowBlur, + time, + })), + ), + ), + ])('time: $time, id: $id, awayOnWindowBlur: $awayOnWindowBlur', (args) => { + const eventId = args.id; + const idleDelayMillis = args.time; + + let cleanupEvents: () => void; + + beforeAll(() => { + document.addEventListener(`${eventId}_idle`, idleCallback); + document.addEventListener(`${eventId}_active`, activeCallback); + document.addEventListener(`${eventId}_change`, changeCallback); + + cleanupEvents = () => { + document.removeEventListener(`${eventId}_idle`, idleCallback); + document.removeEventListener(`${eventId}_active`, activeCallback); + document.removeEventListener(`${eventId}_change`, changeCallback); + }; + }); + + afterAll(() => { + cleanupEvents(); + }); + + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('should not dispatch any event on initial render', async () => { + renderHook(() => useIdleDetection(args)); + + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + }); + + it('should dispatch idle event if no interaction before timeout', async () => { + renderHook(() => useIdleDetection(args)); + + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + + act(() => { + jest.advanceTimersByTime(idleDelayMillis + 1); + }); + + expect(idleCallback).toHaveBeenCalledTimes(1); + expect(idleCallback.mock.lastCall?.[0]).toBeInstanceOf(Event); + expect(idleCallback.mock.lastCall?.[0].type).toBe(`${eventId}_idle`); + + expect(activeCallback).toHaveBeenCalledTimes(0); + + expect(changeCallback).toHaveBeenCalledTimes(1); + expect(changeCallback.mock.lastCall?.[0]).toBeInstanceOf(CustomEvent); + expect(changeCallback.mock.lastCall?.[0].type).toBe(`${eventId}_change`); + }); + + if (args.awayOnWindowBlur) { + it('should dispatch idle event on window blur', async () => { + renderHook(() => useIdleDetection(args)); + + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + + fireEvent.blur(window); + + expect(idleCallback).toHaveBeenCalledTimes(1); + expect(idleCallback.mock.lastCall?.[0]).toBeInstanceOf(Event); + expect(idleCallback.mock.lastCall?.[0].type).toBe(`${eventId}_idle`); + + expect(activeCallback).toHaveBeenCalledTimes(0); + + expect(changeCallback).toHaveBeenCalledTimes(1); + expect(changeCallback.mock.lastCall?.[0]).toBeInstanceOf(CustomEvent); + expect(changeCallback.mock.lastCall?.[0].type).toBe(`${eventId}_change`); + }); + } else { + it('should not dispatch idle event on window blur', async () => { + renderHook(() => useIdleDetection(args)); + + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + + fireEvent.blur(window); + + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + }); + } + + it('should dispatch active event if idle after interaction', async () => { + renderHook(() => useIdleDetection(args)); + + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + + // Ensure the idle event is dispatched + act(() => { + jest.advanceTimersByTime(idleDelayMillis + 1); + }); + + expect(idleCallback).toHaveBeenCalledTimes(1); + expect(idleCallback.mock.lastCall?.[0]).toBeInstanceOf(Event); + expect(idleCallback.mock.lastCall?.[0].type).toBe(`${eventId}_idle`); + + expect(activeCallback).toHaveBeenCalledTimes(0); + + expect(changeCallback).toHaveBeenCalledTimes(1); + expect(changeCallback.mock.lastCall?.[0]).toBeInstanceOf(CustomEvent); + expect(changeCallback.mock.lastCall?.[0].type).toBe(`${eventId}_change`); + + await user.click(document.body); + + expect(idleCallback).toHaveBeenCalledTimes(1); + + expect(activeCallback).toHaveBeenCalledTimes(1); + expect(activeCallback.mock.lastCall?.[0]).toBeInstanceOf(Event); + expect(activeCallback.mock.lastCall?.[0].type).toBe(`${eventId}_active`); + + expect(changeCallback).toHaveBeenCalledTimes(2); + expect(changeCallback.mock.lastCall?.[0]).toBeInstanceOf(CustomEvent); + expect(changeCallback.mock.lastCall?.[0].type).toBe(`${eventId}_change`); + }); + + it('should not dispatch any event if active and an interaction happened before timeout', async () => { + renderHook(() => useIdleDetection(args)); + + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + + const halfTime = idleDelayMillis / 2; + + // Advance timers by half the setup time + act(() => { + jest.advanceTimersByTime(halfTime + 1); + }); + + await user.click(document.body); + + // Advance the remainder of the time to ensure the idle event is not dispatched + act(() => { + jest.advanceTimersByTime(halfTime + 1); + }); + + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + }); + + it('should not dispatch any event if idle and no interaction happened before timeout', async () => { + renderHook(() => useIdleDetection(args)); + + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + + act(() => { + jest.advanceTimersByTime(idleDelayMillis + 1); + }); + + expect(idleCallback).toHaveBeenCalledTimes(1); + expect(idleCallback.mock.lastCall?.[0]).toBeInstanceOf(Event); + expect(idleCallback.mock.lastCall?.[0].type).toBe(`${eventId}_idle`); + + expect(activeCallback).toHaveBeenCalledTimes(0); + + expect(changeCallback).toHaveBeenCalledTimes(1); + expect(changeCallback.mock.lastCall?.[0]).toBeInstanceOf(CustomEvent); + expect(changeCallback.mock.lastCall?.[0].type).toBe(`${eventId}_change`); + + jest.clearAllMocks(); + + act(() => { + jest.advanceTimersByTime(idleDelayMillis + 1); + }); + + expect(idleCallback).toHaveBeenCalledTimes(0); + expect(activeCallback).toHaveBeenCalledTimes(0); + expect(changeCallback).toHaveBeenCalledTimes(0); + }); + }); +}); diff --git a/apps/meteor/client/hooks/useIdleDetection.spec.tsx b/apps/meteor/client/hooks/useIdleDetection.spec.tsx deleted file mode 100644 index fddc5cf70f3d8..0000000000000 --- a/apps/meteor/client/hooks/useIdleDetection.spec.tsx +++ /dev/null @@ -1,219 +0,0 @@ -import { faker } from '@faker-js/faker'; -import { renderHook, fireEvent } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; -import { act } from 'react'; - -import { useIdleDetection, DEFAULT_IDLE_DETECTION_OPTIONS, type UseIdleDetectionOptions } from './useIdleDetection'; - -const getEventId = (eventId: string = DEFAULT_IDLE_DETECTION_OPTIONS.id, kind: 'idle' | 'active' | 'change') => `${eventId}_${kind}`; - -const addEventListenersToDocument = ( - { - idleCallback, - activeCallback, - changeCallback, - }: { - idleCallback: (...args: any[]) => void; - activeCallback: (...args: any[]) => void; - changeCallback: (...args: any[]) => void; - }, - eventId: string = DEFAULT_IDLE_DETECTION_OPTIONS.id, -) => { - const idleId = getEventId(eventId, 'idle'); - const activeId = getEventId(eventId, 'active'); - const changeId = getEventId(eventId, 'change'); - - document.addEventListener(idleId, idleCallback); - document.addEventListener(activeId, activeCallback); - document.addEventListener(changeId, changeCallback); - - return () => { - document.removeEventListener(idleId, idleCallback); - document.removeEventListener(activeId, activeCallback); - document.removeEventListener(changeId, changeCallback); - }; -}; - -const expectCallback = function (cb: jest.Mock) { - const withId = (event: Event | CustomEvent) => (eventId: string) => { - expect(event?.type).toBe(eventId); - }; - const withInstance = (instance: unknown) => { - const event = cb.mock.lastCall?.[0]; - expect(event).toBeInstanceOf(instance); - return { withId: withId(event) }; - }; - const toHaveBeenCalledTimes = (times: number) => { - expect(cb).toHaveBeenCalledTimes(times); - return { withInstance }; - }; - - return { toHaveBeenCalledTimes }; -}; - -const getTestVariations = (getOptions: () => Exclude): Required[] => { - return [60, 30, 300, 3000].map((seconds): Required => { - return { ...DEFAULT_IDLE_DETECTION_OPTIONS, time: seconds * 1000, ...getOptions() }; - }); -}; - -const variations = [ - ...getTestVariations(() => ({})), - ...getTestVariations(() => ({ id: faker.string.uuid() })), - ...getTestVariations(() => ({ awayOnWindowBlur: true })), - ...getTestVariations(() => ({ awayOnWindowBlur: true, id: faker.string.uuid() })), -]; - -describe('useIdleDetection', () => { - const activeCallback = jest.fn(); - const idleCallback = jest.fn(); - const changeCallback = jest.fn(); - - // userEvent does not trigger when using `jest.useFakeTimers()` - // because userEvent relies on timers to trigger events - // Setting delay to null ensures the interaction is triggered immediately - // removing this dependency - const user = userEvent.setup({ delay: null }); - - const expectNoCalls = () => { - [idleCallback, activeCallback, changeCallback].forEach((cb) => { - expectCallback(cb).toHaveBeenCalledTimes(0); - }); - }; - - beforeAll(() => { - jest.useFakeTimers(); - }); - - afterAll(() => { - jest.useRealTimers(); - }); - - describe.each(variations)('timeout: $time, id: $id, awayOnWindowBlur: $awayOnWindowBlur', (args) => { - const idleDelayMillis = args.time ?? DEFAULT_IDLE_DETECTION_OPTIONS.time; - const EVENT_ID = args.id ?? DEFAULT_IDLE_DETECTION_OPTIONS.id; - - let cleanupEvents: () => void; - - beforeAll(() => { - cleanupEvents = addEventListenersToDocument({ idleCallback, activeCallback, changeCallback }, EVENT_ID); - }); - - afterAll(() => { - cleanupEvents(); - }); - - beforeEach(() => { - jest.clearAllMocks(); - }); - - it('should not dispatch any event on initial render', async () => { - renderHook(() => useIdleDetection(args)); - - expectNoCalls(); - }); - - it('should dispatch idle event if no interaction before timeout', async () => { - renderHook(() => useIdleDetection(args)); - - expectNoCalls(); - - act(() => { - jest.advanceTimersByTime(idleDelayMillis + 1); - }); - - expectCallback(idleCallback).toHaveBeenCalledTimes(1).withInstance(Event).withId(getEventId(EVENT_ID, 'idle')); - expectCallback(changeCallback).toHaveBeenCalledTimes(1).withInstance(CustomEvent).withId(getEventId(EVENT_ID, 'change')); - expectCallback(activeCallback).toHaveBeenCalledTimes(0); - }); - - if (args.awayOnWindowBlur) { - it('should dispatch idle event on window blur', async () => { - renderHook(() => useIdleDetection(args)); - - expectNoCalls(); - - fireEvent.blur(window); - - expectCallback(idleCallback).toHaveBeenCalledTimes(1).withInstance(Event).withId(getEventId(EVENT_ID, 'idle')); - expectCallback(changeCallback).toHaveBeenCalledTimes(1).withInstance(CustomEvent).withId(getEventId(EVENT_ID, 'change')); - expectCallback(activeCallback).toHaveBeenCalledTimes(0); - }); - } else { - it('should not dispatch idle event on window blur', async () => { - renderHook(() => useIdleDetection(args)); - - expectNoCalls(); - - fireEvent.blur(window); - - expectNoCalls(); - }); - } - - it('should dispatch active event if idle after interaction', async () => { - renderHook(() => useIdleDetection(args)); - - expectNoCalls(); - - // Ensure the idle event is dispatched - act(() => { - jest.advanceTimersByTime(idleDelayMillis + 1); - }); - - expectCallback(idleCallback).toHaveBeenCalledTimes(1).withInstance(Event).withId(getEventId(EVENT_ID, 'idle')); - expectCallback(changeCallback).toHaveBeenCalledTimes(1).withInstance(CustomEvent).withId(getEventId(EVENT_ID, 'change')); - expectCallback(activeCallback).toHaveBeenCalledTimes(0); - - await user.click(document.body); - - expectCallback(activeCallback).toHaveBeenCalledTimes(1).withInstance(Event).withId(getEventId(EVENT_ID, 'active')); - expectCallback(changeCallback).toHaveBeenCalledTimes(2).withInstance(CustomEvent).withId(getEventId(EVENT_ID, 'change')); - expectCallback(idleCallback).toHaveBeenCalledTimes(1); - }); - - it('should not dispatch any event if active and an interaction happened before timeout', async () => { - renderHook(() => useIdleDetection(args)); - - expectNoCalls(); - - const halfTime = idleDelayMillis / 2; - - // Advance timers by half the setup time - act(() => { - jest.advanceTimersByTime(halfTime + 1); - }); - - await user.click(document.body); - - // Advance the remainder of the time to ensure the idle event is not dispatched - act(() => { - jest.advanceTimersByTime(halfTime + 1); - }); - - expectNoCalls(); - }); - - it('should not dispatch any event if idle and no interaction happened before timeout', async () => { - renderHook(() => useIdleDetection(args)); - - expectNoCalls(); - - act(() => { - jest.advanceTimersByTime(idleDelayMillis + 1); - }); - - expectCallback(idleCallback).toHaveBeenCalledTimes(1).withInstance(Event).withId(getEventId(EVENT_ID, 'idle')); - expectCallback(changeCallback).toHaveBeenCalledTimes(1).withInstance(CustomEvent).withId(getEventId(EVENT_ID, 'change')); - expectCallback(activeCallback).toHaveBeenCalledTimes(0); - - jest.clearAllMocks(); - - act(() => { - jest.advanceTimersByTime(idleDelayMillis + 1); - }); - - expectNoCalls(); - }); - }); -}); diff --git a/apps/meteor/client/hooks/useRoomIcon.spec.tsx b/apps/meteor/client/hooks/useRoomIcon.spec.ts similarity index 100% rename from apps/meteor/client/hooks/useRoomIcon.spec.tsx rename to apps/meteor/client/hooks/useRoomIcon.spec.ts diff --git a/apps/meteor/client/hooks/useUserCustomFields.spec.tsx b/apps/meteor/client/hooks/useUserCustomFields.spec.ts similarity index 100% rename from apps/meteor/client/hooks/useUserCustomFields.spec.tsx rename to apps/meteor/client/hooks/useUserCustomFields.spec.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/actions/useEncryptedRoomDescription.spec.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/actions/useEncryptedRoomDescription.spec.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/actions/useEncryptedRoomDescription.spec.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/actions/useEncryptedRoomDescription.spec.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/actions/useEncryptedRoomDescription.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/actions/useEncryptedRoomDescription.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/actions/useEncryptedRoomDescription.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/actions/useEncryptedRoomDescription.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewItems.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewItems.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewItems.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewItems.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useGroupingListItems.spec.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useGroupingListItems.spec.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/hooks/useGroupingListItems.spec.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/hooks/useGroupingListItems.spec.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useGrouppingListItems.spec.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useGrouppingListItems.spec.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/hooks/useGrouppingListItems.spec.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/hooks/useGrouppingListItems.spec.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useMarketPlaceMenu.spec.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useMarketPlaceMenu.spec.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/hooks/useMarketPlaceMenu.spec.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/hooks/useMarketPlaceMenu.spec.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useSortMenu.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useSortMenu.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/hooks/useSortMenu.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/hooks/useSortMenu.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useSortModeItems.spec.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useSortModeItems.spec.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/hooks/useSortModeItems.spec.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/hooks/useSortModeItems.spec.ts diff --git a/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useViewModeItems.spec.tsx b/apps/meteor/client/navbar/NavBarPagesGroup/hooks/useViewModeItems.spec.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarPagesGroup/hooks/useViewModeItems.spec.tsx rename to apps/meteor/client/navbar/NavBarPagesGroup/hooks/useViewModeItems.spec.ts diff --git a/apps/meteor/client/navbar/NavBarSettingsToolbar/UserMenu/hooks/useUserMenu.spec.tsx b/apps/meteor/client/navbar/NavBarSettingsToolbar/UserMenu/hooks/useUserMenu.spec.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarSettingsToolbar/UserMenu/hooks/useUserMenu.spec.tsx rename to apps/meteor/client/navbar/NavBarSettingsToolbar/UserMenu/hooks/useUserMenu.spec.ts diff --git a/apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.tsx b/apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.ts similarity index 97% rename from apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.tsx rename to apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.ts index 6eb991ca61afb..7ec820c09c1bd 100644 --- a/apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.tsx +++ b/apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.ts @@ -3,7 +3,7 @@ import { renderHook, waitFor } from '@testing-library/react'; import { useAdministrationMenu } from './useAdministrationMenu'; -it('should return omnichannel item if has `view-livechat-manager` permission ', async () => { +it('should return omnichannel item if has `view-livechat-manager` permission', async () => { const { result } = renderHook(() => useAdministrationMenu(), { wrapper: mockAppRoot() .withEndpoint('GET', '/v1/licenses.info', () => ({ diff --git a/apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.tsx b/apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.ts similarity index 100% rename from apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.tsx rename to apps/meteor/client/navbar/NavBarSettingsToolbar/hooks/useAdministrationMenu.ts diff --git a/apps/meteor/client/providers/AuthenticationProvider/hooks/useLDAPAndCrowdCollisionWarning.tsx b/apps/meteor/client/providers/AuthenticationProvider/hooks/useLDAPAndCrowdCollisionWarning.ts similarity index 100% rename from apps/meteor/client/providers/AuthenticationProvider/hooks/useLDAPAndCrowdCollisionWarning.tsx rename to apps/meteor/client/providers/AuthenticationProvider/hooks/useLDAPAndCrowdCollisionWarning.ts diff --git a/apps/meteor/client/providers/UserProvider/hooks/useEmailVerificationWarning.tsx b/apps/meteor/client/providers/UserProvider/hooks/useEmailVerificationWarning.ts similarity index 100% rename from apps/meteor/client/providers/UserProvider/hooks/useEmailVerificationWarning.tsx rename to apps/meteor/client/providers/UserProvider/hooks/useEmailVerificationWarning.ts diff --git a/apps/meteor/client/sidebar/hooks/useUnreadDisplay.spec.tsx b/apps/meteor/client/sidebar/hooks/useUnreadDisplay.spec.ts similarity index 100% rename from apps/meteor/client/sidebar/hooks/useUnreadDisplay.spec.tsx rename to apps/meteor/client/sidebar/hooks/useUnreadDisplay.spec.ts diff --git a/apps/meteor/client/views/account/integrations/hooks/useRemoveWebDAVAccountIntegrationMutation.tsx b/apps/meteor/client/views/account/integrations/hooks/useRemoveWebDAVAccountIntegrationMutation.ts similarity index 100% rename from apps/meteor/client/views/account/integrations/hooks/useRemoveWebDAVAccountIntegrationMutation.tsx rename to apps/meteor/client/views/account/integrations/hooks/useRemoveWebDAVAccountIntegrationMutation.ts diff --git a/apps/meteor/client/views/admin/ABAC/hooks/useAttributeOptions.spec.tsx b/apps/meteor/client/views/admin/ABAC/hooks/useAttributeOptions.spec.ts similarity index 100% rename from apps/meteor/client/views/admin/ABAC/hooks/useAttributeOptions.spec.tsx rename to apps/meteor/client/views/admin/ABAC/hooks/useAttributeOptions.spec.ts diff --git a/apps/meteor/client/views/admin/ABAC/hooks/useDeleteRoomModal.spec.tsx b/apps/meteor/client/views/admin/ABAC/hooks/useDeleteRoomModal.spec.ts similarity index 100% rename from apps/meteor/client/views/admin/ABAC/hooks/useDeleteRoomModal.spec.tsx rename to apps/meteor/client/views/admin/ABAC/hooks/useDeleteRoomModal.spec.ts diff --git a/apps/meteor/client/views/admin/ABAC/hooks/useRoomItems.spec.tsx b/apps/meteor/client/views/admin/ABAC/hooks/useRoomItems.spec.ts similarity index 100% rename from apps/meteor/client/views/admin/ABAC/hooks/useRoomItems.spec.tsx rename to apps/meteor/client/views/admin/ABAC/hooks/useRoomItems.spec.ts diff --git a/apps/meteor/client/views/admin/integrations/hooks/useExampleIncomingData.tsx b/apps/meteor/client/views/admin/integrations/hooks/useExampleIncomingData.ts similarity index 100% rename from apps/meteor/client/views/admin/integrations/hooks/useExampleIncomingData.tsx rename to apps/meteor/client/views/admin/integrations/hooks/useExampleIncomingData.ts diff --git a/apps/meteor/client/views/admin/subscription/hooks/useCancelSubscriptionModal.spec.tsx b/apps/meteor/client/views/admin/subscription/hooks/useCancelSubscriptionModal.spec.ts similarity index 98% rename from apps/meteor/client/views/admin/subscription/hooks/useCancelSubscriptionModal.spec.tsx rename to apps/meteor/client/views/admin/subscription/hooks/useCancelSubscriptionModal.spec.ts index e3e0be4182376..7b07bfcd41606 100644 --- a/apps/meteor/client/views/admin/subscription/hooks/useCancelSubscriptionModal.spec.tsx +++ b/apps/meteor/client/views/admin/subscription/hooks/useCancelSubscriptionModal.spec.ts @@ -61,7 +61,7 @@ it('should call remove license endpoint when confirm is clicked', async () => { await userEvent.click(screen.getByRole('button', { name: 'Cancel_subscription' })); expect(result.current.isLoading).toBeTruthy(); - await act(() => resolve({ success: true })); + act(() => resolve({ success: true })); await waitFor(() => expect(result.current.isLoading).toBeFalsy()); expect(removeLicenseEndpoint).toHaveBeenCalled(); diff --git a/apps/meteor/client/views/admin/users/useShowVoipExtension.ts b/apps/meteor/client/views/admin/users/useShowVoipExtension.ts new file mode 100644 index 0000000000000..b025a37b73f2b --- /dev/null +++ b/apps/meteor/client/views/admin/users/useShowVoipExtension.ts @@ -0,0 +1,3 @@ +import { useSetting } from '@rocket.chat/ui-contexts'; + +export const useShowVoipExtension = () => useSetting('VoIP_TeamCollab_SIP_Integration_Enabled', false); diff --git a/apps/meteor/client/views/admin/users/useShowVoipExtension.tsx b/apps/meteor/client/views/admin/users/useShowVoipExtension.tsx deleted file mode 100644 index 0adaca013b2bf..0000000000000 --- a/apps/meteor/client/views/admin/users/useShowVoipExtension.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import { useSetting } from '@rocket.chat/ui-contexts'; - -export const useShowVoipExtension = () => { - const isVoipSettingEnabled = useSetting('VoIP_TeamCollab_SIP_Integration_Enabled', false); - - return isVoipSettingEnabled; -}; diff --git a/apps/meteor/client/views/admin/workspace/VersionCard/hooks/useFeatureBullets.tsx b/apps/meteor/client/views/admin/workspace/VersionCard/hooks/useFeatureBullets.ts similarity index 100% rename from apps/meteor/client/views/admin/workspace/VersionCard/hooks/useFeatureBullets.tsx rename to apps/meteor/client/views/admin/workspace/VersionCard/hooks/useFeatureBullets.ts diff --git a/apps/meteor/client/views/hooks/roomActions/useArchiveRoom.tsx b/apps/meteor/client/views/hooks/roomActions/useArchiveRoom.ts similarity index 100% rename from apps/meteor/client/views/hooks/roomActions/useArchiveRoom.tsx rename to apps/meteor/client/views/hooks/roomActions/useArchiveRoom.ts diff --git a/apps/meteor/client/views/hooks/useMemberList.spec.tsx b/apps/meteor/client/views/hooks/useMemberList.spec.ts similarity index 100% rename from apps/meteor/client/views/hooks/useMemberList.spec.tsx rename to apps/meteor/client/views/hooks/useMemberList.spec.ts diff --git a/apps/meteor/client/views/navigation/sidebar/hooks/useUnreadDisplay.spec.tsx b/apps/meteor/client/views/navigation/sidebar/hooks/useUnreadDisplay.spec.ts similarity index 100% rename from apps/meteor/client/views/navigation/sidebar/hooks/useUnreadDisplay.spec.tsx rename to apps/meteor/client/views/navigation/sidebar/hooks/useUnreadDisplay.spec.ts diff --git a/apps/meteor/client/views/omnichannel/components/AutoCompleteContact/useContactsList.tsx b/apps/meteor/client/views/omnichannel/components/AutoCompleteContact/useContactsList.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/components/AutoCompleteContact/useContactsList.tsx rename to apps/meteor/client/views/omnichannel/components/AutoCompleteContact/useContactsList.ts diff --git a/apps/meteor/client/views/omnichannel/directory/hooks/useCustomFieldsMetadata.tsx b/apps/meteor/client/views/omnichannel/directory/hooks/useCustomFieldsMetadata.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/directory/hooks/useCustomFieldsMetadata.tsx rename to apps/meteor/client/views/omnichannel/directory/hooks/useCustomFieldsMetadata.ts diff --git a/apps/meteor/client/views/omnichannel/directory/hooks/useOmnichannelRoomInfo.tsx b/apps/meteor/client/views/omnichannel/directory/hooks/useOmnichannelRoomInfo.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/directory/hooks/useOmnichannelRoomInfo.tsx rename to apps/meteor/client/views/omnichannel/directory/hooks/useOmnichannelRoomInfo.ts diff --git a/apps/meteor/client/views/omnichannel/directory/hooks/usePriorityInfo.tsx b/apps/meteor/client/views/omnichannel/directory/hooks/usePriorityInfo.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/directory/hooks/usePriorityInfo.tsx rename to apps/meteor/client/views/omnichannel/directory/hooks/usePriorityInfo.ts diff --git a/apps/meteor/client/views/omnichannel/directory/hooks/useSlaInfo.tsx b/apps/meteor/client/views/omnichannel/directory/hooks/useSlaInfo.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/directory/hooks/useSlaInfo.tsx rename to apps/meteor/client/views/omnichannel/directory/hooks/useSlaInfo.ts diff --git a/apps/meteor/client/views/omnichannel/directory/hooks/useSlaPolicies.tsx b/apps/meteor/client/views/omnichannel/directory/hooks/useSlaPolicies.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/directory/hooks/useSlaPolicies.tsx rename to apps/meteor/client/views/omnichannel/directory/hooks/useSlaPolicies.ts diff --git a/apps/meteor/client/views/omnichannel/directory/hooks/useVisitorInfo.tsx b/apps/meteor/client/views/omnichannel/directory/hooks/useVisitorInfo.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/directory/hooks/useVisitorInfo.tsx rename to apps/meteor/client/views/omnichannel/directory/hooks/useVisitorInfo.ts diff --git a/apps/meteor/client/views/omnichannel/hooks/useIsOverMacLimit.tsx b/apps/meteor/client/views/omnichannel/hooks/useIsOverMacLimit.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/hooks/useIsOverMacLimit.tsx rename to apps/meteor/client/views/omnichannel/hooks/useIsOverMacLimit.ts diff --git a/apps/meteor/client/views/omnichannel/hooks/useIsRoomOverMacLimit.tsx b/apps/meteor/client/views/omnichannel/hooks/useIsRoomOverMacLimit.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/hooks/useIsRoomOverMacLimit.tsx rename to apps/meteor/client/views/omnichannel/hooks/useIsRoomOverMacLimit.ts diff --git a/apps/meteor/client/views/omnichannel/hooks/useOmnichannelPrioritiesMenu.tsx b/apps/meteor/client/views/omnichannel/hooks/useOmnichannelPrioritiesMenu.ts similarity index 94% rename from apps/meteor/client/views/omnichannel/hooks/useOmnichannelPrioritiesMenu.tsx rename to apps/meteor/client/views/omnichannel/hooks/useOmnichannelPrioritiesMenu.ts index 24487154f3c81..4cb8226b8a583 100644 --- a/apps/meteor/client/views/omnichannel/hooks/useOmnichannelPrioritiesMenu.tsx +++ b/apps/meteor/client/views/omnichannel/hooks/useOmnichannelPrioritiesMenu.ts @@ -20,7 +20,11 @@ export const useOmnichannelPrioritiesMenu = (rid: IRoom['_id']) => { return useMemo(() => { const handlePriorityChange = (priorityId: string) => async () => { try { - priorityId ? await updateRoomPriority({ priorityId }) : await removeRoomPriority(); + if (priorityId) { + await updateRoomPriority({ priorityId }); + } else { + await removeRoomPriority(); + } queryClient.invalidateQueries({ queryKey: ['current-chats'] }); queryClient.invalidateQueries({ queryKey: roomsQueryKeys.info(rid) }); } catch (error) { diff --git a/apps/meteor/client/views/omnichannel/realTimeMonitoring/charts/useChartContext.tsx b/apps/meteor/client/views/omnichannel/realTimeMonitoring/charts/useChartContext.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/realTimeMonitoring/charts/useChartContext.tsx rename to apps/meteor/client/views/omnichannel/realTimeMonitoring/charts/useChartContext.ts diff --git a/apps/meteor/client/views/omnichannel/reports/hooks/useAgentsSection.tsx b/apps/meteor/client/views/omnichannel/reports/hooks/useAgentsSection.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/reports/hooks/useAgentsSection.tsx rename to apps/meteor/client/views/omnichannel/reports/hooks/useAgentsSection.ts diff --git a/apps/meteor/client/views/omnichannel/reports/hooks/useChannelsSection.tsx b/apps/meteor/client/views/omnichannel/reports/hooks/useChannelsSection.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/reports/hooks/useChannelsSection.tsx rename to apps/meteor/client/views/omnichannel/reports/hooks/useChannelsSection.ts diff --git a/apps/meteor/client/views/omnichannel/reports/hooks/useDefaultDownload.tsx b/apps/meteor/client/views/omnichannel/reports/hooks/useDefaultDownload.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/reports/hooks/useDefaultDownload.tsx rename to apps/meteor/client/views/omnichannel/reports/hooks/useDefaultDownload.ts diff --git a/apps/meteor/client/views/omnichannel/reports/hooks/useDepartmentsSection.tsx b/apps/meteor/client/views/omnichannel/reports/hooks/useDepartmentsSection.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/reports/hooks/useDepartmentsSection.tsx rename to apps/meteor/client/views/omnichannel/reports/hooks/useDepartmentsSection.ts diff --git a/apps/meteor/client/views/omnichannel/reports/hooks/useStatusSection.tsx b/apps/meteor/client/views/omnichannel/reports/hooks/useStatusSection.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/reports/hooks/useStatusSection.tsx rename to apps/meteor/client/views/omnichannel/reports/hooks/useStatusSection.ts diff --git a/apps/meteor/client/views/omnichannel/reports/hooks/useTagsSection.tsx b/apps/meteor/client/views/omnichannel/reports/hooks/useTagsSection.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/reports/hooks/useTagsSection.tsx rename to apps/meteor/client/views/omnichannel/reports/hooks/useTagsSection.ts diff --git a/apps/meteor/client/views/omnichannel/triggers/hooks/useFieldError.tsx b/apps/meteor/client/views/omnichannel/triggers/hooks/useFieldError.ts similarity index 100% rename from apps/meteor/client/views/omnichannel/triggers/hooks/useFieldError.tsx rename to apps/meteor/client/views/omnichannel/triggers/hooks/useFieldError.ts diff --git a/apps/meteor/client/views/room/MessageList/hooks/useMessageBody.tsx b/apps/meteor/client/views/room/MessageList/hooks/useMessageBody.ts similarity index 100% rename from apps/meteor/client/views/room/MessageList/hooks/useMessageBody.tsx rename to apps/meteor/client/views/room/MessageList/hooks/useMessageBody.ts diff --git a/apps/meteor/client/views/room/contextualBar/VideoConference/hooks/useVideoConfOpenCall.spec.tsx b/apps/meteor/client/views/room/contextualBar/VideoConference/hooks/useVideoConfOpenCall.spec.ts similarity index 100% rename from apps/meteor/client/views/room/contextualBar/VideoConference/hooks/useVideoConfOpenCall.spec.tsx rename to apps/meteor/client/views/room/contextualBar/VideoConference/hooks/useVideoConfOpenCall.spec.ts diff --git a/apps/meteor/client/views/room/hooks/useBanUser.spec.tsx b/apps/meteor/client/views/room/hooks/useBanUser.spec.ts similarity index 100% rename from apps/meteor/client/views/room/hooks/useBanUser.spec.tsx rename to apps/meteor/client/views/room/hooks/useBanUser.spec.ts diff --git a/apps/meteor/client/views/room/hooks/useOpenRoomMutation.tsx b/apps/meteor/client/views/room/hooks/useOpenRoomMutation.ts similarity index 93% rename from apps/meteor/client/views/room/hooks/useOpenRoomMutation.tsx rename to apps/meteor/client/views/room/hooks/useOpenRoomMutation.ts index 65fbe785bffc9..5eec2267e279e 100644 --- a/apps/meteor/client/views/room/hooks/useOpenRoomMutation.tsx +++ b/apps/meteor/client/views/room/hooks/useOpenRoomMutation.ts @@ -26,7 +26,7 @@ export const useOpenRoomMutation = () => { } const { open } = rollbackDocument; - await updateSubscription(roomId, userId, { open }); + updateSubscription(roomId, userId, { open }); }, }); }; diff --git a/apps/meteor/client/views/room/hooks/useRoomInvitation.spec.tsx b/apps/meteor/client/views/room/hooks/useRoomInvitation.spec.ts similarity index 100% rename from apps/meteor/client/views/room/hooks/useRoomInvitation.spec.tsx rename to apps/meteor/client/views/room/hooks/useRoomInvitation.spec.ts diff --git a/apps/meteor/client/views/room/hooks/useRoomInvitation.tsx b/apps/meteor/client/views/room/hooks/useRoomInvitation.ts similarity index 100% rename from apps/meteor/client/views/room/hooks/useRoomInvitation.tsx rename to apps/meteor/client/views/room/hooks/useRoomInvitation.ts diff --git a/apps/meteor/client/views/room/hooks/useRoomRejectInvitationModal.spec.tsx b/apps/meteor/client/views/room/hooks/useRoomRejectInvitationModal.spec.ts similarity index 100% rename from apps/meteor/client/views/room/hooks/useRoomRejectInvitationModal.spec.tsx rename to apps/meteor/client/views/room/hooks/useRoomRejectInvitationModal.spec.ts diff --git a/apps/meteor/client/views/room/hooks/useUnbanUser.spec.tsx b/apps/meteor/client/views/room/hooks/useUnbanUser.spec.ts similarity index 100% rename from apps/meteor/client/views/room/hooks/useUnbanUser.spec.tsx rename to apps/meteor/client/views/room/hooks/useUnbanUser.spec.ts diff --git a/apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useAddUserAction.tsx b/apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useAddUserAction.ts similarity index 100% rename from apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useAddUserAction.tsx rename to apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useAddUserAction.ts diff --git a/apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useBanUserAction.tsx b/apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useBanUserAction.ts similarity index 100% rename from apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useBanUserAction.tsx rename to apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useBanUserAction.ts diff --git a/apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useUserMediaCallAction.spec.tsx b/apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useUserMediaCallAction.spec.ts similarity index 100% rename from apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useUserMediaCallAction.spec.tsx rename to apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useUserMediaCallAction.spec.ts diff --git a/apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useVideoCallAction.tsx b/apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useVideoCallAction.ts similarity index 100% rename from apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useVideoCallAction.tsx rename to apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useVideoCallAction.ts diff --git a/apps/meteor/client/views/teams/contextualBar/channels/hooks/useToggleAutoJoin.tsx b/apps/meteor/client/views/teams/contextualBar/channels/hooks/useToggleAutoJoin.ts similarity index 100% rename from apps/meteor/client/views/teams/contextualBar/channels/hooks/useToggleAutoJoin.tsx rename to apps/meteor/client/views/teams/contextualBar/channels/hooks/useToggleAutoJoin.ts diff --git a/packages/i18n/src/locales/en.i18n.json b/packages/i18n/src/locales/en.i18n.json index 6d06dfd8b6ad8..2ca1a3a512464 100644 --- a/packages/i18n/src/locales/en.i18n.json +++ b/packages/i18n/src/locales/en.i18n.json @@ -1809,6 +1809,7 @@ "Devices_Set": "Devices Set", "Dialed_number_doesnt_exist": "Dialed number doesn't exist", "Dialed_number_is_incomplete": "Dialed number is not complete", + "Dialpad": "Dialpad", "Different_Style_For_User_Mentions": "Different style for user mentions", "Direct": "Direct", "DirectMesssage_maxUsers": "Max users in direct messages", diff --git a/packages/mock-providers/package.json b/packages/mock-providers/package.json index 351fba9632187..2dca880571aca 100644 --- a/packages/mock-providers/package.json +++ b/packages/mock-providers/package.json @@ -11,7 +11,9 @@ "build": "rm -rf dist && tsc -p tsconfig.json", "dev": "tsc -p tsconfig.json --watch --preserveWatchOutput", "lint": "eslint .", - "lint:fix": "eslint --fix ." + "lint:fix": "eslint --fix .", + "test": "jest", + "testunit": "jest" }, "dependencies": { "@rocket.chat/emitter": "^0.32.0", diff --git a/packages/mock-providers/src/tests/useSetting.spec.tsx b/packages/mock-providers/src/tests/useSetting.spec.ts similarity index 100% rename from packages/mock-providers/src/tests/useSetting.spec.tsx rename to packages/mock-providers/src/tests/useSetting.spec.ts diff --git a/packages/mock-providers/src/tests/useSettings.spec.tsx b/packages/mock-providers/src/tests/useSettings.spec.ts similarity index 100% rename from packages/mock-providers/src/tests/useSettings.spec.tsx rename to packages/mock-providers/src/tests/useSettings.spec.ts diff --git a/packages/mock-providers/src/tests/useUserPresence.spec.tsx b/packages/mock-providers/src/tests/useUserPresence.spec.ts similarity index 100% rename from packages/mock-providers/src/tests/useUserPresence.spec.tsx rename to packages/mock-providers/src/tests/useUserPresence.spec.ts diff --git a/packages/ui-client/src/components/GenericMenu/hooks/useHandleMenuAction.tsx b/packages/ui-client/src/components/GenericMenu/hooks/useHandleMenuAction.ts similarity index 100% rename from packages/ui-client/src/components/GenericMenu/hooks/useHandleMenuAction.tsx rename to packages/ui-client/src/components/GenericMenu/hooks/useHandleMenuAction.ts diff --git a/packages/ui-client/src/components/Wizard/useWizard.spec.tsx b/packages/ui-client/src/components/Wizard/useWizard.spec.ts similarity index 68% rename from packages/ui-client/src/components/Wizard/useWizard.spec.tsx rename to packages/ui-client/src/components/Wizard/useWizard.spec.ts index 4fd04ccdff085..0a10973936fdc 100644 --- a/packages/ui-client/src/components/Wizard/useWizard.spec.tsx +++ b/packages/ui-client/src/components/Wizard/useWizard.spec.ts @@ -15,117 +15,117 @@ describe('useWizard', () => { expect(result.current.currentStep?.id).toBe('step1'); }); - it('should navigate to the next step and enable it', async () => { + it('should navigate to the next step and enable it', () => { const { result } = renderHook(() => useWizard({ steps: initialSteps })); expect(result.current.steps.get('step2')?.disabled).toBe(true); - await act(() => result.current.next()); + act(() => result.current.next()); expect(result.current.currentStep?.id).toBe('step2'); expect(result.current.steps.get('step2')?.disabled).toBe(false); }); - it('should not navigate if there is no next step', async () => { + it('should not navigate if there is no next step', () => { const { result } = renderHook(() => useWizard({ steps: initialSteps })); - await act(() => result.current.next()); // To step2 - await act(() => result.current.next()); // To step3 + act(() => result.current.next()); // To step2 + act(() => result.current.next()); // To step3 expect(result.current.currentStep?.id).toBe('step3'); - await act(() => result.current.next()); // Already at the end + act(() => result.current.next()); // Already at the end expect(result.current.currentStep?.id).toBe('step3'); }); - it('should navigate to the previous step', async () => { + it('should navigate to the previous step', () => { const { result } = renderHook(() => useWizard({ steps: initialSteps })); - await act(() => result.current.next()); + act(() => result.current.next()); expect(result.current.currentStep?.id).toBe('step2'); - await act(() => result.current.previous()); + act(() => result.current.previous()); expect(result.current.currentStep?.id).toBe('step1'); }); - it('should not navigate if there is no previous step', async () => { + it('should not navigate if there is no previous step', () => { const { result } = renderHook(() => useWizard({ steps: initialSteps })); expect(result.current.currentStep?.id).toBe('step1'); - await act(() => result.current.previous()); + act(() => result.current.previous()); expect(result.current.currentStep?.id).toBe('step1'); }); - it('should navigate to a specific step if it is enabled', async () => { + it('should navigate to a specific step if it is enabled', () => { const { result } = renderHook(() => useWizard({ steps: initialSteps })); - await act(() => { + act(() => { const step3 = result.current.steps.get('step3'); - step3 && result.current.steps.enableStep(step3); + if (step3) result.current.steps.enableStep(step3); }); - await act(() => { + act(() => { const step3 = result.current.steps.get('step3'); - step3 && result.current.goTo(step3); + if (step3) result.current.goTo(step3); }); expect(result.current.currentStep?.id).toBe('step3'); }); - it('should not navigate to a specific step if it is disabled', async () => { + it('should not navigate to a specific step if it is disabled', () => { const { result } = renderHook(() => useWizard({ steps: initialSteps })); expect(result.current.steps.get('step3')?.disabled).toBe(true); - await act(() => { + act(() => { const step3 = result.current.steps.get('step3'); - step3 && result.current.goTo(step3); + if (step3) result.current.goTo(step3); }); expect(result.current.currentStep?.id).toBe('step1'); }); - it('should disable all steps after the current one', async () => { + it('should disable all steps after the current one', () => { const { result } = renderHook(() => useWizard({ steps: initialSteps })); // Enable all steps - await act(() => result.current.next()); - await act(() => result.current.next()); + act(() => result.current.next()); + act(() => result.current.next()); expect(result.current.steps.get('step2')?.disabled).toBe(false); expect(result.current.steps.get('step3')?.disabled).toBe(false); // Go back to step 1 - await act(() => { + act(() => { const step1 = result.current.steps.get('step1'); - step1 && result.current.goTo(step1); + if (step1) result.current.goTo(step1); }); // Reset - await act(() => result.current.resetNextSteps()); + act(() => result.current.resetNextSteps()); expect(result.current.steps.get('step2')?.disabled).toBe(true); expect(result.current.steps.get('step3')?.disabled).toBe(true); }); - it('should register a new step and allow unregistering it', async () => { + it('should register a new step and allow unregistering it', () => { const { result } = renderHook(() => useWizard({ steps: initialSteps })); expect(result.current.steps.get('step4')).toBeNull(); let unregister: () => void; - await act(() => { + act(() => { unregister = result.current.register({ id: 'step4', title: 'Step 4' }); }); expect(result.current.steps.get('step4')?.id).toBe('step4'); - await act(() => unregister()); + act(() => unregister()); expect(result.current.steps.get('step4')).toBeNull(); }); diff --git a/packages/ui-client/src/components/Wizard/useWizard.tsx b/packages/ui-client/src/components/Wizard/useWizard.ts similarity index 83% rename from packages/ui-client/src/components/Wizard/useWizard.tsx rename to packages/ui-client/src/components/Wizard/useWizard.ts index c64a09a1e3c1d..e99603fc3ad7b 100644 --- a/packages/ui-client/src/components/Wizard/useWizard.tsx +++ b/packages/ui-client/src/components/Wizard/useWizard.ts @@ -14,10 +14,10 @@ type UseWizardProps = { * Custom hook to manage the state and navigation of a wizard. * It provides methods to register steps, navigate between them, and manage their state. * - * @param {UseWizardProps} props - The properties for the wizard. - * @returns {WizardAPI} The API for managing the wizard state and navigation. + * @param props - The properties for the wizard. + * @returns The API for managing the wizard state and navigation. */ -export const useWizard = ({ steps: stepsMetadata }: UseWizardProps) => { +export const useWizard = ({ steps: stepsMetadata }: UseWizardProps): WizardAPI => { const [steps] = useState(new StepsLinkedList(stepsMetadata)); const [currentStep, setCurrentStep] = useState(steps.head); @@ -34,9 +34,9 @@ export const useWizard = ({ steps: stepsMetadata }: UseWizardProps) => { * Navigates to a specific step in the wizard. * If the step is disabled, it does nothing. * - * @param {StepNode} step - The step to navigate to. + * @param step - The step to navigate to. */ - const goTo = useStableCallback(async (step: StepNode) => { + const goTo = useStableCallback((step: StepNode) => { if (step.disabled) { return; } @@ -48,26 +48,26 @@ export const useWizard = ({ steps: stepsMetadata }: UseWizardProps) => { * Navigates to the next step in the wizard. * If there is no next step, it does nothing. */ - const next = useStableCallback(async () => { + const next = useStableCallback(() => { if (!currentStep?.next) { return; } steps.enableStep(currentStep.next); - void goTo(currentStep.next); + goTo(currentStep.next); }); /** * Navigates to the previous step in the wizard. * If there is no previous step, it does nothing. */ - const previous = useStableCallback(async () => { + const previous = useStableCallback(() => { if (!currentStep?.prev) { return; } steps.enableStep(currentStep.prev); - void goTo(currentStep.prev); + goTo(currentStep.prev); }); /** diff --git a/packages/ui-client/src/components/Wizard/useWizardContext.tsx b/packages/ui-client/src/components/Wizard/useWizardContext.ts similarity index 100% rename from packages/ui-client/src/components/Wizard/useWizardContext.tsx rename to packages/ui-client/src/components/Wizard/useWizardContext.ts diff --git a/packages/ui-client/src/components/Wizard/useWizardSteps.tsx b/packages/ui-client/src/components/Wizard/useWizardSteps.ts similarity index 85% rename from packages/ui-client/src/components/Wizard/useWizardSteps.tsx rename to packages/ui-client/src/components/Wizard/useWizardSteps.ts index 1ae7793a55add..4414bb5e5bba7 100644 --- a/packages/ui-client/src/components/Wizard/useWizardSteps.tsx +++ b/packages/ui-client/src/components/Wizard/useWizardSteps.ts @@ -7,8 +7,8 @@ import type StepsLinkedList from './lib/StepsLinkedList'; * Custom hook to manage the state of wizard steps. * It uses a linked list to store the steps and provides a way to subscribe to changes. * - * @param {StepsLinkedList} list - The linked list containing the steps. - * @returns {StepNode[]} The current state of the steps. + * @param list - The linked list containing the steps. + * @returns The current state of the steps. */ export const useWizardSteps = (list: StepsLinkedList) => { const stateRef = useRef([]); diff --git a/packages/ui-client/src/hooks/useFeaturePreview.spec.tsx b/packages/ui-client/src/hooks/useFeaturePreview.spec.ts similarity index 100% rename from packages/ui-client/src/hooks/useFeaturePreview.spec.tsx rename to packages/ui-client/src/hooks/useFeaturePreview.spec.ts diff --git a/packages/ui-client/src/hooks/usePreferenceFeaturePreviewList.spec.tsx b/packages/ui-client/src/hooks/usePreferenceFeaturePreviewList.spec.ts similarity index 97% rename from packages/ui-client/src/hooks/usePreferenceFeaturePreviewList.spec.tsx rename to packages/ui-client/src/hooks/usePreferenceFeaturePreviewList.spec.ts index e129ee2b263f1..029d48ffc28e1 100644 --- a/packages/ui-client/src/hooks/usePreferenceFeaturePreviewList.spec.tsx +++ b/packages/ui-client/src/hooks/usePreferenceFeaturePreviewList.spec.ts @@ -4,7 +4,7 @@ import { renderHook } from '@testing-library/react'; import { enabledDefaultFeatures } from './useFeaturePreviewList'; import { usePreferenceFeaturePreviewList } from './usePreferenceFeaturePreviewList'; -it('should return the number of unseen features and Accounts_AllowFeaturePreview enabled ', () => { +it('should return the number of unseen features and Accounts_AllowFeaturePreview enabled', () => { const { result } = renderHook(() => usePreferenceFeaturePreviewList(), { wrapper: mockAppRoot().withSetting('Accounts_AllowFeaturePreview', true).build(), }); @@ -17,7 +17,7 @@ it('should return the number of unseen features and Accounts_AllowFeaturePreview ); }); -it('should return the number of unseen features and Accounts_AllowFeaturePreview disabled ', () => { +it('should return the number of unseen features and Accounts_AllowFeaturePreview disabled', () => { const { result } = renderHook(() => usePreferenceFeaturePreviewList(), { wrapper: mockAppRoot().withSetting('Accounts_AllowFeaturePreview', false).build(), }); diff --git a/packages/ui-voip/src/components/Keypad/useKeypad.tsx b/packages/ui-voip/src/components/Keypad/useKeypad.tsx deleted file mode 100644 index 3a9ec4272e8fc..0000000000000 --- a/packages/ui-voip/src/components/Keypad/useKeypad.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { Divider, Box, TextInput, Field, FieldRow } from '@rocket.chat/fuselage'; -import type { ReactNode } from 'react'; -import { useState } from 'react'; -import { useTranslation } from 'react-i18next'; - -import Keypad from './Keypad'; - -type UseKeypad = { - element: ReactNode; - buttonProps: { - title: string; - onClick: () => void; - }; -}; - -export const useKeypad = (onPress: (tone: string) => void): UseKeypad => { - const [open, setOpen] = useState(false); - const [inputValue, setInputValue] = useState(''); - const { t } = useTranslation(); - - const element = ( - - - - - - - { - setInputValue((inputValue) => inputValue + args[0]); - onPress(...args); - }} - /> - - - ); - - return { - element: open ? element : null, - buttonProps: { - title: open ? t('Close_dialpad') : t('Open_dialpad'), - onClick: () => setOpen((open) => !open), - }, - }; -}; diff --git a/packages/ui-voip/src/components/index.ts b/packages/ui-voip/src/components/index.ts index c2372b724e821..0f4ee8b2011fe 100644 --- a/packages/ui-voip/src/components/index.ts +++ b/packages/ui-voip/src/components/index.ts @@ -7,7 +7,6 @@ export * from './Actions'; export { default as ToggleButton } from './ToggleButton'; export { default as ActionButton } from './ActionButton'; export { default as Keypad } from './Keypad/Keypad'; -export { useKeypad } from './Keypad/useKeypad'; export { useInfoSlots } from './PeerInfo/useInfoSlots'; export { default as PeerAutocomplete } from './PeerAutocomplete'; export { default as Timer } from './Timer'; diff --git a/packages/ui-voip/src/context/usePeekMediaSessionFeatures.tsx b/packages/ui-voip/src/context/usePeekMediaSessionFeatures.ts similarity index 100% rename from packages/ui-voip/src/context/usePeekMediaSessionFeatures.tsx rename to packages/ui-voip/src/context/usePeekMediaSessionFeatures.ts diff --git a/packages/ui-voip/src/hooks/useMediaCallAction.spec.tsx b/packages/ui-voip/src/hooks/useMediaCallAction.spec.ts similarity index 100% rename from packages/ui-voip/src/hooks/useMediaCallAction.spec.tsx rename to packages/ui-voip/src/hooks/useMediaCallAction.spec.ts diff --git a/packages/ui-voip/src/views/MediaCallWidget/OngoingCall.tsx b/packages/ui-voip/src/views/MediaCallWidget/OngoingCall.tsx index 929f91d820a9e..04f5b77012fe5 100644 --- a/packages/ui-voip/src/views/MediaCallWidget/OngoingCall.tsx +++ b/packages/ui-voip/src/views/MediaCallWidget/OngoingCall.tsx @@ -1,4 +1,5 @@ -import { ButtonGroup } from '@rocket.chat/fuselage'; +import { Box, ButtonGroup, Divider, Field, FieldRow, TextInput } from '@rocket.chat/fuselage'; +import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { @@ -13,8 +14,8 @@ import { Timer, DevicePicker, ActionButton, - useKeypad, useInfoSlots, + Keypad, } from '../../components'; import { useMediaCallView } from '../../context/MediaCallViewContext'; @@ -24,7 +25,8 @@ const OngoingCall = () => { const { sessionState, onMute, onHold, onForward, onEndCall, onTone, onClickDirectMessage } = useMediaCallView(); const { muted, held, remoteMuted, remoteHeld, peerInfo, connectionState, supportedFeatures } = sessionState; - const { element: keypad, buttonProps: keypadButtonProps } = useKeypad(onTone); + const [open, setOpen] = useState(false); + const [inputValue, setInputValue] = useState(''); const slots = useInfoSlots(muted, held, connectionState); const remoteSlots = useInfoSlots(remoteMuted, remoteHeld); @@ -54,9 +56,30 @@ const OngoingCall = () => { - {keypad} + {open ? ( + + + + + + + { + setInputValue((inputValue) => inputValue + args[0]); + onTone(...args); + }} + /> + + + ) : null} - + setOpen((open) => !open)} + />