accountSettingsLayout.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {Component} from 'react';
  2. import {fetchOrganizationDetails} from 'sentry/actionCreators/organizations';
  3. import {Client} from 'sentry/api';
  4. import SentryTypes from 'sentry/sentryTypes';
  5. import {Organization} from 'sentry/types';
  6. import withApi from 'sentry/utils/withApi';
  7. import withLatestContext from 'sentry/utils/withLatestContext';
  8. import AccountSettingsNavigation from 'sentry/views/settings/account/accountSettingsNavigation';
  9. import SettingsLayout from 'sentry/views/settings/components/settingsLayout';
  10. type Props = React.ComponentProps<typeof SettingsLayout> & {
  11. api: Client;
  12. organization: Organization;
  13. };
  14. class AccountSettingsLayout extends Component<Props> {
  15. static childContextTypes = {
  16. organization: SentryTypes.Organization,
  17. };
  18. getChildContext() {
  19. return {
  20. organization: this.props.organization,
  21. };
  22. }
  23. componentDidUpdate(prevProps: Props) {
  24. const {api, organization} = this.props;
  25. if (prevProps.organization === organization) {
  26. return;
  27. }
  28. // if there is no org in context, SidebarDropdown uses an org from `withLatestContext`
  29. // (which queries the org index endpoint instead of org details)
  30. // and does not have `access` info
  31. if (organization && typeof organization.access === 'undefined') {
  32. fetchOrganizationDetails(api, organization.slug, {
  33. setActive: true,
  34. loadProjects: true,
  35. });
  36. }
  37. }
  38. render() {
  39. const {organization} = this.props;
  40. return (
  41. <SettingsLayout
  42. {...this.props}
  43. renderNavigation={() => <AccountSettingsNavigation organization={organization} />}
  44. >
  45. {this.props.children}
  46. </SettingsLayout>
  47. );
  48. }
  49. }
  50. export default withLatestContext(withApi(AccountSettingsLayout));