1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 00:28:00 +02:00
onion/js/components/whitelabel/wallet/wallet_app.js

100 lines
3.2 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
2016-01-11 16:26:36 +01:00
import classNames from 'classnames';
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 AppRouteWrapper from '../../app_route_wrapper';
import Header from '../../header';
import Footer from '../../footer';
import GlobalNotification from '../../global_notification';
2016-01-11 16:26:36 +01:00
import { getSubdomain, mergeOptions } from '../../../utils/general_utils';
let WalletApp = React.createClass({
propTypes: {
2016-01-12 15:05:00 +01:00
history: React.PropTypes.object.isRequired,
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element
2016-01-12 15:05:00 +01:00
])
},
2015-08-19 14:48:22 +02:00
2016-01-11 16:26:36 +01:00
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() {
2016-01-12 15:05:00 +01:00
const { children, history, routes } = this.props;
const { currentUser, whitelabel } = this.state;
2016-01-11 16:26:36 +01:00
const subdomain = getSubdomain();
2015-10-01 15:57:46 +02:00
// 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;
2015-10-01 16:11:29 +02:00
2016-01-11 16:26:36 +01:00
let header = null;
2015-10-01 16:11:29 +02:00
// if the path of the current activeRoute is not defined, then this is the IndexRoute
if ((!path || history.isActive('/login') || history.isActive('/signup') || history.isActive('/contract_notifications'))
&& (['cyland', 'ikonotv', 'lumenus', '23vivi']).indexOf(subdomain) > -1) {
header = (<div className="hero"/>);
2015-08-19 14:48:22 +02:00
} else {
header = (
<Header
currentUser={currentUser}
routes={routes}
whitelabel={whitelabel} />
);
2015-08-19 14:48:22 +02:00
}
2015-10-01 15:57:46 +02:00
// In react-router 1.0, Routes have no 'name' property anymore. To keep functionality however,
// we split the path by the first occurring slash and take the first splitter.
return (
2015-10-01 15:57:46 +02:00
<div className={classNames('ascribe-wallet-app', 'route--' + (path ? path.split('/')[0] : 'landing'))}>
2015-09-18 15:36:01 +02:00
<div className='container'>
{header}
2016-01-11 16:26:36 +01:00
<AppRouteWrapper
currentUser={currentUser}
whitelabel={whitelabel}>
{/* Routes are injected here */}
{children}
</AppRouteWrapper>
<Footer />
2015-09-18 15:36:01 +02:00
<GlobalNotification />
<div id="modal" className="container"></div>
</div>
</div>
);
}
});
export default WalletApp;