The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/hooks/menuActions/useToggleNotificationsActio...

30 lines
1.1 KiB

import type { IRoom } from '@rocket.chat/core-typings';
import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useTranslation } from 'react-i18next';
type useToggleNotificationActionProps = {
rid: IRoom['_id'];
isNotificationEnabled: boolean;
roomName: string;
};
export const useToggleNotificationAction = ({ rid, isNotificationEnabled, roomName }: useToggleNotificationActionProps) => {
const toggleNotification = useEndpoint('POST', '/v1/rooms.saveNotification');
const dispatchToastMessage = useToastMessageDispatch();
const { t } = useTranslation();
const handleToggleNotification = useEffectEvent(async () => {
try {
await toggleNotification({ roomId: rid, notifications: { disableNotifications: isNotificationEnabled ? '1' : '0' } });
dispatchToastMessage({
type: 'success',
message: t(isNotificationEnabled ? 'Room_notifications_off' : 'Room_notifications_on', { roomName }),
});
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
});
return handleToggleNotification;
};