2018-05-09 00:30:00 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import _ from 'lodash';
|
2020-05-26 04:00:13 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2018-05-09 00:30:00 +08:00
|
|
|
import { styles } from './styles';
|
|
|
|
|
2019-05-09 23:00:17 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
legendTitle: {
|
|
|
|
id: 'app.meeting-ended.rating.legendLabel',
|
|
|
|
description: 'label for star feedback legend',
|
|
|
|
},
|
2019-05-09 23:35:52 +08:00
|
|
|
starLabel: {
|
|
|
|
id: 'app.meeting-ended.rating.starLabel',
|
|
|
|
description: 'label for feedback stars',
|
|
|
|
},
|
2019-05-09 23:00:17 +08:00
|
|
|
});
|
|
|
|
|
2019-08-06 20:57:26 +08:00
|
|
|
const propTypes = {
|
2020-05-26 04:00:13 +08:00
|
|
|
intl: PropTypes.object.isRequired,
|
2019-08-06 20:57:26 +08:00
|
|
|
onRate: PropTypes.func.isRequired,
|
|
|
|
total: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2018-05-09 00:30:00 +08:00
|
|
|
class Rating extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.clickStar = this.clickStar.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldComponentUpdate() {
|
|
|
|
// when component re render lost checked item
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
clickStar(e) {
|
2019-08-06 20:57:26 +08:00
|
|
|
const { onRate } = this.props;
|
|
|
|
onRate(e);
|
2018-05-09 00:30:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
renderStars(num) {
|
2019-05-09 23:00:17 +08:00
|
|
|
const { intl } = this.props;
|
|
|
|
|
2018-05-09 00:30:00 +08:00
|
|
|
return (
|
|
|
|
<div className={styles.starRating}>
|
|
|
|
<fieldset>
|
2019-05-16 03:37:49 +08:00
|
|
|
<legend className={styles.legend}>{intl.formatMessage(intlMessages.legendTitle)}</legend>
|
2018-05-09 00:30:00 +08:00
|
|
|
{
|
2019-05-09 23:35:52 +08:00
|
|
|
_.range(num)
|
|
|
|
.map(i => [
|
|
|
|
(
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
id={`${i + 1}star`}
|
|
|
|
name="rating"
|
|
|
|
value={i + 1}
|
|
|
|
key={_.uniqueId('star-')}
|
|
|
|
onChange={() => this.clickStar(i + 1)}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
(
|
|
|
|
<label
|
|
|
|
htmlFor={`${i + 1}star`}
|
|
|
|
key={_.uniqueId('star-')}
|
2019-08-06 20:57:26 +08:00
|
|
|
aria-label={`${i + 1} ${intl.formatMessage(intlMessages.starLabel)}`}
|
|
|
|
/>
|
2019-05-09 23:35:52 +08:00
|
|
|
),
|
|
|
|
]).reverse()
|
2018-05-09 00:30:00 +08:00
|
|
|
}
|
|
|
|
</fieldset>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
total,
|
|
|
|
} = this.props;
|
|
|
|
return (
|
|
|
|
<div className={styles.father}>
|
|
|
|
{
|
|
|
|
this.renderStars(total)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 23:00:17 +08:00
|
|
|
export default injectIntl(Rating);
|
2019-08-06 20:57:26 +08:00
|
|
|
|
|
|
|
Rating.propTypes = propTypes;
|