grafana/public/app/features/org/OrgDetailsPage.tsx

71 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-10-25 00:45:22 -05:00
import React, { PureComponent } from 'react';
import { hot } from 'react-hot-loader';
import { connect } from 'react-redux';
import Page from 'app/core/components/Page/Page';
2018-10-25 09:56:49 -05:00
import OrgProfile from './OrgProfile';
import SharedPreferences from 'app/core/components/SharedPreferences/SharedPreferences';
import { loadOrganization, setOrganizationName, updateOrganization } from './state/actions';
import { NavModel, Organization, StoreState } from 'app/types';
import { getNavModel } from 'app/core/selectors/navModel';
2018-10-25 00:45:22 -05:00
export interface Props {
navModel: NavModel;
2018-10-25 09:56:49 -05:00
organization: Organization;
loadOrganization: typeof loadOrganization;
2018-10-26 07:15:37 -05:00
setOrganizationName: typeof setOrganizationName;
updateOrganization: typeof updateOrganization;
2018-10-25 00:45:22 -05:00
}
2018-10-26 07:15:37 -05:00
export class OrgDetailsPage extends PureComponent<Props> {
2018-10-25 00:45:22 -05:00
async componentDidMount() {
2018-10-26 07:15:37 -05:00
await this.props.loadOrganization();
2018-10-25 00:45:22 -05:00
}
onOrgNameChange = name => {
this.props.setOrganizationName(name);
2018-10-25 00:45:22 -05:00
};
onUpdateOrganization = () => {
this.props.updateOrganization();
};
2018-10-25 00:45:22 -05:00
2018-10-25 09:56:49 -05:00
render() {
const { navModel, organization } = this.props;
const isLoading = Object.keys(organization).length === 0;
2018-10-25 00:45:22 -05:00
return (
<Page navModel={navModel}>
<Page.Contents isLoading={isLoading}>
<div className="page-container page-body">
{!isLoading && (
<div>
<OrgProfile
onOrgNameChange={name => this.onOrgNameChange(name)}
onSubmit={this.onUpdateOrganization}
orgName={organization.name}
/>
<SharedPreferences resourceUri="org" />
</div>
)}
2018-10-25 00:45:22 -05:00
</div>
</Page.Contents>
</Page>
2018-10-25 00:45:22 -05:00
);
}
}
function mapStateToProps(state: StoreState) {
return {
navModel: getNavModel(state.navIndex, 'org-settings'),
2018-10-26 07:15:37 -05:00
organization: state.organization.organization,
2018-10-25 00:45:22 -05:00
};
}
const mapDispatchToProps = {
2018-10-25 09:56:49 -05:00
loadOrganization,
2018-10-26 07:15:37 -05:00
setOrganizationName,
updateOrganization,
2018-10-25 00:45:22 -05:00
};
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(OrgDetailsPage));