2023-03-27 13:40:55 +03:00
|
|
|
import React, { useCallback } from 'react';
|
2023-03-21 09:47:52 +02:00
|
|
|
import { connect } from 'react-redux';
|
2023-03-27 13:40:55 +03:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2019-03-21 17:38:29 +01:00
|
|
|
|
2022-10-20 12:11:27 +03:00
|
|
|
import { IReduxState } from '../../../app/types';
|
2021-10-04 16:07:05 +02:00
|
|
|
import { hideNotification } from '../../actions';
|
|
|
|
|
import { areThereNotifications } from '../../functions';
|
2023-03-13 15:15:32 +02:00
|
|
|
import { INotificationProps } from '../../types';
|
|
|
|
|
import NotificationsTransition from '../NotificationsTransition';
|
2019-03-27 15:00:10 +01:00
|
|
|
|
2018-06-14 11:14:32 +02:00
|
|
|
import Notification from './Notification';
|
2023-03-27 13:40:55 +03:00
|
|
|
interface IProps {
|
2020-02-25 11:47:37 +01:00
|
|
|
|
|
|
|
|
/**
|
2021-03-16 11:59:33 -04:00
|
|
|
* Whether we are a SIP gateway or not.
|
2020-02-25 11:47:37 +01:00
|
|
|
*/
|
2022-09-08 12:52:36 +03:00
|
|
|
_iAmSipGateway: boolean;
|
2021-10-04 16:07:05 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether or not the chat is open.
|
|
|
|
|
*/
|
2022-09-08 12:52:36 +03:00
|
|
|
_isChatOpen: boolean;
|
2021-10-04 16:07:05 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The notifications to be displayed, with the first index being the
|
|
|
|
|
* notification at the top and the rest shown below it in order.
|
|
|
|
|
*/
|
2022-08-25 14:35:19 +03:00
|
|
|
_notifications: Array<{
|
2023-03-13 15:15:32 +02:00
|
|
|
props: INotificationProps;
|
2023-03-10 14:11:31 +02:00
|
|
|
uid: string;
|
2022-09-08 12:52:36 +03:00
|
|
|
}>;
|
2021-10-04 16:07:05 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Invoked to update the redux store in order to remove notifications.
|
|
|
|
|
*/
|
2022-09-08 12:52:36 +03:00
|
|
|
dispatch: Function;
|
2021-10-04 16:07:05 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether or not the notifications are displayed in a portal.
|
|
|
|
|
*/
|
2022-09-08 12:52:36 +03:00
|
|
|
portal?: boolean;
|
2022-08-25 14:35:19 +03:00
|
|
|
}
|
2021-10-04 16:07:05 +02:00
|
|
|
|
2023-03-27 13:40:55 +03:00
|
|
|
const useStyles = makeStyles()(() => {
|
2021-10-04 16:07:05 +02:00
|
|
|
return {
|
|
|
|
|
container: {
|
2023-03-27 13:40:55 +03:00
|
|
|
position: 'absolute',
|
2021-10-04 16:07:05 +02:00
|
|
|
left: '16px',
|
2023-03-13 15:15:32 +02:00
|
|
|
bottom: '84px',
|
|
|
|
|
width: '320px',
|
2021-10-04 16:07:05 +02:00
|
|
|
maxWidth: '100%',
|
|
|
|
|
zIndex: 600
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
containerPortal: {
|
2023-03-13 15:15:32 +02:00
|
|
|
width: '100%',
|
2021-10-04 16:07:05 +02:00
|
|
|
maxWidth: 'calc(100% - 32px)'
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-03-27 13:40:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const NotificationsContainer = ({
|
|
|
|
|
_iAmSipGateway,
|
|
|
|
|
_notifications,
|
|
|
|
|
dispatch,
|
|
|
|
|
portal
|
|
|
|
|
}: IProps) => {
|
|
|
|
|
const { classes, cx } = useStyles();
|
|
|
|
|
|
|
|
|
|
const _onDismissed = useCallback((uid: string) => {
|
|
|
|
|
dispatch(hideNotification(uid));
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
if (_iAmSipGateway) {
|
|
|
|
|
return null;
|
2021-10-04 16:07:05 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-27 13:40:55 +03:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className = { cx(classes.container, {
|
|
|
|
|
[classes.containerPortal]: portal
|
|
|
|
|
}) }
|
|
|
|
|
id = 'notifications-container'>
|
|
|
|
|
<NotificationsTransition>
|
|
|
|
|
{_notifications.map(({ props, uid }) => (
|
|
|
|
|
<Notification
|
|
|
|
|
{ ...props }
|
|
|
|
|
key = { uid }
|
|
|
|
|
onDismissed = { _onDismissed }
|
|
|
|
|
uid = { uid } />
|
|
|
|
|
)) || null}
|
|
|
|
|
</NotificationsTransition>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
2017-07-28 10:56:49 -07:00
|
|
|
|
2020-02-25 11:47:37 +01:00
|
|
|
/**
|
|
|
|
|
* Maps (parts of) the Redux state to the associated props for this component.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
|
* @private
|
2022-10-20 12:11:27 +03:00
|
|
|
* @returns {IProps}
|
2020-02-25 11:47:37 +01:00
|
|
|
*/
|
2022-10-20 12:11:27 +03:00
|
|
|
function _mapStateToProps(state: IReduxState) {
|
2021-10-04 16:07:05 +02:00
|
|
|
const { notifications } = state['features/notifications'];
|
2020-02-25 11:47:37 +01:00
|
|
|
const { iAmSipGateway } = state['features/base/config'];
|
2021-10-04 16:07:05 +02:00
|
|
|
const { isOpen: isChatOpen } = state['features/chat'];
|
|
|
|
|
const _visible = areThereNotifications(state);
|
2020-02-25 11:47:37 +01:00
|
|
|
|
|
|
|
|
return {
|
2021-10-04 16:07:05 +02:00
|
|
|
_iAmSipGateway: Boolean(iAmSipGateway),
|
|
|
|
|
_isChatOpen: isChatOpen,
|
2021-11-24 13:05:27 +02:00
|
|
|
_notifications: _visible ? notifications : []
|
2020-02-25 11:47:37 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 13:40:55 +03:00
|
|
|
export default connect(_mapStateToProps)(NotificationsContainer);
|