-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Remove hideRoom client meteor method (#33766)
- Loading branch information
1 parent
3a66c37
commit 8420101
Showing
9 changed files
with
119 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import type { RoomType } from '@rocket.chat/core-typings'; | ||
import { useEffectEvent } from '@rocket.chat/fuselage-hooks'; | ||
import type { TranslationKey } from '@rocket.chat/ui-contexts'; | ||
import { useEndpoint, useSetModal, useToastMessageDispatch, useRouter, useUserId } from '@rocket.chat/ui-contexts'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { useDontAskAgain } from './useDontAskAgain'; | ||
import { UiTextContext } from '../../definition/IRoomTypeConfig'; | ||
import { GenericModalDoNotAskAgain } from '../components/GenericModal'; | ||
import { updateSubscription } from '../lib/mutationEffects/updateSubscription'; | ||
import { roomCoordinator } from '../lib/rooms/roomCoordinator'; | ||
|
||
type HideRoomProps = { | ||
rid: string; | ||
type: RoomType; | ||
name: string; | ||
}; | ||
|
||
type HideRoomOptions = { | ||
redirect?: boolean; | ||
}; | ||
|
||
const CLOSE_ENDPOINTS_BY_ROOM_TYPE = { | ||
p: '/v1/groups.close', // private | ||
c: '/v1/channels.close', // channel | ||
d: '/v1/im.close', // direct message | ||
v: '/v1/channels.close', // omnichannel voip | ||
l: '/v1/channels.close', // livechat | ||
} as const; | ||
|
||
export const useHideRoomAction = ({ rid: roomId, type, name }: HideRoomProps, { redirect = true }: HideRoomOptions = {}) => { | ||
const { t } = useTranslation(); | ||
const setModal = useSetModal(); | ||
const closeModal = useEffectEvent(() => setModal()); | ||
const dispatchToastMessage = useToastMessageDispatch(); | ||
const dontAskHideRoom = useDontAskAgain('hideRoom'); | ||
const router = useRouter(); | ||
const userId = useUserId(); | ||
|
||
const hideRoomEndpoint = useEndpoint('POST', CLOSE_ENDPOINTS_BY_ROOM_TYPE[type]); | ||
|
||
const hideRoom = useMutation({ | ||
mutationFn: () => hideRoomEndpoint({ roomId }), | ||
onMutate: async () => { | ||
closeModal(); | ||
|
||
if (userId) { | ||
return updateSubscription(roomId, userId, { alert: false, open: false }); | ||
} | ||
}, | ||
onSuccess: () => { | ||
if (redirect) { | ||
router.navigate('/home'); | ||
} | ||
}, | ||
onError: async (error, _, rollbackDocument) => { | ||
dispatchToastMessage({ type: 'error', message: error }); | ||
|
||
if (userId && rollbackDocument) { | ||
const { alert, open } = rollbackDocument; | ||
updateSubscription(roomId, userId, { alert, open }); | ||
} | ||
}, | ||
}); | ||
|
||
const handleHide = useEffectEvent(async () => { | ||
const warnText = roomCoordinator.getRoomDirectives(type).getUiText(UiTextContext.HIDE_WARNING); | ||
|
||
if (dontAskHideRoom) { | ||
hideRoom.mutate(); | ||
return; | ||
} | ||
|
||
setModal( | ||
<GenericModalDoNotAskAgain | ||
variant='danger' | ||
confirmText={t('Yes_hide_it')} | ||
cancelText={t('Cancel')} | ||
onClose={closeModal} | ||
onCancel={closeModal} | ||
onConfirm={() => hideRoom.mutate()} | ||
dontAskAgain={{ | ||
action: 'hideRoom', | ||
label: t('Hide_room'), | ||
}} | ||
> | ||
{t(warnText as TranslationKey, { postProcess: 'sprintf', sprintf: [name] })} | ||
</GenericModalDoNotAskAgain>, | ||
); | ||
}); | ||
|
||
return handleHide; | ||
}; |
11 changes: 11 additions & 0 deletions
11
apps/meteor/client/lib/mutationEffects/updateSubscription.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { ISubscription } from '@rocket.chat/core-typings'; | ||
|
||
import { Subscriptions } from '../../../app/models/client'; | ||
|
||
export const updateSubscription = (roomId: string, userId: string, data: Partial<ISubscription>) => { | ||
const oldDocument = Subscriptions.findOne({ 'rid': roomId, 'u._id': userId }); | ||
|
||
Subscriptions.update({ 'rid': roomId, 'u._id': userId }, { $set: data }); | ||
|
||
return oldDocument; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import './hideRoom'; | ||
import './openRoom'; | ||
import './pinMessage'; | ||
import './unpinMessage'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
apps/meteor/client/views/room/contextualBar/Info/hooks/actions/useRoomHide.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.