2019-02-27 01:08:15 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import injectNotify from '/imports/ui/components/toast/inject-notify/component';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { styles } from './styles';
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
pendingGuestAlert: {
|
|
|
|
id: 'app.userList.guest.pendingGuestAlert',
|
|
|
|
description: 'Title for the notes list',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
class PendingUsersAlert extends Component {
|
|
|
|
static messageElement(text, style) {
|
|
|
|
return (
|
|
|
|
<div className={style}>
|
|
|
|
{ text }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
notifiedIds: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
this.notifyAndStore = this.notifyAndStore.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const {
|
2019-02-27 01:21:57 +08:00
|
|
|
pendingUsers,
|
2019-02-27 01:08:15 +08:00
|
|
|
joinTime,
|
|
|
|
} = this.props;
|
|
|
|
const { notifiedIds } = this.state;
|
2019-02-27 01:21:57 +08:00
|
|
|
const notifiedPendingUsers = pendingUsers
|
2019-02-27 01:08:15 +08:00
|
|
|
.filter(user => user.loginTime < joinTime)
|
|
|
|
.map(user => user.intId);
|
|
|
|
this.setState({ notifiedIds: [...notifiedIds, ...notifiedPendingUsers] });
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
const {
|
2019-02-27 01:21:57 +08:00
|
|
|
pendingUsers,
|
2019-02-27 01:08:15 +08:00
|
|
|
managementPanelIsOpen,
|
|
|
|
currentUserIsModerator,
|
|
|
|
} = this.props;
|
|
|
|
const { notifiedIds } = this.state;
|
|
|
|
|
2019-02-27 01:21:57 +08:00
|
|
|
pendingUsers
|
2019-02-27 01:08:15 +08:00
|
|
|
.filter(user => !notifiedIds.includes(user.intId))
|
|
|
|
.forEach((user) => {
|
|
|
|
if (managementPanelIsOpen || !currentUserIsModerator) {
|
|
|
|
return this.storeId(user.intId);
|
|
|
|
}
|
|
|
|
return this.notifyAndStore(user);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
storeId(id) {
|
|
|
|
const { notifiedIds } = this.state;
|
|
|
|
this.setState({ notifiedIds: [...notifiedIds, id] });
|
|
|
|
}
|
|
|
|
|
|
|
|
notifyAndStore(user) {
|
|
|
|
const { notify, intl } = this.props;
|
|
|
|
notify(
|
|
|
|
PendingUsersAlert.messageElement(user.name, styles.titleMessage),
|
|
|
|
'info',
|
|
|
|
'user',
|
|
|
|
{ onOpen: this.storeId(user.intId) },
|
|
|
|
PendingUsersAlert.messageElement(
|
|
|
|
intl.formatMessage(intlMessages.pendingGuestAlert),
|
|
|
|
styles.contentMessage,
|
|
|
|
),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(injectNotify(PendingUsersAlert));
|