accountSettingsLayout.tsx 1.6 KB

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