OrgDetailsPage.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { PureComponent } from 'react';
  2. import { hot } from 'react-hot-loader';
  3. import { connect } from 'react-redux';
  4. import Page from 'app/core/components/Page/Page';
  5. import OrgProfile from './OrgProfile';
  6. import SharedPreferences from 'app/core/components/SharedPreferences/SharedPreferences';
  7. import { loadOrganization, setOrganizationName, updateOrganization } from './state/actions';
  8. import { Organization, StoreState } from 'app/types';
  9. import { getNavModel } from 'app/core/selectors/navModel';
  10. import { NavModel } from '@grafana/data';
  11. export interface Props {
  12. navModel: NavModel;
  13. organization: Organization;
  14. loadOrganization: typeof loadOrganization;
  15. setOrganizationName: typeof setOrganizationName;
  16. updateOrganization: typeof updateOrganization;
  17. }
  18. export class OrgDetailsPage extends PureComponent<Props> {
  19. async componentDidMount() {
  20. await this.props.loadOrganization();
  21. }
  22. onOrgNameChange = (name: string) => {
  23. this.props.setOrganizationName(name);
  24. };
  25. onUpdateOrganization = () => {
  26. this.props.updateOrganization();
  27. };
  28. render() {
  29. const { navModel, organization } = this.props;
  30. const isLoading = Object.keys(organization).length === 0;
  31. return (
  32. <Page navModel={navModel}>
  33. <Page.Contents isLoading={isLoading}>
  34. {!isLoading && (
  35. <div>
  36. <OrgProfile
  37. onOrgNameChange={name => this.onOrgNameChange(name)}
  38. onSubmit={this.onUpdateOrganization}
  39. orgName={organization.name}
  40. />
  41. <SharedPreferences resourceUri="org" />
  42. </div>
  43. )}
  44. </Page.Contents>
  45. </Page>
  46. );
  47. }
  48. }
  49. function mapStateToProps(state: StoreState) {
  50. return {
  51. navModel: getNavModel(state.navIndex, 'org-settings'),
  52. organization: state.organization.organization,
  53. };
  54. }
  55. const mapDispatchToProps = {
  56. loadOrganization,
  57. setOrganizationName,
  58. updateOrganization,
  59. };
  60. export default hot(module)(
  61. connect(
  62. mapStateToProps,
  63. mapDispatchToProps
  64. )(OrgDetailsPage)
  65. );