bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/meeting-ended/component.jsx

382 lines
12 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl } from 'react-intl';
import { Meteor } from 'meteor/meteor';
2018-05-09 00:30:00 +08:00
import Auth from '/imports/ui/services/auth';
import LearningDashboardService from '../learning-dashboard/service';
import Button from '/imports/ui/components/button/component';
import allowRedirectToLogoutURL from './service';
import getFromUserSettings from '/imports/ui/services/users-settings';
import logoutRouteHandler from '/imports/utils/logoutRouteHandler';
2018-05-09 00:30:00 +08:00
import Rating from './rating/component';
2018-01-31 00:12:05 +08:00
import { styles } from './styles';
import logger from '/imports/startup/client/logger';
2019-11-06 05:16:34 +08:00
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
import AudioManager from '/imports/ui/services/audio-manager';
import { meetingIsBreakout } from '/imports/ui/components/app/service';
const intlMessage = defineMessages({
410: {
id: 'app.meeting.ended',
description: 'message when meeting is ended',
},
403: {
id: 'app.error.removed',
description: 'Message to display when user is removed from the conference',
},
430: {
id: 'app.error.meeting.ended',
description: 'user logged conference',
},
'acl-not-allowed': {
id: 'app.error.removed',
description: 'Message to display when user is removed from the conference',
},
messageEnded: {
id: 'app.meeting.endedMessage',
description: 'message saying to go back to home screen',
},
messageEndedByUser: {
id: 'app.meeting.endedByUserMessage',
description: 'message informing who ended the meeting',
},
2021-07-08 22:51:00 +08:00
messageEndedByNoModeratorSingular: {
id: 'app.meeting.endedByNoModeratorMessageSingular',
description: 'message informing that the meeting was ended due to no moderator present (singular)',
},
messageEndedByNoModeratorPlural: {
id: 'app.meeting.endedByNoModeratorMessagePlural',
description: 'message informing that the meeting was ended due to no moderator present (plural)',
},
buttonOkay: {
2017-12-18 18:53:37 +08:00
id: 'app.meeting.endNotification.ok.label',
description: 'label okay for button',
},
2018-05-09 00:30:00 +08:00
title: {
id: 'app.feedback.title',
description: 'title for feedback screen',
},
subtitle: {
id: 'app.feedback.subtitle',
description: 'subtitle for feedback screen',
},
textarea: {
id: 'app.feedback.textarea',
description: 'placeholder for textarea',
},
confirmDesc: {
id: 'app.leaveConfirmation.confirmDesc',
description: 'adds context to confim option',
},
sendLabel: {
id: 'app.feedback.sendFeedback',
description: 'send feedback button label',
},
sendDesc: {
id: 'app.feedback.sendFeedbackDesc',
description: 'adds context to send feedback option',
},
duplicate_user_in_meeting_eject_reason: {
id: 'app.meeting.logout.duplicateUserEjectReason',
description: 'message for duplicate users',
},
2019-03-14 21:25:07 +08:00
not_enough_permission_eject_reason: {
id: 'app.meeting.logout.permissionEjectReason',
2019-03-14 21:25:07 +08:00
description: 'message for whom was kicked by doing something without permission',
},
user_requested_eject_reason: {
id: 'app.meeting.logout.ejectedFromMeeting',
description: 'message when the user is removed by someone',
},
validate_token_failed_eject_reason: {
id: 'app.meeting.logout.validateTokenFailedEjectReason',
description: 'invalid auth token',
},
user_inactivity_eject_reason: {
id: 'app.meeting.logout.userInactivityEjectReason',
description: 'message for whom was kicked by inactivity',
},
open_activity_report_btn: {
id: 'app.learning-dashboard.clickHereToOpen',
description: 'description of link to open activity report',
},
});
const propTypes = {
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
code: PropTypes.string.isRequired,
2021-07-09 00:09:25 +08:00
ejectedReason: PropTypes.string,
endedReason: PropTypes.string,
2021-03-05 21:49:28 +08:00
};
const defaultProps = {
2021-07-09 00:09:25 +08:00
ejectedReason: null,
endedReason: null,
};
class MeetingEnded extends PureComponent {
2018-05-09 00:30:00 +08:00
static getComment() {
const textarea = document.getElementById('feedbackComment');
const comment = textarea.value;
return comment;
}
2018-05-09 00:30:00 +08:00
constructor(props) {
super(props);
this.state = {
selected: 0,
dispatched: false,
2018-05-09 00:30:00 +08:00
};
2019-11-06 05:16:34 +08:00
const user = Users.findOne({ userId: Auth.userID });
if (user) {
this.localUserRole = user.role;
}
const meeting = Meetings.findOne({ id: user.meetingID });
if (meeting) {
2021-07-08 22:51:00 +08:00
this.endWhenNoModeratorMinutes = meeting.durationProps.endWhenNoModeratorDelayInMinutes;
const endedBy = Users.findOne({
userId: meeting.meetingEndedBy,
}, { fields: { name: 1 } });
if (endedBy) {
this.meetingEndedBy = endedBy.name;
}
}
2018-05-09 00:30:00 +08:00
this.setSelectedStar = this.setSelectedStar.bind(this);
this.confirmRedirect = this.confirmRedirect.bind(this);
2018-05-09 00:30:00 +08:00
this.sendFeedback = this.sendFeedback.bind(this);
this.shouldShowFeedback = this.shouldShowFeedback.bind(this);
2021-07-08 22:51:00 +08:00
this.getEndingMessage = this.getEndingMessage.bind(this);
AudioManager.exitAudio();
Meteor.disconnect();
}
2018-05-09 00:30:00 +08:00
setSelectedStar(starNumber) {
this.setState({
selected: starNumber,
});
}
shouldShowFeedback() {
const { dispatched } = this.state;
return getFromUserSettings('bbb_ask_for_feedback_on_logout', Meteor.settings.public.app.askForFeedbackOnLogout) && !dispatched;
}
confirmRedirect() {
2018-05-09 00:30:00 +08:00
const {
selected,
} = this.state;
if (selected <= 0) {
if (meetingIsBreakout()) window.close();
if (allowRedirectToLogoutURL()) logoutRouteHandler();
2018-05-09 00:30:00 +08:00
}
}
2021-07-08 22:51:00 +08:00
getEndingMessage() {
const { intl, code, endedReason } = this.props;
if (endedReason && endedReason === 'ENDED_DUE_TO_NO_MODERATOR') {
return this.endWhenNoModeratorMinutes === 1
? intl.formatMessage(intlMessage.messageEndedByNoModeratorSingular)
: intl.formatMessage(intlMessage.messageEndedByNoModeratorPlural, { 0: this.endWhenNoModeratorMinutes });
}
if (this.meetingEndedBy) {
return intl.formatMessage(intlMessage.messageEndedByUser, { 0: this.meetingEndedBy });
}
if (intlMessage[code]) {
return intl.formatMessage(intlMessage[code]);
}
2021-07-20 01:34:00 +08:00
return intl.formatMessage(intlMessage[430]);
2021-07-08 22:51:00 +08:00
}
sendFeedback() {
const {
selected,
} = this.state;
2018-05-09 00:30:00 +08:00
const { fullname } = Auth.credentials;
2018-05-09 00:30:00 +08:00
const message = {
rating: selected,
userId: Auth.userID,
userName: fullname,
authToken: Auth.token,
2018-05-09 00:30:00 +08:00
meetingId: Auth.meetingID,
comment: MeetingEnded.getComment(),
2019-11-06 05:16:34 +08:00
userRole: this.localUserRole,
2018-05-09 00:30:00 +08:00
};
const url = './feedback';
const options = {
method: 'POST',
body: JSON.stringify(message),
headers: {
'Content-Type': 'application/json',
},
};
// client logger
logger.info({ logCode: 'feedback_functionality', extraInfo: { feedback: message } }, 'Feedback component');
this.setState({
dispatched: true,
});
if (allowRedirectToLogoutURL()) {
const FEEDBACK_WAIT_TIME = 500;
setTimeout(() => {
fetch(url, options)
.then(() => {
logoutRouteHandler();
})
.catch(() => {
logoutRouteHandler();
});
}, FEEDBACK_WAIT_TIME);
}
2018-05-09 00:30:00 +08:00
}
renderNoFeedback() {
2021-07-09 00:09:25 +08:00
const { intl, code, ejectedReason } = this.props;
2021-08-27 02:04:06 +08:00
const { locale } = intl;
2021-07-09 00:09:25 +08:00
const logMessage = ejectedReason === 'user_requested_eject_reason' ? 'User removed from the meeting' : 'Meeting ended component, no feedback configured';
logger.info({ logCode: 'meeting_ended_code', extraInfo: { endedCode: code, reason: ejectedReason } }, logMessage);
return (
<div className={styles.parent}>
<div className={styles.modal}>
<div className={styles.content}>
<h1 className={styles.title} data-test="meetingEndedModalTitle">
2021-07-08 22:51:00 +08:00
{this.getEndingMessage()}
</h1>
{!allowRedirectToLogoutURL() ? null : (
<div>
{
LearningDashboardService.isModerator()
&& LearningDashboardService.isLearningDashboardEnabled() === true
// Always set cookie in case Dashboard is already opened
&& LearningDashboardService.setLearningDashboardCookie() === true
? (
<div className={styles.text}>
<Button
icon="multi_whiteboard"
color="default"
onClick={() => LearningDashboardService.openLearningDashboardUrl(locale)}
className={styles.button}
label={intl.formatMessage(intlMessage.open_activity_report_btn)}
description={intl.formatMessage(intlMessage.open_activity_report_btn)}
/>
</div>
) : null
}
<div className={styles.text}>
{intl.formatMessage(intlMessage.messageEnded)}
</div>
<Button
color="primary"
onClick={this.confirmRedirect}
className={styles.button}
label={intl.formatMessage(intlMessage.buttonOkay)}
description={intl.formatMessage(intlMessage.confirmDesc)}
/>
</div>
)}
</div>
</div>
</div>
);
}
renderFeedback() {
2021-07-09 00:09:25 +08:00
const { intl, code, ejectedReason } = this.props;
const {
selected,
dispatched,
} = this.state;
const noRating = selected <= 0;
2019-03-20 03:55:12 +08:00
2021-07-09 00:09:25 +08:00
const logMessage = ejectedReason === 'user_requested_eject_reason' ? 'User removed from the meeting' : 'Meeting ended component, feedback allowed';
logger.info({ logCode: 'meeting_ended_code', extraInfo: { endedCode: code, reason: ejectedReason } }, logMessage);
2019-03-20 03:55:12 +08:00
return (
<div className={styles.parent}>
<div className={styles.modal} data-test="meetingEndedModal">
<div className={styles.content}>
<h1 className={styles.title}>
2021-07-08 22:51:00 +08:00
{this.getEndingMessage()}
</h1>
<div className={styles.text}>
{this.shouldShowFeedback()
2018-05-09 00:30:00 +08:00
? intl.formatMessage(intlMessage.subtitle)
: intl.formatMessage(intlMessage.messageEnded)}
</div>
{this.shouldShowFeedback() ? (
<div data-test="rating">
2018-05-09 00:30:00 +08:00
<Rating
total="5"
onRate={this.setSelectedStar}
/>
{!noRating ? (
<textarea
rows="5"
id="feedbackComment"
className={styles.textarea}
placeholder={intl.formatMessage(intlMessage.textarea)}
aria-describedby="textareaDesc"
/>
) : null}
2018-05-09 00:30:00 +08:00
</div>
) : null}
{noRating && allowRedirectToLogoutURL() ? (
<Button
color="primary"
onClick={this.confirmRedirect}
className={styles.button}
label={intl.formatMessage(intlMessage.buttonOkay)}
description={intl.formatMessage(intlMessage.confirmDesc)}
/>
) : null}
{!noRating && !dispatched ? (
<Button
color="primary"
onClick={this.sendFeedback}
className={styles.button}
label={intl.formatMessage(intlMessage.sendLabel)}
description={intl.formatMessage(intlMessage.sendDesc)}
/>
) : null}
</div>
</div>
</div>
);
}
render() {
if (this.shouldShowFeedback()) return this.renderFeedback();
return this.renderNoFeedback();
}
}
MeetingEnded.propTypes = propTypes;
2021-03-05 21:49:28 +08:00
MeetingEnded.defaultProps = defaultProps;
export default injectIntl(MeetingEnded);