2019-03-19 15:42:25 +00:00
|
|
|
// @flow
|
2017-11-16 18:26:14 +00:00
|
|
|
|
2017-08-07 16:20:44 +00:00
|
|
|
import StarIcon from '@atlaskit/icon/glyph/star';
|
|
|
|
import StarFilledIcon from '@atlaskit/icon/glyph/star-filled';
|
|
|
|
import React, { Component } from 'react';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2017-08-07 16:20:44 +00:00
|
|
|
|
2017-12-11 18:48:32 +00:00
|
|
|
import {
|
2018-01-03 21:24:07 +00:00
|
|
|
createFeedbackOpenEvent,
|
|
|
|
sendAnalytics
|
2017-12-11 18:48:32 +00:00
|
|
|
} from '../../analytics';
|
2021-07-07 07:32:59 +00:00
|
|
|
import { isMobileBrowser } from '../../base/environment/utils';
|
2017-08-07 16:20:44 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2022-10-07 09:16:41 +00:00
|
|
|
import Dialog from '../../base/ui/components/web/Dialog';
|
2022-09-29 09:40:16 +00:00
|
|
|
import Input from '../../base/ui/components/web/Input';
|
2017-08-07 16:20:44 +00:00
|
|
|
import { cancelFeedback, submitFeedback } from '../actions';
|
|
|
|
|
2019-02-19 22:18:49 +00:00
|
|
|
declare var APP: Object;
|
2018-10-30 05:02:23 +00:00
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
2017-10-02 23:08:07 +00:00
|
|
|
const scoreAnimationClass
|
|
|
|
= interfaceConfig.ENABLE_FEEDBACK_ANIMATION ? 'shake-rotate' : '';
|
2017-08-07 16:20:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The scores to display for selecting. The score is the index in the array and
|
|
|
|
* the value of the index is a translation key used for display in the dialog.
|
|
|
|
*/
|
|
|
|
const SCORES = [
|
|
|
|
'feedback.veryBad',
|
|
|
|
'feedback.bad',
|
|
|
|
'feedback.average',
|
|
|
|
'feedback.good',
|
|
|
|
'feedback.veryGood'
|
|
|
|
];
|
|
|
|
|
2021-09-15 08:13:05 +00:00
|
|
|
type Scrollable = {
|
|
|
|
scroll: Function
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link FeedbackDialog}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The cached feedback message, if any, that was set when closing a previous
|
|
|
|
* instance of {@code FeedbackDialog}.
|
|
|
|
*/
|
|
|
|
_message: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The cached feedback score, if any, that was set when closing a previous
|
|
|
|
* instance of {@code FeedbackDialog}.
|
|
|
|
*/
|
|
|
|
_score: number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The JitsiConference that is being rated. The conference is passed in
|
|
|
|
* because feedback can occur after a conference has been left, so
|
|
|
|
* references to it may no longer exist in redux.
|
|
|
|
*/
|
|
|
|
conference: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to signal feedback submission or canceling.
|
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked when {@code FeedbackDialog} is unmounted.
|
|
|
|
*/
|
|
|
|
onClose: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} state of {@link FeedbackDialog}.
|
|
|
|
*/
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently entered feedback message.
|
|
|
|
*/
|
|
|
|
message: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The score selection index which is currently being hovered. The value -1
|
|
|
|
* is used as a sentinel value to match store behavior of using -1 for no
|
|
|
|
* score having been selected.
|
|
|
|
*/
|
|
|
|
mousedOverScore: number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently selected score selection index. The score will not be 0
|
|
|
|
* indexed so subtract one to map with SCORES.
|
|
|
|
*/
|
|
|
|
score: number
|
|
|
|
};
|
|
|
|
|
2017-08-07 16:20:44 +00:00
|
|
|
/**
|
|
|
|
* A React {@code Component} for displaying a dialog to rate the current
|
|
|
|
* conference quality, write a message describing the experience, and submit
|
|
|
|
* the feedback.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2017-08-07 16:20:44 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
class FeedbackDialog extends Component<Props, State> {
|
2017-08-07 16:20:44 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* An array of objects with click handlers for each of the scores listed in
|
|
|
|
* the constant SCORES. This pattern is used for binding event handlers only
|
|
|
|
* once for each score selection icon.
|
2017-08-07 16:20:44 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
_scoreClickConfigurations: Array<Object>;
|
2017-08-07 16:20:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code FeedbackDialog} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only React {@code Component} props with
|
|
|
|
* which the new instance is to be initialized.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: Props) {
|
2017-08-07 16:20:44 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
const { _message, _score } = this.props;
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
/**
|
|
|
|
* The currently entered feedback message.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
message: _message,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The score selection index which is currently being hovered. The
|
|
|
|
* value -1 is used as a sentinel value to match store behavior of
|
|
|
|
* using -1 for no score having been selected.
|
|
|
|
*
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
mousedOverScore: -1,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently selected score selection index. The score will not
|
|
|
|
* be 0 indexed so subtract one to map with SCORES.
|
|
|
|
*
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
score: _score > -1 ? _score - 1 : _score
|
|
|
|
};
|
|
|
|
|
|
|
|
this._scoreClickConfigurations = SCORES.map((textKey, index) => {
|
|
|
|
return {
|
|
|
|
_onClick: () => this._onScoreSelect(index),
|
2021-06-10 12:48:44 +00:00
|
|
|
_onKeyPres: e => {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
this._onScoreSelect(index);
|
|
|
|
}
|
|
|
|
},
|
2017-08-07 16:20:44 +00:00
|
|
|
_onMouseOver: () => this._onScoreMouseOver(index)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
|
|
|
this._onCancel = this._onCancel.bind(this);
|
|
|
|
this._onMessageChange = this._onMessageChange.bind(this);
|
|
|
|
this._onScoreContainerMouseLeave
|
|
|
|
= this._onScoreContainerMouseLeave.bind(this);
|
|
|
|
this._onSubmit = this._onSubmit.bind(this);
|
2021-09-15 08:13:05 +00:00
|
|
|
|
|
|
|
// On some mobile browsers opening Feedback dialog scrolls down the whole content because of the keyboard.
|
|
|
|
// By scrolling to the top we prevent hiding the feedback stars so the user knows those exist.
|
|
|
|
this._onScrollTop = (node: ?Scrollable) => {
|
|
|
|
node && node.scroll && node.scroll(0, 0);
|
|
|
|
};
|
2017-08-07 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emits an analytics event to notify feedback has been opened.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
2018-01-03 21:24:07 +00:00
|
|
|
sendAnalytics(createFeedbackOpenEvent());
|
2019-02-19 22:18:49 +00:00
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
APP.API.notifyFeedbackPromptDisplayed();
|
|
|
|
}
|
2017-08-07 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invokes the onClose callback, if defined, to notify of the close event.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.props.onClose) {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { message, mousedOverScore, score } = this.state;
|
|
|
|
const scoreToDisplayAsSelected
|
|
|
|
= mousedOverScore > -1 ? mousedOverScore : score;
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
const { t } = this.props;
|
|
|
|
|
2017-08-07 16:20:44 +00:00
|
|
|
const scoreIcons = this._scoreClickConfigurations.map(
|
|
|
|
(config, index) => {
|
|
|
|
const isFilled = index <= scoreToDisplayAsSelected;
|
|
|
|
const activeClass = isFilled ? 'active' : '';
|
|
|
|
const className
|
|
|
|
= `star-btn ${scoreAnimationClass} ${activeClass}`;
|
|
|
|
|
|
|
|
return (
|
2021-06-10 12:48:44 +00:00
|
|
|
<span
|
|
|
|
aria-label = { t(SCORES[index]) }
|
2017-08-07 16:20:44 +00:00
|
|
|
className = { className }
|
|
|
|
key = { index }
|
|
|
|
onClick = { config._onClick }
|
2021-06-10 12:48:44 +00:00
|
|
|
onKeyPress = { config._onKeyPres }
|
|
|
|
role = 'button'
|
2021-07-07 07:32:59 +00:00
|
|
|
tabIndex = { 0 }
|
|
|
|
{ ...(isMobileBrowser() ? {} : {
|
|
|
|
onMouseOver: config._onMouseOver
|
|
|
|
}) }>
|
2017-08-07 16:20:44 +00:00
|
|
|
{ isFilled
|
|
|
|
? <StarFilledIcon
|
|
|
|
label = 'star-filled'
|
|
|
|
size = 'xlarge' />
|
|
|
|
: <StarIcon
|
|
|
|
label = 'star'
|
|
|
|
size = 'xlarge' /> }
|
2021-06-10 12:48:44 +00:00
|
|
|
</span>
|
2017-08-07 16:20:44 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog
|
2022-10-07 09:16:41 +00:00
|
|
|
ok = {{
|
|
|
|
translationKey: 'dialog.Submit'
|
|
|
|
}}
|
2017-08-07 16:20:44 +00:00
|
|
|
onCancel = { this._onCancel }
|
|
|
|
onSubmit = { this._onSubmit }
|
|
|
|
titleKey = 'feedback.rateExperience'>
|
|
|
|
<div className = 'feedback-dialog'>
|
|
|
|
<div className = 'rating'>
|
2021-06-10 12:48:44 +00:00
|
|
|
<div
|
|
|
|
aria-label = { this.props.t('feedback.star') }
|
|
|
|
className = 'star-label' >
|
2017-08-07 16:20:44 +00:00
|
|
|
<p id = 'starLabel'>
|
|
|
|
{ t(SCORES[scoreToDisplayAsSelected]) }
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className = 'stars'
|
|
|
|
onMouseLeave = { this._onScoreContainerMouseLeave }>
|
|
|
|
{ scoreIcons }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className = 'details'>
|
2022-09-29 09:40:16 +00:00
|
|
|
<Input
|
2017-08-07 16:20:44 +00:00
|
|
|
autoFocus = { true }
|
|
|
|
id = 'feedbackTextArea'
|
2018-04-11 18:31:03 +00:00
|
|
|
label = { t('feedback.detailsLabel') }
|
2017-08-07 16:20:44 +00:00
|
|
|
onChange = { this._onMessageChange }
|
2022-09-29 09:40:16 +00:00
|
|
|
textarea = { true }
|
2017-08-07 16:20:44 +00:00
|
|
|
value = { message } />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onCancel: () => boolean;
|
|
|
|
|
2017-08-07 16:20:44 +00:00
|
|
|
/**
|
|
|
|
* Dispatches an action notifying feedback was not submitted. The submitted
|
|
|
|
* score will have one added as the rest of the app does not expect 0
|
|
|
|
* indexing.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {boolean} Returns true to close the dialog.
|
|
|
|
*/
|
|
|
|
_onCancel() {
|
|
|
|
const { message, score } = this.state;
|
|
|
|
const scoreToSubmit = score > -1 ? score + 1 : score;
|
|
|
|
|
|
|
|
this.props.dispatch(cancelFeedback(scoreToSubmit, message));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onMessageChange: (Object) => void;
|
|
|
|
|
2017-08-07 16:20:44 +00:00
|
|
|
/**
|
|
|
|
* Updates the known entered feedback message.
|
|
|
|
*
|
2022-09-29 09:40:16 +00:00
|
|
|
* @param {string} newValue - The new value from updating the textfield for the
|
2017-08-07 16:20:44 +00:00
|
|
|
* feedback message.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-29 09:40:16 +00:00
|
|
|
_onMessageChange(newValue) {
|
|
|
|
this.setState({ message: newValue });
|
2017-08-07 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the currently selected score.
|
|
|
|
*
|
|
|
|
* @param {number} score - The index of the selected score in SCORES.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onScoreSelect(score) {
|
|
|
|
this.setState({ score });
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onScoreContainerMouseLeave: () => void;
|
|
|
|
|
2017-08-07 16:20:44 +00:00
|
|
|
/**
|
|
|
|
* Sets the currently hovered score to null to indicate no hover is
|
|
|
|
* occurring.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onScoreContainerMouseLeave() {
|
|
|
|
this.setState({ mousedOverScore: -1 });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the known state of the score icon currently behind hovered over.
|
|
|
|
*
|
|
|
|
* @param {number} mousedOverScore - The index of the SCORES value currently
|
|
|
|
* being moused over.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onScoreMouseOver(mousedOverScore) {
|
|
|
|
this.setState({ mousedOverScore });
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onSubmit: () => void;
|
|
|
|
|
2017-08-07 16:20:44 +00:00
|
|
|
/**
|
|
|
|
* Dispatches the entered feedback for submission. The submitted score will
|
|
|
|
* have one added as the rest of the app does not expect 0 indexing.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {boolean} Returns true to close the dialog.
|
|
|
|
*/
|
|
|
|
_onSubmit() {
|
|
|
|
const { conference, dispatch } = this.props;
|
|
|
|
const { message, score } = this.state;
|
|
|
|
|
|
|
|
const scoreToSubmit = score > -1 ? score + 1 : score;
|
|
|
|
|
|
|
|
dispatch(submitFeedback(scoreToSubmit, message, conference));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-15 08:13:05 +00:00
|
|
|
|
|
|
|
_onScrollTop: (node: ?Scrollable) => void;
|
2017-08-07 16:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated {@code FeedbackDialog}'s
|
|
|
|
* props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
const { message, score } = state['features/feedback'];
|
|
|
|
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* The cached feedback message, if any, that was set when closing a
|
|
|
|
* previous instance of {@code FeedbackDialog}.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
_message: message,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently selected score selection index.
|
|
|
|
*
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
_score: score
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(FeedbackDialog));
|