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/client/views/room/contexts/RoomContext.ts

31 lines
750 B

import { createContext, useContext } from 'react';
import { IRoom, IOmnichannelRoom, isOmnichannelRoom } from '../../../../definition/IRoom';
export type RoomContextValue = {
rid: IRoom['_id'];
room: IRoom;
};
export const RoomContext = createContext<RoomContextValue | null>(null);
export const useRoom = (): IRoom => {
const { room } = useContext(RoomContext) || {};
if (!room) {
throw new Error('use useRoom only inside opened rooms');
}
return room;
};
export const useOmnichannelRoom = (): IOmnichannelRoom => {
const { room } = useContext(RoomContext) || {};
if (!room) {
throw new Error('use useRoom only inside opened rooms');
}
if (!isOmnichannelRoom(room)) {
throw new Error('invalid room type');
}
return room;
};