diff --git a/js/components/ascribe_settings/settings_container.js b/js/components/ascribe_settings/settings_container.js index 594341a5..3b9a1694 100644 --- a/js/components/ascribe_settings/settings_container.js +++ b/js/components/ascribe_settings/settings_container.js @@ -36,7 +36,7 @@ let SettingsContainer = React.createClass({ }, render() { - const { currentUser, whitelabel } = this.props; + const { children, currentUser, whitelabel } = this.props; setDocumentTitle(getLangText('Account settings')); @@ -47,7 +47,7 @@ let SettingsContainer = React.createClass({ currentUser={currentUser} loadUser={this.loadUser} whitelabel={whitelabel} /> - {this.props.children} + {children} diff --git a/js/components/register_piece.js b/js/components/register_piece.js index f0f5b241..e778d35e 100644 --- a/js/components/register_piece.js +++ b/js/components/register_piece.js @@ -77,7 +77,7 @@ let RegisterPiece = React.createClass( { }, getSpecifyEditions() { - if (this.props.whitelabel && this.props.whitelabel.acl_create_editions || Object.keys(this.props.whitelabel).length === 0) { + if (this.props.whitelabel && (this.props.whitelabel.acl_create_editions || Object.keys(this.props.whitelabel).length)) { return (
- {this.state.message} + {message}
); @@ -50,7 +53,7 @@ let SignupContainer = React.createClass({
+ location={location}/>
{getLangText('Already an ascribe user')}? {getLangText('Log in')}...
diff --git a/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js b/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js index e3d5ab93..2f5954ac 100644 --- a/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js +++ b/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js @@ -30,9 +30,8 @@ const { object } = React.PropTypes; const PRRegisterPieceForm = React.createClass({ propTypes: { - location: object, - history: object, - currentUser: object + currentUser: object, + location: object }, mixins: [History], diff --git a/js/components/whitelabel/prize/portfolioreview/components/pr_landing.js b/js/components/whitelabel/prize/portfolioreview/components/pr_landing.js index cdada68b..d24f1cee 100644 --- a/js/components/whitelabel/prize/portfolioreview/components/pr_landing.js +++ b/js/components/whitelabel/prize/portfolioreview/components/pr_landing.js @@ -3,43 +3,39 @@ import React from 'react'; import { History } from 'react-router'; -import PrizeActions from '../../simple_prize/actions/prize_actions'; -import PrizeStore from '../../simple_prize/stores/prize_store'; - import Button from 'react-bootstrap/lib/Button'; import ButtonGroup from 'react-bootstrap/lib/ButtonGroup'; import LinkContainer from 'react-router-bootstrap/lib/LinkContainer'; -import UserStore from '../../../../../stores/user_store'; -import UserActions from '../../../../../actions/user_actions'; +import PrizeActions from '../../simple_prize/actions/prize_actions'; +import PrizeStore from '../../simple_prize/stores/prize_store'; -import { mergeOptions } from '../../../../../utils/general_utils'; import { getLangText } from '../../../../../utils/lang_utils'; const PRLanding = React.createClass({ propTypes: { + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, + + //Provided from router location: React.PropTypes.object }, mixins: [History], getInitialState() { - return mergeOptions( - PrizeStore.getState(), - UserStore.getState() - ); + return PrizeStore.getState(); }, componentDidMount() { const { location } = this.props; - UserStore.listen(this.onChange); - UserActions.fetchCurrentUser(); PrizeStore.listen(this.onChange); PrizeActions.fetchPrize(); - if(location && location.query && location.query.redirect) { + if (location && location.query && location.query.redirect) { let queryCopy = JSON.parse(JSON.stringify(location.query)); delete queryCopy.redirect; window.setTimeout(() => this.history.replaceState(null, `/${location.query.redirect}`, queryCopy)); @@ -47,7 +43,6 @@ const PRLanding = React.createClass({ }, componentWillUnmount() { - UserStore.unlisten(this.onChange); PrizeStore.unlisten(this.onChange); }, @@ -56,7 +51,7 @@ const PRLanding = React.createClass({ }, getButtons() { - if (this.state.prize && this.state.prize.active){ + if (this.state.prize && this.state.prize.active) { return ( @@ -75,39 +70,37 @@ const PRLanding = React.createClass({ ); - } - return ( - - - {getLangText('Sign up to ascribe')} - + } else { + return ( + + + {getLangText('Sign up to ascribe')} + -

- {getLangText('or, already an ascribe user?')} -

- - - -
- ); +

+ {getLangText('or, already an ascribe user?')} +

+ + + +
+ ); + } }, getTitle() { - if (this.state.prize && this.state.prize.active){ - return ( -

- {getLangText('This is the submission page for Portfolio Review 2016.')} -

- ); - } + const { prize } = this.state; + return (

- {getLangText('Submissions for Portfolio Review 2016 are now closed.')} + {getLangText(prize && prize.active ? 'This is the submission page for Portfolio Review 2016.' + : 'Submissions for Portfolio Review 2016 are now closed.')}

); }, + render() { return (
@@ -125,4 +118,4 @@ const PRLanding = React.createClass({ } }); -export default PRLanding; \ No newline at end of file +export default PRLanding; diff --git a/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js b/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js index d7aa1aa8..a78a2196 100644 --- a/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js +++ b/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js @@ -6,9 +6,6 @@ import { Link, History } from 'react-router'; import Col from 'react-bootstrap/lib/Col'; import Row from 'react-bootstrap/lib/Row'; -import UserStore from '../../../../../stores/user_store'; -import UserActions from '../../../../../actions/user_actions'; - import PRRegisterPieceForm from './pr_forms/pr_register_piece_form'; import { getLangText } from '../../../../../utils/lang_utils'; @@ -20,43 +17,31 @@ const { object } = React.PropTypes; const PRRegisterPiece = React.createClass({ propTypes: { + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, + + //Provided from router location: object }, mixins: [History], - getInitialState() { - return UserStore.getState(); - }, - - componentDidMount() { - UserStore.listen(this.onChange); - UserActions.fetchCurrentUser(); - }, - componentDidUpdate() { - const { currentUser } = this.state; - if(currentUser && currentUser.email) { + const { currentUser } = this.props; + if (currentUser && currentUser.email) { const submittedPieceId = getCookie(currentUser.email); - if(submittedPieceId) { + if (submittedPieceId) { this.history.pushState(null, `/pieces/${submittedPieceId}`); } } }, - componentWillUnmount() { - UserStore.unlisten(this.onChange); - }, - - onChange(state) { - this.setState(state); - }, - render() { - const { currentUser } = this.state; - const { location } = this.props; + const { currentUser, location } = this.props; setDocumentTitle(getLangText('Submit to Portfolio Review')); + return ( @@ -77,7 +62,7 @@ const PRRegisterPiece = React.createClass({ + currentUser={currentUser} /> ); diff --git a/js/components/whitelabel/prize/portfolioreview/pr_app.js b/js/components/whitelabel/prize/portfolioreview/pr_app.js index 30e5ee75..f6364bc8 100644 --- a/js/components/whitelabel/prize/portfolioreview/pr_app.js +++ b/js/components/whitelabel/prize/portfolioreview/pr_app.js @@ -1,17 +1,21 @@ 'use strict'; import React from 'react'; -import GlobalNotification from '../../../global_notification'; - -import Hero from './components/pr_hero'; -import Header from '../../../header'; import EventActions from '../../../../actions/event_actions'; import UserStore from '../../../../stores/user_store'; import UserActions from '../../../../actions/user_actions'; -import { getSubdomain } from '../../../../utils/general_utils'; +import WhitelabelActions from '../../../../actions/whitelabel_actions'; +import WhitelabelStore from '../../../../stores/whitelabel_store'; + +import AppRouteWrapper from '../../../app_route_wrapper'; +import Hero from './components/pr_hero'; +import Header from '../../../header'; +import GlobalNotification from '../../../global_notification'; + +import { getSubdomain, mergeOptions } from '../../../../utils/general_utils'; import { getCookie } from '../../../../utils/fetch_api_utils'; @@ -26,16 +30,23 @@ let PRApp = React.createClass({ }, getInitialState() { - return UserStore.getState(); + return mergeOptions( + UserStore.getState(), + WhitelabelStore.getState() + ); }, componentDidMount() { UserStore.listen(this.onChange); + WhitelabelStore.listen(this.onChange); + UserActions.fetchCurrentUser(); + WhitelabelActions.fetchWhitelabel(); }, componentWillUnmount() { UserStore.unlisten(this.onChange); + WhitelabelActions.unlisten(this.onChange); }, onChange(state) { @@ -43,13 +54,20 @@ let PRApp = React.createClass({ }, render() { - const { history, children, routes } = this.props; - const { currentUser } = this.state; + const { children, history, routes } = this.props; + const { currentUser, whitelabel } = this.state; + const subdomain = getSubdomain(); + + // Add the current user and whitelabel settings to all child routes + const childrenWithProps = React.Children.map(children, (child) => { + return React.cloneElement(child, { + currentUser, + whitelabel + }); + }); + let style = {}; - let subdomain = getSubdomain(); let header; - - if (currentUser && currentUser.email && history.isActive(`/pieces/${getCookie(currentUser.email)}`)) { header = ; style = { paddingTop: '0 !important' }; @@ -65,7 +83,12 @@ let PRApp = React.createClass({
- {children} + + {/* Routes are injected here */} + {children} +
diff --git a/js/components/whitelabel/prize/prize_routes.js b/js/components/whitelabel/prize/prize_routes.js index 5f80b30c..e727b3e4 100644 --- a/js/components/whitelabel/prize/prize_routes.js +++ b/js/components/whitelabel/prize/prize_routes.js @@ -31,7 +31,7 @@ import { AuthPrizeRoleRedirect } from './portfolioreview/components/pr_routes/pr const ROUTES = { sluice: ( - + @@ -63,7 +63,7 @@ const ROUTES = { ), portfolioreview: ( - + diff --git a/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js b/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js index c5ab2c81..9a4cd39c 100644 --- a/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js +++ b/js/components/whitelabel/prize/simple_prize/components/ascribe_detail/prize_piece_container.js @@ -19,9 +19,6 @@ import PieceStore from '../../../../../../stores/piece_store'; import PieceListStore from '../../../../../../stores/piece_list_store'; import PieceListActions from '../../../../../../actions/piece_list_actions'; -import UserStore from '../../../../../../stores/user_store'; -import UserActions from '../../../../../../actions/user_actions'; - import Piece from '../../../../../../components/ascribe_detail/piece'; import Note from '../../../../../../components/ascribe_detail/note'; @@ -53,8 +50,15 @@ import { setDocumentTitle } from '../../../../../../utils/dom_utils'; */ let PrizePieceContainer = React.createClass({ propTypes: { - params: React.PropTypes.object, - selectedPrizeActionButton: React.PropTypes.func + selectedPrizeActionButton: React.PropTypes.func, + + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, + + //Provided from router + location: React.PropTypes.object, + params: React.PropTypes.object }, mixins: [ReactError], @@ -62,7 +66,7 @@ let PrizePieceContainer = React.createClass({ getInitialState() { //FIXME: this component uses the PieceStore, but we avoid using the getState() here since it may contain stale data // It should instead use something like getInitialState() where that call also resets the state. - return UserStore.getState(); + return {}; }, componentWillMount() { @@ -74,9 +78,7 @@ let PrizePieceContainer = React.createClass({ componentDidMount() { PieceStore.listen(this.onChange); - UserStore.listen(this.onChange); - UserActions.fetchCurrentUser(); this.loadPiece(); }, @@ -99,7 +101,6 @@ let PrizePieceContainer = React.createClass({ componentWillUnmount() { PieceStore.unlisten(this.onChange); - UserStore.unlisten(this.onChange); }, onChange(state) { @@ -107,7 +108,8 @@ let PrizePieceContainer = React.createClass({ }, getActions() { - const { currentUser, piece } = this.state; + const { currentUser } = this.props; + const { piece } = this.state; if (piece && piece.notifications && piece.notifications.length > 0) { return ( @@ -124,8 +126,8 @@ let PrizePieceContainer = React.createClass({ }, render() { - const { selectedPrizeActionButton } = this.props; - const { currentUser, piece } = this.state; + const { currentUser, selectedPrizeActionButton } = this.props; + const { piece } = this.state; if (piece && piece.id) { /* diff --git a/js/components/whitelabel/prize/simple_prize/components/prize_landing.js b/js/components/whitelabel/prize/simple_prize/components/prize_landing.js index e26a05b5..17c2e0c1 100644 --- a/js/components/whitelabel/prize/simple_prize/components/prize_landing.js +++ b/js/components/whitelabel/prize/simple_prize/components/prize_landing.js @@ -1,57 +1,47 @@ 'use strict'; import React from 'react'; -import { History } from 'react-router'; - -import PrizeActions from '../actions/prize_actions'; -import PrizeStore from '../stores/prize_store'; import Button from 'react-bootstrap/lib/Button'; import ButtonGroup from 'react-bootstrap/lib/ButtonGroup'; import LinkContainer from 'react-router-bootstrap/lib/LinkContainer'; -import UserStore from '../../../../../stores/user_store'; -import UserActions from '../../../../../actions/user_actions'; +import PrizeActions from '../actions/prize_actions'; +import PrizeStore from '../stores/prize_store'; -import { mergeOptions } from '../../../../../utils/general_utils'; import { getLangText } from '../../../../../utils/lang_utils'; -let Landing = React.createClass({ - mixins: [History], +let Landing = React.createClass({ + propTypes: { + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, + + //Provided from router + location: React.PropTypes.object + }, getInitialState() { - return mergeOptions( - PrizeStore.getState(), - UserStore.getState() - ); + return PrizeStore.getState(); }, componentDidMount() { - UserStore.listen(this.onChange); - UserActions.fetchCurrentUser(); PrizeStore.listen(this.onChange); PrizeActions.fetchPrize(); }, componentWillUnmount() { - UserStore.unlisten(this.onChange); PrizeStore.unlisten(this.onChange); }, onChange(state) { this.setState(state); - - // if user is already logged in, redirect him to piece list - if(this.state.currentUser && this.state.currentUser.email) { - // FIXME: hack to redirect out of the dispatch cycle - window.setTimeout(() => this.history.replaceState(null, '/collection'), 0); - } }, getButtons() { - if (this.state.prize && this.state.prize.active){ + if (this.state.prize && this.state.prize.active) { return ( @@ -70,39 +60,37 @@ let Landing = React.createClass({ ); - } - return ( - - - {getLangText('Sign up to ascribe')} - + } else { + return ( + + + {getLangText('Sign up to ascribe')} + -

- {getLangText('or, already an ascribe user?')} -

- - - -
- ); +

+ {getLangText('or, already an ascribe user?')} +

+ + + +
+ ); + } }, getTitle() { - if (this.state.prize && this.state.prize.active){ - return ( -

- {getLangText('This is the submission page for Sluice_screens ↄc Prize 2015.')} -

- ); - } + const { prize } = this.state; + return (

- {getLangText('Submissions for Sluice_screens ↄc Prize 2015 are now closed.')} + {getLangText(prize && prize.active ? 'This is the submission page for Sluice_screens ↄc Prize 2015.' + : 'Submissions for Sluice_screens ↄc Prize 2015 are now closed.')}

); }, + render() { return (
diff --git a/js/components/whitelabel/prize/simple_prize/components/prize_login_container.js b/js/components/whitelabel/prize/simple_prize/components/prize_login_container.js index e168ca68..66466e3e 100644 --- a/js/components/whitelabel/prize/simple_prize/components/prize_login_container.js +++ b/js/components/whitelabel/prize/simple_prize/components/prize_login_container.js @@ -11,6 +11,11 @@ import { setDocumentTitle } from '../../../../../utils/dom_utils'; let LoginContainer = React.createClass({ propTypes: { + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, + + //Provided from router location: React.PropTypes.object }, 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 23cdbb23..4724cd68 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 @@ -1,19 +1,15 @@ 'use strict'; import React from 'react'; -import PieceList from '../../../../piece_list'; -import UserActions from '../../../../../actions/user_actions'; -import UserStore from '../../../../../stores/user_store'; +import Button from 'react-bootstrap/lib/Button'; +import LinkContainer from 'react-router-bootstrap/lib/LinkContainer'; import PrizeActions from '../actions/prize_actions'; import PrizeStore from '../stores/prize_store'; -import Button from 'react-bootstrap/lib/Button'; - -import LinkContainer from 'react-router-bootstrap/lib/LinkContainer'; - import AccordionListItemPrize from './ascribe_accordion_list/accordion_list_item_prize'; +import PieceList from '../../../../piece_list'; import { mergeOptions } from '../../../../../utils/general_utils'; import { getLangText } from '../../../../../utils/lang_utils'; @@ -21,25 +17,24 @@ import { setDocumentTitle } from '../../../../../utils/dom_utils'; let PrizePieceList = React.createClass({ propTypes: { + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, + + //Provided from router location: React.PropTypes.object }, getInitialState() { - return mergeOptions( - PrizeStore.getState(), - UserStore.getState() - ); + return PrizeStore.getState(); }, componentDidMount() { - UserStore.listen(this.onChange); - UserActions.fetchCurrentUser(); PrizeStore.listen(this.onChange); PrizeActions.fetchPrize(); }, componentWillUnmount() { - UserStore.unlisten(this.onChange); PrizeStore.unlisten(this.onChange); }, @@ -48,7 +43,8 @@ let PrizePieceList = React.createClass({ }, getButtonSubmit() { - const { currentUser, prize } = this.state; + const { currentUser } = this.props; + const { prize } = this.state; if (prize && prize.active && !currentUser.is_jury && !currentUser.is_admin && !currentUser.is_judge) { return ( @@ -57,32 +53,34 @@ let PrizePieceList = React.createClass({ ); + } else { + return null; } - return null; }, render() { + const { currentUser, location } = this.props; + setDocumentTitle(getLangText('Collection')); let orderParams = ['artist_name', 'title']; - if (this.state.currentUser.is_jury) { + if (currentUser.is_jury) { orderParams = ['rating', 'title']; } - if (this.state.currentUser.is_judge) { + if (currentUser.is_judge) { orderParams = ['rating', 'title', 'selected']; } + return ( -
- -
+ ); } }); diff --git a/js/components/whitelabel/prize/simple_prize/components/prize_register_piece.js b/js/components/whitelabel/prize/simple_prize/components/prize_register_piece.js index ca4e8fa9..60929a7e 100644 --- a/js/components/whitelabel/prize/simple_prize/components/prize_register_piece.js +++ b/js/components/whitelabel/prize/simple_prize/components/prize_register_piece.js @@ -16,6 +16,11 @@ import { setDocumentTitle } from '../../../../../utils/dom_utils'; let PrizeRegisterPiece = React.createClass({ propTypes: { + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, + + //Provided from router location: React.PropTypes.object }, @@ -38,62 +43,61 @@ let PrizeRegisterPiece = React.createClass({ render() { const { location } = this.props; + const { prize } = this.state; setDocumentTitle(getLangText('Submit to the prize')); - if(this.state.prize && this.state.prize.active){ + if (prize && prize.active) { return ( -
- - - - - - - - - - - {' ' + getLangText('I agree to the Terms of Service the art price') + ' '} - ( - {getLangText('read')} - ) - - - - -
+ + + + + + + + + + + {' ' + getLangText('I agree to the Terms of Service the art price') + ' '} + ( + {getLangText('read')} + ) + + + + ); - } - else { + } else { return (
{getLangText('The prize is no longer active')}
- ); + ); } } }); diff --git a/js/components/whitelabel/prize/simple_prize/components/prize_settings_container.js b/js/components/whitelabel/prize/simple_prize/components/prize_settings_container.js index b91f9789..22a004d4 100644 --- a/js/components/whitelabel/prize/simple_prize/components/prize_settings_container.js +++ b/js/components/whitelabel/prize/simple_prize/components/prize_settings_container.js @@ -2,8 +2,6 @@ import React from 'react'; -import UserStore from '../../../../../stores/user_store'; -import UserActions from '../../../../../actions/user_actions'; import PrizeActions from '../actions/prize_actions'; import PrizeStore from '../stores/prize_store'; import PrizeJuryActions from '../actions/prize_jury_actions'; @@ -28,40 +26,27 @@ import { setDocumentTitle } from '../../../../../utils/dom_utils'; let Settings = React.createClass({ - getInitialState() { - return UserStore.getState(); - }, + propTypes: { + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, - componentDidMount() { - UserStore.listen(this.onChange); - UserActions.fetchCurrentUser(); - }, - - componentWillUnmount() { - UserStore.unlisten(this.onChange); - }, - - onChange(state) { - this.setState(state); + //Provided from router + location: React.PropTypes.object }, render() { setDocumentTitle(getLangText('Account settings')); - let prizeSettings = null; - if (this.state.currentUser.is_admin){ - prizeSettings = ; - } return ( - - {prizeSettings} + + {this.props.currentUser.is_admin ? : null} ); } }); let PrizeSettings = React.createClass({ - getInitialState() { return PrizeStore.getState(); }, diff --git a/js/components/whitelabel/prize/simple_prize/components/prize_signup_container.js b/js/components/whitelabel/prize/simple_prize/components/prize_signup_container.js index 7a44d521..5bf222ba 100644 --- a/js/components/whitelabel/prize/simple_prize/components/prize_signup_container.js +++ b/js/components/whitelabel/prize/simple_prize/components/prize_signup_container.js @@ -8,6 +8,11 @@ import { setDocumentTitle } from '../../../../../utils/dom_utils'; let SignupContainer = React.createClass({ propTypes: { + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, + + //Provided from router location: React.PropTypes.object }, @@ -18,7 +23,7 @@ let SignupContainer = React.createClass({ }; }, - handleSuccess(message){ + handleSuccess(message) { this.setState({ submitted: true, message: message @@ -26,13 +31,15 @@ let SignupContainer = React.createClass({ }, render() { + const { location } = this.props; + const { message, submitted } = this.state; setDocumentTitle(getLangText('Sign up')); - if (this.state.submitted){ + if (submitted) { return (
- {this.state.message} + {message}
); @@ -43,7 +50,7 @@ let SignupContainer = React.createClass({ headerMessage={getLangText('Create account for submission')} submitMessage={getLangText('Sign up')} handleSuccess={this.handleSuccess} - location={this.props.location}/> + location={location} />
); } diff --git a/js/components/whitelabel/prize/simple_prize/prize_app.js b/js/components/whitelabel/prize/simple_prize/prize_app.js index d5b55d5f..a5cea483 100644 --- a/js/components/whitelabel/prize/simple_prize/prize_app.js +++ b/js/components/whitelabel/prize/simple_prize/prize_app.js @@ -1,12 +1,21 @@ 'use strict'; import React from 'react'; + +import UserStore from '../../../../stores/user_store'; +import UserActions from '../../../../actions/user_actions'; + +import WhitelabelActions from '../../../../actions/whitelabel_actions'; +import WhitelabelStore from '../../../../stores/whitelabel_store'; + import Hero from './components/prize_hero'; + +import AppRouteWrapper from '../../../app_route_wrapper'; import Header from '../../../header'; import Footer from '../../../footer'; import GlobalNotification from '../../../global_notification'; -import { getSubdomain } from '../../../../utils/general_utils'; +import { getSubdomain, mergeOptions } from '../../../../utils/general_utils'; let PrizeApp = React.createClass({ @@ -19,15 +28,40 @@ let PrizeApp = React.createClass({ routes: React.PropTypes.arrayOf(React.PropTypes.object) }, + getInitialState() { + return mergeOptions( + UserStore.getState(), + WhitelabelStore.getState() + ); + }, + + componentDidMount() { + UserStore.listen(this.onChange); + WhitelabelStore.listen(this.onChange); + + UserActions.fetchCurrentUser(); + WhitelabelActions.fetchWhitelabel(); + }, + + componentWillUnmount() { + UserStore.unlisten(this.onChange); + WhitelabelActions.unlisten(this.onChange); + }, + + onChange(state) { + this.setState(state); + }, + render() { - const { history, routes } = this.props; - let header = null; - let subdomain = getSubdomain(); + const { history, routes, children } = this.props; + const { currentUser, whitelabel } = this.state; + const subdomain = getSubdomain(); // The second element of routes is always the active component object, where we can // extract the path. let path = routes[1] ? routes[1].path : null; + let header = null; // if the path of the current activeRoute is not defined, then this is the IndexRoute if (!path || history.isActive('/login') || history.isActive('/signup')) { header = ; @@ -38,10 +72,15 @@ let PrizeApp = React.createClass({ return (
{header} - {this.props.children} + + {/* Routes are injected here */} + {children} + +
); } diff --git a/js/components/whitelabel/prize/sluice/components/sluice_detail/sluice_piece_container.js b/js/components/whitelabel/prize/sluice/components/sluice_detail/sluice_piece_container.js index 2d9debca..7ddd7953 100644 --- a/js/components/whitelabel/prize/sluice/components/sluice_detail/sluice_piece_container.js +++ b/js/components/whitelabel/prize/sluice/components/sluice_detail/sluice_piece_container.js @@ -8,6 +8,12 @@ import PrizePieceContainer from '../../../simple_prize/components/ascribe_detail const SluicePieceContainer = React.createClass({ propTypes: { + // Provided from PrizeApp + currentUser: React.PropTypes.object, + whitelabel: React.PropTypes.object, + + //Provided from router + location: React.PropTypes.object, params: React.PropTypes.object },