import React, { Component } from 'react'; import PropTypes from 'prop-types'; import _ from 'lodash'; import { defineMessages, injectIntl } from 'react-intl'; import { styles } from './styles'; const intlMessages = defineMessages({ legendTitle: { id: 'app.meeting-ended.rating.legendLabel', description: 'label for star feedback legend', }, starLabel: { id: 'app.meeting-ended.rating.starLabel', description: 'label for feedback stars', }, }); const propTypes = { intl: PropTypes.object.isRequired, onRate: PropTypes.func.isRequired, total: PropTypes.string.isRequired, }; 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) { const { onRate } = this.props; onRate(e); } renderStars(num) { const { intl } = this.props; return (
{intl.formatMessage(intlMessages.legendTitle)} { _.range(num) .map(i => [ ( this.clickStar(i + 1)} /> ), (
); } render() { const { total, } = this.props; return (
{ this.renderStars(total) }
); } } export default injectIntl(Rating); Rating.propTypes = propTypes;