}
buttons={this.getPrizeButtons()}
badge={this.getPrizeBadge()}>
- {this.props.children}
+ {children}
);
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 16849ed1..68a66cc0 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
@@ -34,9 +34,7 @@ import CollapsibleParagraph from '../../../../../../components/ascribe_collapsib
import FurtherDetailsFileuploader from '../../../../../ascribe_detail/further_details_fileuploader';
import InputCheckbox from '../../../../../ascribe_forms/input_checkbox';
-import LoanForm from '../../../../../ascribe_forms/form_loan';
import ListRequestActions from '../../../../../ascribe_forms/list_form_request_actions';
-import ModalWrapper from '../../../../../ascribe_modal/modal_wrapper';
import GlobalNotificationModel from '../../../../../../models/global_notification_model';
import GlobalNotificationActions from '../../../../../../actions/global_notification_actions';
@@ -52,39 +50,41 @@ import { setDocumentTitle } from '../../../../../../utils/dom_utils';
/**
* This is the component that implements resource/data specific functionality
*/
-let PieceContainer = React.createClass({
+let PrizePieceContainer = React.createClass({
propTypes: {
- params: React.PropTypes.object
+ params: React.PropTypes.object,
+ selectedPrizeActionButton: React.PropTypes.func
},
mixins: [ReactError],
getInitialState() {
- return mergeOptions(
- PieceStore.getState(),
- UserStore.getState()
- );
+ //FIXME: this component uses the PieceStore, but we avoid using the getState() here since it may contain stale data
+ // It should instead use something like getInitialState() where that call also resets the state.
+ return UserStore.getState();
+ },
+
+ componentWillMount() {
+ // Every time we enter the piece detail page, just reset the piece
+ // store as it will otherwise display wrong/old data once the user loads
+ // the piece detail a second time
+ PieceActions.updatePiece({});
},
componentDidMount() {
PieceStore.listen(this.onChange);
UserStore.listen(this.onChange);
- // Every time we enter the piece detail page, just reset the piece
- // store as it will otherwise display wrong/old data once the user loads
- // the piece detail a second time
- PieceActions.updatePiece({});
-
- PieceActions.fetchOne(this.props.params.pieceId);
UserActions.fetchCurrentUser();
+ this.loadPiece();
},
// This is done to update the container when the user clicks on the prev or next
// button to update the URL parameter (and therefore to switch pieces)
componentWillReceiveProps(nextProps) {
- if(this.props.params.pieceId !== nextProps.params.pieceId) {
+ if (this.props.params.pieceId !== nextProps.params.pieceId) {
PieceActions.updatePiece({});
- PieceActions.fetchOne(nextProps.params.pieceId);
+ this.loadPiece(nextProps.params.pieceId);
}
},
@@ -101,26 +101,32 @@ let PieceContainer = React.createClass({
UserStore.unlisten(this.onChange);
},
-
onChange(state) {
this.setState(state);
},
getActions() {
- if (this.state.piece &&
- this.state.piece.notifications &&
- this.state.piece.notifications.length > 0) {
+ const { currentUser, piece } = this.state;
+
+ if (piece && piece.notifications && piece.notifications.length > 0) {
return (
);
+ notifications={piece.notifications}/>);
}
},
+ loadPiece(pieceId = this.props.params.pieceId) {
+ PieceActions.fetchOne(pieceId);
+ },
+
render() {
- if(this.state.piece && this.state.piece.id) {
+ const { selectedPrizeActionButton } = this.props;
+ const { currentUser, piece } = this.state;
+
+ if (piece && piece.id) {
/*
This really needs a refactor!
@@ -129,37 +135,32 @@ let PieceContainer = React.createClass({
*/
// Only show the artist name if you are the participant or if you are a judge and the piece is shortlisted
- 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;
+ let artistName;
+ if ((currentUser.is_jury && !currentUser.is_judge) || (currentUser.is_judge && !piece.selected )) {
+ artistName = ;
+ setDocumentTitle(piece.title);
+ } else {
+ artistName = piece.artist_name;
+ setDocumentTitle([artistName, piece.title].join(', '));
+ }
// 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;
-
- if (artistName === null) {
- setDocumentTitle(this.state.piece.title);
- } else {
- setDocumentTitle([artistName, this.state.piece.title].join(', '));
- }
-
- if (artistName === null) {
- artistName = ;
- }
+ const artistEmail = (currentUser.is_judge && piece.selected ) ?
+ : null;
return (
+ piece={piece}
+ currentUser={currentUser}/>
-
{this.state.piece.title}
+
{piece.title}
-
+
{artistEmail}
{this.getActions()}
@@ -168,10 +169,11 @@ let PieceContainer = React.createClass({
subheader={
+ piece={piece}
+ currentUser={currentUser}
+ selectedPrizeActionButton={selectedPrizeActionButton} />
}>
-
+
);
} else {
@@ -225,29 +227,26 @@ let PrizePieceRatings = React.createClass({
propTypes: {
loadPiece: React.PropTypes.func,
piece: React.PropTypes.object,
- currentUser: React.PropTypes.object
+ currentUser: React.PropTypes.object,
+ selectedPrizeActionButton: React.PropTypes.func
},
getInitialState() {
return mergeOptions(
PieceListStore.getState(),
- PrizeRatingStore.getState()
+ PrizeRatingStore.getInitialState()
);
},
componentDidMount() {
PrizeRatingStore.listen(this.onChange);
+ PieceListStore.listen(this.onChange);
+
PrizeRatingActions.fetchOne(this.props.piece.id);
PrizeRatingActions.fetchAverage(this.props.piece.id);
- PieceListStore.listen(this.onChange);
},
componentWillUnmount() {
- // Every time we're leaving the piece detail page,
- // just reset the piece that is saved in the piece store
- // as it will otherwise display wrong/old data once the user loads
- // the piece detail a second time
- PrizeRatingActions.updateRating({});
PrizeRatingStore.unlisten(this.onChange);
PieceListStore.unlisten(this.onChange);
},
@@ -270,48 +269,23 @@ let PrizePieceRatings = React.createClass({
onRatingClick(event, args) {
event.preventDefault();
- PrizeRatingActions.createRating(this.props.piece.id, args.rating).then(
- this.refreshPieceData()
- );
+ PrizeRatingActions
+ .createRating(this.props.piece.id, args.rating)
+ .then(this.refreshPieceData);
},
- handleLoanRequestSuccess(message){
- let notification = new GlobalNotificationModel(message, 'success', 4000);
- GlobalNotificationActions.appendGlobalNotification(notification);
- },
+ getSelectedActionButton() {
+ const { currentUser, piece, selectedPrizeActionButton: SelectedPrizeActionButton } = this.props;
- getLoanButton(){
- let today = new Moment();
- let endDate = new Moment();
- endDate.add(6, 'months');
- return (
-
- {getLangText('SEND LOAN REQUEST')}
-
- }
- handleSuccess={this.handleLoanRequestSuccess}
- title='REQUEST LOAN'>
-
- );
- },
-
- handleShortlistSuccess(message){
- let notification = new GlobalNotificationModel(message, 'success', 2000);
- GlobalNotificationActions.appendGlobalNotification(notification);
+ if (piece.selected && SelectedPrizeActionButton) {
+ return (
+
+
+
+ );
+ }
},
refreshPieceData() {
@@ -321,20 +295,19 @@ let PrizePieceRatings = React.createClass({
},
onSelectChange() {
- PrizeRatingActions.toggleShortlist(this.props.piece.id)
- .then(
- (res) => {
+ PrizeRatingActions
+ .toggleShortlist(this.props.piece.id)
+ .then((res) => {
this.refreshPieceData();
- return res;
- })
- .then(
- (res) => {
- this.handleShortlistSuccess(res.notification);
- }
- );
+
+ if (res && res.notification) {
+ const notification = new GlobalNotificationModel(res.notification, 'success', 2000);
+ GlobalNotificationActions.appendGlobalNotification(notification);
+ }
+ });
},
- render(){
+ render() {
if (this.props.piece && this.props.currentUser && this.props.currentUser.is_judge && this.state.average) {
// Judge sees shortlisting, average and per-jury notes
return (
@@ -352,9 +325,7 @@ let PrizePieceRatings = React.createClass({
-
- {this.props.piece.selected ? this.getLoanButton() : null}
-
+ {this.getSelectedActionButton()}
@@ -373,13 +344,19 @@ let PrizePieceRatings = React.createClass({
{this.state.ratings.map((item, i) => {
- let note = item.note ?
+ let note = item.note ? (