1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 17:45:10 +01:00
onion/js/components/ascribe_settings/settings_container.js

86 lines
2.4 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
2015-09-18 09:46:37 +02:00
import UserStore from '../../stores/user_store';
import UserActions from '../../actions/user_actions';
2015-09-23 15:41:12 +02:00
import WhitelabelStore from '../../stores/whitelabel_store';
import WhitelabelActions from '../../actions/whitelabel_actions';
import AccountSettings from './account_settings';
import BitcoinWalletSettings from './bitcoin_wallet_settings';
import APISettings from './api_settings';
2015-09-23 15:41:12 +02:00
import AclProxy from '../acl_proxy';
import { mergeOptions } from '../../utils/general_utils';
import { getLangText } from '../../utils/lang_utils';
import { setDocumentTitle } from '../../utils/dom_utils';
2015-09-23 15:41:12 +02:00
let SettingsContainer = React.createClass({
propTypes: {
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element])
},
2015-09-18 09:46:37 +02:00
getInitialState() {
2015-09-23 15:41:12 +02:00
return mergeOptions(
UserStore.getState(),
WhitelabelStore.getState()
);
2015-09-18 09:46:37 +02:00
},
componentDidMount() {
UserStore.listen(this.onChange);
2015-09-23 15:41:12 +02:00
WhitelabelStore.listen(this.onChange);
WhitelabelActions.fetchWhitelabel();
2015-09-18 09:46:37 +02:00
UserActions.fetchCurrentUser();
},
componentWillUnmount() {
2015-09-23 15:41:12 +02:00
WhitelabelStore.unlisten(this.onChange);
2015-09-18 09:46:37 +02:00
UserStore.unlisten(this.onChange);
},
loadUser(){
UserActions.fetchCurrentUser();
},
onChange(state) {
this.setState(state);
},
render() {
setDocumentTitle(getLangText('Account settings'));
2015-09-21 10:32:35 +02:00
if (this.state.currentUser && this.state.currentUser.username) {
return (
<div className="settings-container">
<AccountSettings
currentUser={this.state.currentUser}
loadUser={this.loadUser}
whitelabel={this.state.whitelabel}/>
2015-09-21 10:32:35 +02:00
{this.props.children}
2015-09-23 15:41:12 +02:00
<AclProxy
aclObject={this.state.whitelabel}
aclName="acl_view_settings_api">
<APISettings />
</AclProxy>
<AclProxy
aclObject={this.state.whitelabel}
aclName="acl_view_settings_bitcoin">
<BitcoinWalletSettings />
</AclProxy>
2015-09-21 10:32:35 +02:00
</div>
);
}
return null;
}
});
export default SettingsContainer;