mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Merge pull request #147 from ascribe/AG-144-wallet-owner-should-not-be-redirected
Fix redirection of wallet owners
This commit is contained in:
commit
c0e55a1829
@ -1,4 +1,4 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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)} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
import Moment from 'moment';
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
|
@ -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 (
|
||||
<div>
|
||||
<PieceList
|
||||
redirectTo="/register_piece?slide_num=0"
|
||||
redirectTo={{
|
||||
pathname: '/register_piece',
|
||||
query: {
|
||||
'slide_num': 0
|
||||
}
|
||||
}}
|
||||
shouldRedirect={this.shouldRedirect}
|
||||
accordionListItemType={CylandAccordionListItem}
|
||||
filterParams={[{
|
||||
label: getLangText('Show works I have'),
|
||||
|
@ -6,8 +6,12 @@ import PieceList from '../../../../piece_list';
|
||||
|
||||
import UserActions from '../../../../../actions/user_actions';
|
||||
import UserStore from '../../../../../stores/user_store';
|
||||
|
||||
import NotificationStore from '../../../../../stores/notification_store';
|
||||
|
||||
import WhitelabelActions from '../../../../../actions/whitelabel_actions';
|
||||
import WhitelabelStore from '../../../../../stores/whitelabel_store';
|
||||
|
||||
import IkonotvAccordionListItem from './ikonotv_accordion_list/ikonotv_accordion_list_item';
|
||||
|
||||
import { setDocumentTitle } from '../../../../../utils/dom_utils';
|
||||
@ -23,31 +27,41 @@ let IkonotvPieceList = React.createClass({
|
||||
getInitialState() {
|
||||
return mergeOptions(
|
||||
NotificationStore.getState(),
|
||||
UserStore.getState()
|
||||
UserStore.getState(),
|
||||
WhitelabelStore.getState()
|
||||
);
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
NotificationStore.listen(this.onChange);
|
||||
WhitelabelStore.listen(this.onChange);
|
||||
UserStore.listen(this.onChange);
|
||||
|
||||
WhitelabelActions.fetchWhitelabel();
|
||||
UserActions.fetchCurrentUser();
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
NotificationStore.unlisten(this.onChange);
|
||||
WhitelabelStore.unlisten(this.onChange);
|
||||
UserStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
this.setState(state);
|
||||
|
||||
},
|
||||
|
||||
redirectIfNoContractNotifications() {
|
||||
const { contractAgreementListNotifications } = this.state;
|
||||
shouldRedirect(pieceCount) {
|
||||
const { contractAgreementListNotifications,
|
||||
currentUser: { email: userEmail },
|
||||
whitelabel: {
|
||||
user: whitelabelAdminEmail
|
||||
} } = this.state;
|
||||
|
||||
return contractAgreementListNotifications && !contractAgreementListNotifications.length;
|
||||
return contractAgreementListNotifications &&
|
||||
!contractAgreementListNotifications.length &&
|
||||
userEmail !== whitelabelAdminEmail &&
|
||||
!pieceCount;
|
||||
},
|
||||
|
||||
render() {
|
||||
@ -56,8 +70,13 @@ let IkonotvPieceList = React.createClass({
|
||||
return (
|
||||
<div>
|
||||
<PieceList
|
||||
redirectTo="/register_piece?slide_num=0"
|
||||
shouldRedirect={this.redirectIfNoContractNotifications}
|
||||
redirectTo={{
|
||||
pathname: '/register_piece',
|
||||
query: {
|
||||
'slide_num': 0
|
||||
}
|
||||
}}
|
||||
shouldRedirect={this.shouldRedirect}
|
||||
accordionListItemType={IkonotvAccordionListItem}
|
||||
filterParams={[{
|
||||
label: getLangText('Show works I have'),
|
||||
|
@ -59,11 +59,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 +79,13 @@ let MarketPieceList = React.createClass({
|
||||
return (
|
||||
<PieceList
|
||||
canLoadPieceList={canLoadPieceList}
|
||||
redirectTo="/register_piece?slide_num=0"
|
||||
redirectTo={{
|
||||
pathname: '/register_piece',
|
||||
query: {
|
||||
'slide_num': 0
|
||||
}
|
||||
}}
|
||||
shouldRedirect={(pieceCount) => !isUserAdmin && !pieceCount}
|
||||
bulkModalButtonListType={MarketAclButtonList}
|
||||
customThumbnailPlaceholder={customThumbnailPlaceholder}
|
||||
filterParams={filterParams}
|
||||
|
@ -112,12 +112,11 @@ let MarketRegisterPiece = React.createClass({
|
||||
|
||||
render() {
|
||||
const { location } = this.props;
|
||||
const {
|
||||
piece,
|
||||
step,
|
||||
whitelabel: {
|
||||
name: whitelabelName = 'Market'
|
||||
} } = this.state;
|
||||
const { piece,
|
||||
step,
|
||||
whitelabel: {
|
||||
name: whitelabelName = 'Market'
|
||||
} } = this.state;
|
||||
|
||||
setDocumentTitle(getLangText('Register a new piece'));
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
// TODO: Create Unittests that test all functions
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
import camelCase from 'camelcase';
|
||||
import decamelize from 'decamelize';
|
||||
|
Loading…
Reference in New Issue
Block a user