diff --git a/js/components/ascribe_routes/proxy_handler.js b/js/components/ascribe_routes/proxy_handler.js index c5c60506..06b27422 100644 --- a/js/components/ascribe_routes/proxy_handler.js +++ b/js/components/ascribe_routes/proxy_handler.js @@ -41,6 +41,7 @@ export function AuthRedirect({to, when}) { // and redirect if `true`. if(exprToValidate) { window.setTimeout(() => history.replaceState(null, to, query)); + return true; // Otherwise there can also be the case that the backend // wants to redirect the user to a specific route when the user is logged out already @@ -48,6 +49,7 @@ export function AuthRedirect({to, when}) { delete query.redirect; window.setTimeout(() => history.replaceState(null, '/' + redirect, query)); + return true; } else if(!exprToValidate && when === 'loggedOut' && redirectAuthenticated) { /* @@ -60,7 +62,9 @@ export function AuthRedirect({to, when}) { * `baseUrl` + `redirectAuthenticated`, as it gets rid of queries as well. */ window.location = AppConstants.baseUrl + redirectAuthenticated; + return true; } + return false; }; } @@ -71,7 +75,7 @@ export function AuthRedirect({to, when}) { * * @param {[function]} redirectFn A function that conditionally redirects */ -export function ProxyHandler(redirectFn) { +export function ProxyHandler(...redirectFunctions) { return (Component) => { return React.createClass({ displayName: 'ProxyHandler', @@ -97,7 +101,15 @@ export function ProxyHandler(redirectFn) { if(!UserStore.isLoading()) { const { currentUser } = this.state; const { query } = this.props.location; - redirectFn(currentUser, query); + for(let i = 0; i < redirectFunctions.length; i++) { + // if a redirectFunction redirects the user, + // it should return `true` and therefore + // stop/avoid the execution of all functions + // that follow + if(redirectFunctions[i](currentUser, query)) { + break; + } + } } }, diff --git a/js/components/whitelabel/prize/portfolioreview/components/pr_routes/pr_proxy_handler.js b/js/components/whitelabel/prize/portfolioreview/components/pr_routes/pr_proxy_handler.js new file mode 100644 index 00000000..edaa6663 --- /dev/null +++ b/js/components/whitelabel/prize/portfolioreview/components/pr_routes/pr_proxy_handler.js @@ -0,0 +1,26 @@ +'use strict'; + +import history from '../../../../../../history'; + + +export function AuthPrizeRoleRedirect({ to, when }) { + if(when.constructor !== Array && when.length) { + throw new Error('`when` of AuthPrizeRoleRedirect must be an array containing values'); + } + if(!to && to.indexOf('/') !== -1) { + throw new Error('`to` of AuthPrizeRoleRedirect must be defined and contain a valid route'); + } + + return function(currentUser, query) { + const exprToValidate = when + .map((role) => currentUser[role]) + .reduce((a, b) => a || b); + + if(exprToValidate) { + window.setTimeout(() => history.replaceState(null, to, query)); + return true; + } else { + return false; + } + }; +} \ No newline at end of file diff --git a/js/components/whitelabel/prize/portfolioreview/pr_app.js b/js/components/whitelabel/prize/portfolioreview/pr_app.js index 7e66c43c..93b1a168 100644 --- a/js/components/whitelabel/prize/portfolioreview/pr_app.js +++ b/js/components/whitelabel/prize/portfolioreview/pr_app.js @@ -4,6 +4,7 @@ import React from 'react'; import GlobalNotification from '../../../global_notification'; import Hero from './components/pr_hero'; +import Header from '../../../header'; import UserStore from '../../../../stores/user_store'; import UserActions from '../../../../actions/user_actions'; @@ -42,17 +43,26 @@ let PRApp = React.createClass({ render() { const { history, children } = this.props; const { currentUser } = this.state; + let style = {}; let subdomain = getSubdomain(); let header; + if (currentUser && currentUser.email && history.isActive(`/pieces/${getCookie(currentUser.email)}`)) { header = ; + style = { paddingTop: '0 !important' }; + } else if(history.isActive('/collection') || history.isActive('/settings')) { + header =
; + } else { + style = { paddingTop: '0 !important' }; } return (
{header} -
+
{children} diff --git a/js/components/whitelabel/prize/prize_routes.js b/js/components/whitelabel/prize/prize_routes.js index 19215f08..896939ee 100644 --- a/js/components/whitelabel/prize/prize_routes.js +++ b/js/components/whitelabel/prize/prize_routes.js @@ -23,6 +23,7 @@ import CoaVerifyContainer from '../../coa_verify_container'; import ErrorNotFoundPage from '../../error_not_found_page'; import { ProxyHandler, AuthRedirect } from '../../../components/ascribe_routes/proxy_handler'; +import { AuthPrizeRoleRedirect } from './portfolioreview/components/pr_routes/pr_proxy_handler'; const ROUTES = { @@ -52,7 +53,6 @@ const ROUTES = { path='collection' component={ProxyHandler(AuthRedirect({to: '/login', when: 'loggedOut'}))(SPPieceList)} headerTitle='COLLECTION'/> - @@ -66,9 +66,16 @@ const ROUTES = { path='register_piece' component={ProxyHandler(AuthRedirect({to: '/login', when: 'loggedOut'}))(PRRegisterPiece)} headerTitle='+ NEW WORK'/> + + component={ProxyHandler( + AuthPrizeRoleRedirect({ to: '/collection', when: ['is_admin', 'is_judge', 'is_jury'] }), + AuthRedirect({to: '/register_piece', when: 'loggedIn'}) + )(SPLoginContainer)} /> @@ -78,7 +85,12 @@ const ROUTES = { + + + ) diff --git a/sass/whitelabel/prize/portfolioreview/portfolioreview_custom_style.scss b/sass/whitelabel/prize/portfolioreview/portfolioreview_custom_style.scss index d8ccd858..5b4dd559 100644 --- a/sass/whitelabel/prize/portfolioreview/portfolioreview_custom_style.scss +++ b/sass/whitelabel/prize/portfolioreview/portfolioreview_custom_style.scss @@ -2,7 +2,6 @@ $pr--nav-fg-prim-color: black; $pr--button-color: $pr--nav-fg-prim-color; .client--portfolioreview { - padding-top: 0 !important; .btn-wide, .btn-default {