diff --git a/js/components/ascribe_accordion_list/accordion_list_item_thumbnail_placeholder.js b/js/components/ascribe_accordion_list/accordion_list_item_thumbnail_placeholder.js index 37c98371..8000affd 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_thumbnail_placeholder.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_thumbnail_placeholder.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; import React from 'react'; diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 567a53e9..caf48aae 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -36,7 +36,10 @@ let PieceList = React.createClass({ accordionListItemType: React.PropTypes.func, bulkModalButtonListType: React.PropTypes.func, canLoadPieceList: React.PropTypes.bool, - redirectTo: React.PropTypes.string, + redirectTo: React.PropTypes.shape({ + pathname: React.PropTypes.string, + query: React.PropTypes.object + }), shouldRedirect: React.PropTypes.func, customSubmitButton: React.PropTypes.element, customThumbnailPlaceholder: React.PropTypes.func, @@ -62,8 +65,11 @@ let PieceList = React.createClass({ ] }], orderParams: ['artist_name', 'title'], - redirectTo: '/register_piece', - shouldRedirect: () => true + redirectTo: { + pathname: '/register_piece', + query: null + }, + shouldRedirect: (pieceCount) => !pieceCount }; }, @@ -120,10 +126,16 @@ let PieceList = React.createClass({ const { location: { query }, redirectTo, shouldRedirect } = this.props; const { unfilteredPieceListCount } = this.state; - if (redirectTo && unfilteredPieceListCount === 0 && + if (redirectTo && redirectTo.pathname && (typeof shouldRedirect === 'function' && shouldRedirect(unfilteredPieceListCount))) { // FIXME: hack to redirect out of the dispatch cycle - window.setTimeout(() => this.history.push({ query, pathname: redirectTo }), 0); + window.setTimeout(() => this.history.push({ + // Occasionally, the back end also sets query parameters for Onion. + // We need to consider this by merging all passed query parameters, as we'll + // otherwise end up in a 404 screen + query: Object.assign({}, query, redirectTo.query), + pathname: redirectTo.pathname + }), 0); } }, diff --git a/js/components/whitelabel/prize/simple_prize/components/prize_piece_list.js b/js/components/whitelabel/prize/simple_prize/components/prize_piece_list.js index bd2b9f06..ec0def22 100644 --- a/js/components/whitelabel/prize/simple_prize/components/prize_piece_list.js +++ b/js/components/whitelabel/prize/simple_prize/components/prize_piece_list.js @@ -62,13 +62,15 @@ let PrizePieceList = React.createClass({ }, render() { + const { is_judge: isJudge, is_jury: isJury, is_admin: isAdmin } = this.state.currentUser; + setDocumentTitle(getLangText('Collection')); let orderParams = ['artist_name', 'title']; - if (this.state.currentUser.is_jury) { + if (isJury) { orderParams = ['rating', 'title']; } - if (this.state.currentUser.is_judge) { + if (isJudge) { orderParams = ['rating', 'title', 'selected']; } return ( @@ -80,7 +82,8 @@ let PrizePieceList = React.createClass({ orderBy={this.state.currentUser.is_jury ? 'rating' : null} filterParams={[]} customSubmitButton={this.getButtonSubmit()} - location={this.props.location}/> + location={this.props.location} + shouldRedirect={() => !(isJury || isJudge || isAdmin)} /> ); } diff --git a/js/components/whitelabel/prize/sluice/components/sluice_buttons/sluice_selected_prize_action_button.js b/js/components/whitelabel/prize/sluice/components/sluice_buttons/sluice_selected_prize_action_button.js index 7778a8de..7d013d5d 100644 --- a/js/components/whitelabel/prize/sluice/components/sluice_buttons/sluice_selected_prize_action_button.js +++ b/js/components/whitelabel/prize/sluice/components/sluice_buttons/sluice_selected_prize_action_button.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; import React from 'react'; import Moment from 'moment'; diff --git a/js/components/whitelabel/wallet/components/23vivi/23vivi_accordion_list/23vivi_accordion_list_item_thumbnail_placeholder.js b/js/components/whitelabel/wallet/components/23vivi/23vivi_accordion_list/23vivi_accordion_list_item_thumbnail_placeholder.js index f360c932..3a9b3943 100644 --- a/js/components/whitelabel/wallet/components/23vivi/23vivi_accordion_list/23vivi_accordion_list_item_thumbnail_placeholder.js +++ b/js/components/whitelabel/wallet/components/23vivi/23vivi_accordion_list/23vivi_accordion_list_item_thumbnail_placeholder.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; import React from 'react'; diff --git a/js/components/whitelabel/wallet/components/23vivi/23vivi_piece_list.js b/js/components/whitelabel/wallet/components/23vivi/23vivi_piece_list.js index 0bfb8aa0..fa2bf5f0 100644 --- a/js/components/whitelabel/wallet/components/23vivi/23vivi_piece_list.js +++ b/js/components/whitelabel/wallet/components/23vivi/23vivi_piece_list.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; import React from 'react'; diff --git a/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js b/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js index c40b455a..29c7d46f 100644 --- a/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js +++ b/js/components/whitelabel/wallet/components/cyland/cyland_piece_list.js @@ -6,11 +6,14 @@ import PieceList from '../../../../piece_list'; import UserActions from '../../../../../actions/user_actions'; import UserStore from '../../../../../stores/user_store'; +import WhitelabelActions from '../../../../../actions/whitelabel_actions'; +import WhitelabelStore from '../../../../../stores/whitelabel_store'; + import CylandAccordionListItem from './cyland_accordion_list/cyland_accordion_list_item'; import { getLangText } from '../../../../../utils/lang_utils'; import { setDocumentTitle } from '../../../../../utils/dom_utils'; - +import { mergeOptions } from '../../../../../utils/general_utils'; let CylandPieceList = React.createClass({ propTypes: { @@ -18,15 +21,22 @@ let CylandPieceList = React.createClass({ }, getInitialState() { - return UserStore.getState(); + return mergeOptions( + UserStore.getState(), + WhitelabelStore.getState() + ); }, componentDidMount() { UserStore.listen(this.onChange); + WhitelabelStore.listen(this.onChange); + + WhitelabelActions.fetchWhitelabel(); UserActions.fetchCurrentUser(); }, componentWillUnmount() { + WhitelabelStore.unlisten(this.onChange); UserStore.unlisten(this.onChange); }, @@ -34,13 +44,28 @@ let CylandPieceList = React.createClass({ this.setState(state); }, + shouldRedirect(pieceCount) { + const { currentUser: { email: userEmail }, + whitelabel: { + user: whitelabelAdminEmail + } } = this.state; + + return userEmail !== whitelabelAdminEmail && !pieceCount; + }, + render() { setDocumentTitle(getLangText('Collection')); return (