OrgDetailsPage.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. {!isLoading && (
  34. <div>
  35. <OrgProfile
  36. onOrgNameChange={name => this.onOrgNameChange(name)}
  37. onSubmit={this.onUpdateOrganization}
  38. orgName={organization.name}
  39. />
  40. <SharedPreferences resourceUri="org" />
  41. </div>
  42. )}
  43. </Page.Contents>
  44. </Page>
  45. );
  46. }
  47. }
  48. function mapStateToProps(state: StoreState) {
  49. return {
  50. navModel: getNavModel(state.navIndex, 'org-settings'),
  51. organization: state.organization.organization,
  52. };
  53. }
  54. const mapDispatchToProps = {
  55. loadOrganization,
  56. setOrganizationName,
  57. updateOrganization,
  58. };
  59. export default hot(module)(
  60. connect(
  61. mapStateToProps,
  62. mapDispatchToProps
  63. )(OrgDetailsPage)
  64. );