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/providers/ToastMessagesProvider.tsx

33 lines
882 B

import React, { FC, useEffect } from 'react';
import toastr from 'toastr';
import { ToastMessagesContext } from '../contexts/ToastMessagesContext';
import { dispatchToastMessage, subscribeToToastMessages } from '../lib/toast';
import { handleError } from '../lib/utils/handleError';
const contextValue = {
dispatch: dispatchToastMessage,
};
const ToastMessagesProvider: FC = ({ children }) => {
useEffect(
() =>
subscribeToToastMessages(({ type, message, title, options }) => {
if (type === 'error' && typeof message === 'object') {
handleError(message);
return;
}
if (typeof message !== 'string') {
message = `[${message.name}] ${message.message}`;
}
toastr[type](message, title, options);
}),
[],
);
return <ToastMessagesContext.Provider children={children} value={contextValue} />;
};
export default ToastMessagesProvider;