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

172 lines
4.7 KiB
React
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl } from 'react-intl';
2018-05-09 00:30:00 +08:00
import Auth from '/imports/ui/services/auth';
import Button from '/imports/ui/components/button/component';
import getFromUserSettings from '/imports/ui/services/users-settings';
import { logoutRouteHandler } from '/imports/startup/client/auth';
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';
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',
},
messageEnded: {
id: 'app.meeting.endedMessage',
description: 'message saying to go back to home screen',
},
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',
},
confirmLabel: {
id: 'app.leaveConfirmation.confirmLabel',
description: 'Confirmation button label',
},
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',
},
});
const propTypes = {
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
code: PropTypes.string.isRequired,
};
class MeetingEnded extends React.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,
};
this.setSelectedStar = this.setSelectedStar.bind(this);
this.sendFeedback = this.sendFeedback.bind(this);
this.shouldShowFeedback = getFromUserSettings('askForFeedbackOnLogout', Meteor.settings.public.app.askForFeedbackOnLogout);
2018-05-09 00:30:00 +08:00
}
setSelectedStar(starNumber) {
this.setState({
selected: starNumber,
});
}
2018-05-09 00:30:00 +08:00
sendFeedback() {
const {
selected,
} = this.state;
if (selected <= 0) {
logoutRouteHandler();
2018-05-09 00:30:00 +08:00
return;
}
const message = {
rating: selected,
userId: Auth.userID,
authToken: Auth.token,
2018-05-09 00:30:00 +08:00
meetingId: Auth.meetingID,
comment: MeetingEnded.getComment(),
};
const url = '/html5client/feedback';
const options = {
method: 'POST',
body: JSON.stringify(message),
headers: {
'Content-Type': 'application/json',
},
};
fetch(url, options)
.finally(() => {
logoutRouteHandler();
});
2018-05-09 00:30:00 +08:00
}
render() {
2018-05-11 21:05:59 +08:00
const { intl, code } = this.props;
2018-05-09 00:30:00 +08:00
const noRating = this.state.selected <= 0;
return (
<div className={styles.parent}>
<div className={styles.modal}>
<div className={styles.content}>
<h1 className={styles.title}>{intl.formatMessage(intlMessage[code])}</h1>
<div className={styles.text}>
2018-05-11 21:05:59 +08:00
{this.shouldShowFeedback
2018-05-09 00:30:00 +08:00
? intl.formatMessage(intlMessage.subtitle)
: intl.formatMessage(intlMessage.messageEnded)}
</div>
2018-05-11 21:05:59 +08:00
{this.shouldShowFeedback ? (
2018-05-09 00:30:00 +08:00
<div className={styles.rating}>
<Rating
total="5"
onRate={this.setSelectedStar}
/>
{!noRating ? (<textarea
2018-05-09 00:30:00 +08:00
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 }
<Button
color="primary"
2018-05-09 00:30:00 +08:00
onClick={this.sendFeedback}
className={styles.button}
2018-05-09 00:30:00 +08:00
label={noRating
? intl.formatMessage(intlMessage.buttonOkay)
: intl.formatMessage(intlMessage.sendLabel)}
description={noRating ?
intl.formatMessage(intlMessage.confirmDesc)
: intl.formatMessage(intlMessage.sendDesc)}
/>
</div>
</div>
</div>
);
}
}
MeetingEnded.propTypes = propTypes;
export default injectIntl(MeetingEnded);