diff --git a/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js b/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js index 982af7b0..4f5c9107 100644 --- a/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js +++ b/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js @@ -112,7 +112,7 @@ let PieceContainer = React.createClass({ render() { if(this.state.piece && this.state.piece.id) { /* - + This really needs a refactor! - Tim @@ -122,7 +122,7 @@ let PieceContainer = React.createClass({ let artistName = ((this.state.currentUser.is_jury && !this.state.currentUser.is_judge) || (this.state.currentUser.is_judge && !this.state.piece.selected )) ? null : this.state.piece.artist_name; - + // Only show the artist email if you are a judge and the piece is shortlisted let artistEmail = (this.state.currentUser.is_judge && this.state.piece.selected ) ? : null; @@ -146,7 +146,7 @@ let PieceContainer = React.createClass({ - +

{this.state.piece.title}

@@ -176,8 +176,8 @@ let PieceContainer = React.createClass({ let NavigationHeader = React.createClass({ propTypes: { - piece: React.PropTypes.object, - currentUser: React.PropTypes.object + piece: React.PropTypes.object.isRequired, + currentUser: React.PropTypes.object.isRequired }, render() { @@ -213,9 +213,9 @@ let NavigationHeader = React.createClass({ let PrizePieceRatings = React.createClass({ propTypes: { - loadPiece: React.PropTypes.func, - piece: React.PropTypes.object, - currentUser: React.PropTypes.object + loadPiece: React.PropTypes.func.isRequired, + piece: React.PropTypes.object.isRequired, + currentUser: React.PropTypes.object.isRequired }, getInitialState() { @@ -227,9 +227,15 @@ let PrizePieceRatings = React.createClass({ componentDidMount() { PrizeRatingStore.listen(this.onChange); - PrizeRatingActions.fetchOne(this.props.piece.id); - PrizeRatingActions.fetchAverage(this.props.piece.id); PieceListStore.listen(this.onChange); + + this.fetchRatingsIfAuthorized(); + }, + + componentWillReceiveProps(nextProps) { + if (nextProps.currentUser.email !== this.props.currentUser.email) { + this.fetchRatingsIfAuthorized(); + } }, componentWillUnmount() { @@ -258,6 +264,21 @@ let PrizePieceRatings = React.createClass({ } }, + fetchRatingsIfAuthorized() { + const { + currentUser: { + is_admin: isAdmin, + is_judge: isJudge, + is_jury: isJury + }, + piece: { id: pieceId } } = this.props; + + if (isAdmin || isJudge || isJury) { + PrizeRatingActions.fetchOne(pieceId); + PrizeRatingActions.fetchAverage(pieceId); + } + }, + onRatingClick(event, args) { event.preventDefault(); PrizeRatingActions.createRating(this.props.piece.id, args.rating).then( @@ -425,12 +446,11 @@ let PrizePieceRatings = React.createClass({ let PrizePieceDetails = React.createClass({ propTypes: { - piece: React.PropTypes.object + piece: React.PropTypes.object.isRequired }, render() { - if (this.props.piece - && this.props.piece.prize + if (this.props.piece.prize && this.props.piece.prize.name && Object.keys(this.props.piece.extra_data).length !== 0){ return (