2018-12-17 19:48:34 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-10-28 03:29:48 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2022-02-16 01:57:50 +08:00
|
|
|
import injectNotify from '/imports/ui/components/common/toast/inject-notify/component';
|
2021-05-18 04:25:07 +08:00
|
|
|
import { PANELS, ACTIONS } from '../../../layout/enums';
|
2018-06-15 22:22:56 +08:00
|
|
|
|
2017-10-28 03:29:48 +08:00
|
|
|
const propTypes = {
|
|
|
|
notify: PropTypes.func.isRequired,
|
|
|
|
onOpen: PropTypes.func.isRequired,
|
2018-10-25 23:20:37 +08:00
|
|
|
chatId: PropTypes.string.isRequired,
|
2019-01-14 21:23:35 +08:00
|
|
|
title: PropTypes.node.isRequired,
|
2018-10-25 23:20:37 +08:00
|
|
|
content: PropTypes.node.isRequired,
|
2019-01-14 21:23:35 +08:00
|
|
|
alertDuration: PropTypes.number.isRequired,
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch: PropTypes.func.isRequired,
|
2017-10-28 03:29:48 +08:00
|
|
|
};
|
2017-10-27 01:14:50 +08:00
|
|
|
|
2018-12-17 19:48:34 +08:00
|
|
|
class ChatPushAlert extends PureComponent {
|
2021-05-18 04:25:07 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.showNotify = this.showNotify.bind(this);
|
|
|
|
|
|
|
|
this.componentDidMount = this.showNotify;
|
|
|
|
this.componentDidUpdate = this.showNotify;
|
|
|
|
this.link = this.link.bind(this);
|
|
|
|
}
|
2019-01-22 19:42:03 +08:00
|
|
|
|
2021-05-18 04:25:07 +08:00
|
|
|
link(title, chatId) {
|
2021-08-05 19:03:24 +08:00
|
|
|
const { layoutContextDispatch } = this.props;
|
2019-01-22 19:42:03 +08:00
|
|
|
|
2018-10-17 01:48:27 +08:00
|
|
|
return (
|
|
|
|
<div
|
2019-01-14 21:23:35 +08:00
|
|
|
key={chatId}
|
2018-10-17 01:48:27 +08:00
|
|
|
role="button"
|
2019-01-14 21:23:35 +08:00
|
|
|
aria-label={title}
|
2018-10-25 23:20:37 +08:00
|
|
|
tabIndex={0}
|
2018-10-17 01:48:27 +08:00
|
|
|
onClick={() => {
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-05-18 04:25:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: true,
|
|
|
|
});
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-06-07 22:18:57 +08:00
|
|
|
type: ACTIONS.SET_ID_CHAT_OPEN,
|
|
|
|
value: chatId,
|
|
|
|
});
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-05-18 04:25:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: PANELS.CHAT,
|
|
|
|
});
|
2018-12-18 23:15:51 +08:00
|
|
|
}}
|
2019-01-22 19:42:03 +08:00
|
|
|
onKeyPress={() => null}
|
2018-10-17 01:48:27 +08:00
|
|
|
>
|
2019-01-14 21:23:35 +08:00
|
|
|
{title}
|
2018-10-17 01:48:27 +08:00
|
|
|
</div>
|
|
|
|
);
|
2018-06-13 01:21:31 +08:00
|
|
|
}
|
|
|
|
|
2017-10-27 01:14:50 +08:00
|
|
|
showNotify() {
|
|
|
|
const {
|
|
|
|
notify,
|
|
|
|
onOpen,
|
2021-06-08 00:53:35 +08:00
|
|
|
onClose,
|
2018-05-30 00:43:11 +08:00
|
|
|
chatId,
|
2019-01-14 21:23:35 +08:00
|
|
|
title,
|
2018-05-30 00:43:11 +08:00
|
|
|
content,
|
2019-01-14 21:23:35 +08:00
|
|
|
alertDuration,
|
2017-10-27 01:14:50 +08:00
|
|
|
} = this.props;
|
2018-05-30 00:43:11 +08:00
|
|
|
|
2018-06-15 22:37:57 +08:00
|
|
|
return notify(
|
2021-05-18 04:25:07 +08:00
|
|
|
this.link(title, chatId),
|
2018-06-15 22:37:57 +08:00
|
|
|
'info',
|
|
|
|
'chat',
|
2021-06-08 00:53:35 +08:00
|
|
|
{ onOpen, onClose, autoClose: alertDuration },
|
2021-05-18 04:25:07 +08:00
|
|
|
this.link(content, chatId),
|
2018-06-15 22:37:57 +08:00
|
|
|
true,
|
|
|
|
);
|
2017-10-27 01:14:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2018-08-15 10:35:58 +08:00
|
|
|
ChatPushAlert.propTypes = propTypes;
|
2017-10-27 01:14:50 +08:00
|
|
|
|
2018-08-15 10:35:58 +08:00
|
|
|
export default injectNotify(ChatPushAlert);
|