diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 567a53e9..82fc2df3 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,7 +65,10 @@ let PieceList = React.createClass({ ] }], orderParams: ['artist_name', 'title'], - redirectTo: '/register_piece', + redirectTo: { + pathname: '/register_piece', + query: {} + }, shouldRedirect: () => true }; }, @@ -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 && unfilteredPieceListCount === 0 && (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/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..288b7eb8 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,30 @@ 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 (
!isUserAdmin && !pieceCount; + }, + render() { const { customThumbnailPlaceholder, location } = this.props; const { @@ -59,11 +63,12 @@ let MarketPieceList = React.createClass({ } } = this.state; let filterParams = null; + let isUserAdmin = null; let canLoadPieceList = false; if (userEmail && whitelabelAdminEmail) { canLoadPieceList = true; - const isUserAdmin = userEmail === whitelabelAdminEmail; + isUserAdmin = userEmail === whitelabelAdminEmail; filterParams = [{ label: getLangText('Show works I can'), @@ -78,7 +83,13 @@ let MarketPieceList = React.createClass({ return (