OrgDetailsPage.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 { NavModel, Organization, StoreState } from 'app/types';
  9. import { getNavModel } from 'app/core/selectors/navModel';
  10. export interface Props {
  11. navModel: NavModel;
  12. organization: Organization;
  13. loadOrganization: typeof loadOrganization;
  14. setOrganizationName: typeof setOrganizationName;
  15. updateOrganization: typeof updateOrganization;
  16. }
  17. export class OrgDetailsPage extends PureComponent<Props> {
  18. async componentDidMount() {
  19. await this.props.loadOrganization();
  20. }
  21. onOrgNameChange = name => {
  22. this.props.setOrganizationName(name);
  23. };
  24. onUpdateOrganization = () => {
  25. this.props.updateOrganization();
  26. };
  27. render() {
  28. const { navModel, organization } = this.props;
  29. const isLoading = Object.keys(organization).length === 0;
  30. return (
  31. <Page navModel={navModel}>
  32. <Page.Contents isLoading={isLoading}>
  33. <div className="page-container page-body">
  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. </div>
  45. </Page.Contents>
  46. </Page>
  47. );
  48. }
  49. }
  50. function mapStateToProps(state: StoreState) {
  51. return {
  52. navModel: getNavModel(state.navIndex, 'org-settings'),
  53. organization: state.organization.organization,
  54. };
  55. }
  56. const mapDispatchToProps = {
  57. loadOrganization,
  58. setOrganizationName,
  59. updateOrganization,
  60. };
  61. export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(OrgDetailsPage));