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';
|
2017-10-27 01:14:50 +08:00
|
|
|
import _ from 'lodash';
|
|
|
|
import injectNotify from '/imports/ui/components/toast/inject-notify/component';
|
2018-10-17 01:48:27 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2017-10-28 03:29:48 +08:00
|
|
|
|
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,
|
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 {
|
2019-01-14 21:23:35 +08:00
|
|
|
static link(title, chatId) {
|
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={() => {
|
2018-12-18 23:15:51 +08:00
|
|
|
Session.set('openPanel', 'chat');
|
|
|
|
Session.set('idChatOpen', chatId);
|
|
|
|
}}
|
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
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-01-14 21:23:35 +08:00
|
|
|
this.showNotify = this.showNotify.bind(this);
|
2017-10-27 01:14:50 +08:00
|
|
|
|
|
|
|
this.componentDidMount = this.showNotify;
|
|
|
|
this.componentDidUpdate = this.showNotify;
|
|
|
|
}
|
|
|
|
|
|
|
|
showNotify() {
|
|
|
|
const {
|
|
|
|
notify,
|
|
|
|
onOpen,
|
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(
|
2019-01-14 21:23:35 +08:00
|
|
|
ChatPushAlert.link(title, chatId),
|
2018-06-15 22:37:57 +08:00
|
|
|
'info',
|
|
|
|
'chat',
|
2019-01-14 21:23:35 +08:00
|
|
|
{ onOpen, autoClose: alertDuration },
|
2018-08-15 10:35:58 +08:00
|
|
|
ChatPushAlert.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);
|