mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +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';
|
import React from 'react';
|
||||||
|
|
||||||
|
@ -36,7 +36,10 @@ let PieceList = React.createClass({
|
|||||||
accordionListItemType: React.PropTypes.func,
|
accordionListItemType: React.PropTypes.func,
|
||||||
bulkModalButtonListType: React.PropTypes.func,
|
bulkModalButtonListType: React.PropTypes.func,
|
||||||
canLoadPieceList: React.PropTypes.bool,
|
canLoadPieceList: React.PropTypes.bool,
|
||||||
redirectTo: React.PropTypes.string,
|
redirectTo: React.PropTypes.shape({
|
||||||
|
pathname: React.PropTypes.string,
|
||||||
|
query: React.PropTypes.object
|
||||||
|
}),
|
||||||
shouldRedirect: React.PropTypes.func,
|
shouldRedirect: React.PropTypes.func,
|
||||||
customSubmitButton: React.PropTypes.element,
|
customSubmitButton: React.PropTypes.element,
|
||||||
customThumbnailPlaceholder: React.PropTypes.func,
|
customThumbnailPlaceholder: React.PropTypes.func,
|
||||||
@ -62,8 +65,11 @@ let PieceList = React.createClass({
|
|||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
orderParams: ['artist_name', 'title'],
|
orderParams: ['artist_name', 'title'],
|
||||||
redirectTo: '/register_piece',
|
redirectTo: {
|
||||||
shouldRedirect: () => true
|
pathname: '/register_piece',
|
||||||
|
query: null
|
||||||
|
},
|
||||||
|
shouldRedirect: (pieceCount) => !pieceCount
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -120,10 +126,16 @@ let PieceList = React.createClass({
|
|||||||
const { location: { query }, redirectTo, shouldRedirect } = this.props;
|
const { location: { query }, redirectTo, shouldRedirect } = this.props;
|
||||||
const { unfilteredPieceListCount } = this.state;
|
const { unfilteredPieceListCount } = this.state;
|
||||||
|
|
||||||
if (redirectTo && unfilteredPieceListCount === 0 &&
|
if (redirectTo && redirectTo.pathname &&
|
||||||
(typeof shouldRedirect === 'function' && shouldRedirect(unfilteredPieceListCount))) {
|
(typeof shouldRedirect === 'function' && shouldRedirect(unfilteredPieceListCount))) {
|
||||||
// FIXME: hack to redirect out of the dispatch cycle
|
// 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() {
|
render() {
|
||||||
|
const { is_judge: isJudge, is_jury: isJury, is_admin: isAdmin } = this.state.currentUser;
|
||||||
|
|
||||||
setDocumentTitle(getLangText('Collection'));
|
setDocumentTitle(getLangText('Collection'));
|
||||||
|
|
||||||
let orderParams = ['artist_name', 'title'];
|
let orderParams = ['artist_name', 'title'];
|
||||||
if (this.state.currentUser.is_jury) {
|
if (isJury) {
|
||||||
orderParams = ['rating', 'title'];
|
orderParams = ['rating', 'title'];
|
||||||
}
|
}
|
||||||
if (this.state.currentUser.is_judge) {
|
if (isJudge) {
|
||||||
orderParams = ['rating', 'title', 'selected'];
|
orderParams = ['rating', 'title', 'selected'];
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
@ -80,7 +82,8 @@ let PrizePieceList = React.createClass({
|
|||||||
orderBy={this.state.currentUser.is_jury ? 'rating' : null}
|
orderBy={this.state.currentUser.is_jury ? 'rating' : null}
|
||||||
filterParams={[]}
|
filterParams={[]}
|
||||||
customSubmitButton={this.getButtonSubmit()}
|
customSubmitButton={this.getButtonSubmit()}
|
||||||
location={this.props.location}/>
|
location={this.props.location}
|
||||||
|
shouldRedirect={() => !(isJury || isJudge || isAdmin)} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
'use strict'
|
'use strict';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Moment from 'moment';
|
import Moment from 'moment';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
'use strict'
|
'use strict';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
'use strict'
|
'use strict';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
@ -6,11 +6,14 @@ import PieceList from '../../../../piece_list';
|
|||||||
import UserActions from '../../../../../actions/user_actions';
|
import UserActions from '../../../../../actions/user_actions';
|
||||||
import UserStore from '../../../../../stores/user_store';
|
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 CylandAccordionListItem from './cyland_accordion_list/cyland_accordion_list_item';
|
||||||
|
|
||||||
import { getLangText } from '../../../../../utils/lang_utils';
|
import { getLangText } from '../../../../../utils/lang_utils';
|
||||||
import { setDocumentTitle } from '../../../../../utils/dom_utils';
|
import { setDocumentTitle } from '../../../../../utils/dom_utils';
|
||||||
|
import { mergeOptions } from '../../../../../utils/general_utils';
|
||||||
|
|
||||||
let CylandPieceList = React.createClass({
|
let CylandPieceList = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
@ -18,15 +21,22 @@ let CylandPieceList = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return UserStore.getState();
|
return mergeOptions(
|
||||||
|
UserStore.getState(),
|
||||||
|
WhitelabelStore.getState()
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
UserStore.listen(this.onChange);
|
UserStore.listen(this.onChange);
|
||||||
|
WhitelabelStore.listen(this.onChange);
|
||||||
|
|
||||||
|
WhitelabelActions.fetchWhitelabel();
|
||||||
UserActions.fetchCurrentUser();
|
UserActions.fetchCurrentUser();
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
WhitelabelStore.unlisten(this.onChange);
|
||||||
UserStore.unlisten(this.onChange);
|
UserStore.unlisten(this.onChange);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -34,13 +44,28 @@ let CylandPieceList = React.createClass({
|
|||||||
this.setState(state);
|
this.setState(state);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
shouldRedirect(pieceCount) {
|
||||||
|
const { currentUser: { email: userEmail },
|
||||||
|
whitelabel: {
|
||||||
|
user: whitelabelAdminEmail
|
||||||
|
} } = this.state;
|
||||||
|
|
||||||
|
return userEmail !== whitelabelAdminEmail && !pieceCount;
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
setDocumentTitle(getLangText('Collection'));
|
setDocumentTitle(getLangText('Collection'));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<PieceList
|
<PieceList
|
||||||
redirectTo="/register_piece?slide_num=0"
|
redirectTo={{
|
||||||
|
pathname: '/register_piece',
|
||||||
|
query: {
|
||||||
|
'slide_num': 0
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
shouldRedirect={this.shouldRedirect}
|
||||||
accordionListItemType={CylandAccordionListItem}
|
accordionListItemType={CylandAccordionListItem}
|
||||||
filterParams={[{
|
filterParams={[{
|
||||||
label: getLangText('Show works I have'),
|
label: getLangText('Show works I have'),
|
||||||
|
@ -6,8 +6,12 @@ import PieceList from '../../../../piece_list';
|
|||||||
|
|
||||||
import UserActions from '../../../../../actions/user_actions';
|
import UserActions from '../../../../../actions/user_actions';
|
||||||
import UserStore from '../../../../../stores/user_store';
|
import UserStore from '../../../../../stores/user_store';
|
||||||
|
|
||||||
import NotificationStore from '../../../../../stores/notification_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 IkonotvAccordionListItem from './ikonotv_accordion_list/ikonotv_accordion_list_item';
|
||||||
|
|
||||||
import { setDocumentTitle } from '../../../../../utils/dom_utils';
|
import { setDocumentTitle } from '../../../../../utils/dom_utils';
|
||||||
@ -23,31 +27,41 @@ let IkonotvPieceList = React.createClass({
|
|||||||
getInitialState() {
|
getInitialState() {
|
||||||
return mergeOptions(
|
return mergeOptions(
|
||||||
NotificationStore.getState(),
|
NotificationStore.getState(),
|
||||||
UserStore.getState()
|
UserStore.getState(),
|
||||||
|
WhitelabelStore.getState()
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
NotificationStore.listen(this.onChange);
|
NotificationStore.listen(this.onChange);
|
||||||
|
WhitelabelStore.listen(this.onChange);
|
||||||
UserStore.listen(this.onChange);
|
UserStore.listen(this.onChange);
|
||||||
|
|
||||||
|
WhitelabelActions.fetchWhitelabel();
|
||||||
UserActions.fetchCurrentUser();
|
UserActions.fetchCurrentUser();
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
NotificationStore.unlisten(this.onChange);
|
NotificationStore.unlisten(this.onChange);
|
||||||
|
WhitelabelStore.unlisten(this.onChange);
|
||||||
UserStore.unlisten(this.onChange);
|
UserStore.unlisten(this.onChange);
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(state) {
|
onChange(state) {
|
||||||
this.setState(state);
|
this.setState(state);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
redirectIfNoContractNotifications() {
|
shouldRedirect(pieceCount) {
|
||||||
const { contractAgreementListNotifications } = this.state;
|
const { contractAgreementListNotifications,
|
||||||
|
currentUser: { email: userEmail },
|
||||||
|
whitelabel: {
|
||||||
|
user: whitelabelAdminEmail
|
||||||
|
} } = this.state;
|
||||||
|
|
||||||
return contractAgreementListNotifications && !contractAgreementListNotifications.length;
|
return contractAgreementListNotifications &&
|
||||||
|
!contractAgreementListNotifications.length &&
|
||||||
|
userEmail !== whitelabelAdminEmail &&
|
||||||
|
!pieceCount;
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -56,8 +70,13 @@ let IkonotvPieceList = React.createClass({
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<PieceList
|
<PieceList
|
||||||
redirectTo="/register_piece?slide_num=0"
|
redirectTo={{
|
||||||
shouldRedirect={this.redirectIfNoContractNotifications}
|
pathname: '/register_piece',
|
||||||
|
query: {
|
||||||
|
'slide_num': 0
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
shouldRedirect={this.shouldRedirect}
|
||||||
accordionListItemType={IkonotvAccordionListItem}
|
accordionListItemType={IkonotvAccordionListItem}
|
||||||
filterParams={[{
|
filterParams={[{
|
||||||
label: getLangText('Show works I have'),
|
label: getLangText('Show works I have'),
|
||||||
|
@ -59,11 +59,12 @@ let MarketPieceList = React.createClass({
|
|||||||
} } = this.state;
|
} } = this.state;
|
||||||
|
|
||||||
let filterParams = null;
|
let filterParams = null;
|
||||||
|
let isUserAdmin = null;
|
||||||
let canLoadPieceList = false;
|
let canLoadPieceList = false;
|
||||||
|
|
||||||
if (userEmail && whitelabelAdminEmail) {
|
if (userEmail && whitelabelAdminEmail) {
|
||||||
canLoadPieceList = true;
|
canLoadPieceList = true;
|
||||||
const isUserAdmin = userEmail === whitelabelAdminEmail;
|
isUserAdmin = userEmail === whitelabelAdminEmail;
|
||||||
|
|
||||||
filterParams = [{
|
filterParams = [{
|
||||||
label: getLangText('Show works I can'),
|
label: getLangText('Show works I can'),
|
||||||
@ -78,7 +79,13 @@ let MarketPieceList = React.createClass({
|
|||||||
return (
|
return (
|
||||||
<PieceList
|
<PieceList
|
||||||
canLoadPieceList={canLoadPieceList}
|
canLoadPieceList={canLoadPieceList}
|
||||||
redirectTo="/register_piece?slide_num=0"
|
redirectTo={{
|
||||||
|
pathname: '/register_piece',
|
||||||
|
query: {
|
||||||
|
'slide_num': 0
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
shouldRedirect={(pieceCount) => !isUserAdmin && !pieceCount}
|
||||||
bulkModalButtonListType={MarketAclButtonList}
|
bulkModalButtonListType={MarketAclButtonList}
|
||||||
customThumbnailPlaceholder={customThumbnailPlaceholder}
|
customThumbnailPlaceholder={customThumbnailPlaceholder}
|
||||||
filterParams={filterParams}
|
filterParams={filterParams}
|
||||||
|
@ -112,12 +112,11 @@ let MarketRegisterPiece = React.createClass({
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { location } = this.props;
|
const { location } = this.props;
|
||||||
const {
|
const { piece,
|
||||||
piece,
|
step,
|
||||||
step,
|
whitelabel: {
|
||||||
whitelabel: {
|
name: whitelabelName = 'Market'
|
||||||
name: whitelabelName = 'Market'
|
} } = this.state;
|
||||||
} } = this.state;
|
|
||||||
|
|
||||||
setDocumentTitle(getLangText('Register a new piece'));
|
setDocumentTitle(getLangText('Register a new piece'));
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
'use strict'
|
'use strict';
|
||||||
|
|
||||||
// TODO: Create Unittests that test all functions
|
// TODO: Create Unittests that test all functions
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
'use strict'
|
'use strict';
|
||||||
|
|
||||||
import camelCase from 'camelcase';
|
import camelCase from 'camelcase';
|
||||||
import decamelize from 'decamelize';
|
import decamelize from 'decamelize';
|
||||||
|
Loading…
Reference in New Issue
Block a user