accountSettingsLayout.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {Component, Fragment} from 'react';
  2. import {fetchOrganizationDetails} from 'sentry/actionCreators/organizations';
  3. import type {Client} from 'sentry/api';
  4. import {prefersStackedNav} from 'sentry/components/nav/prefersStackedNav';
  5. import type {Organization} from 'sentry/types/organization';
  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. componentDidUpdate(prevProps: Props) {
  16. const {api, organization} = this.props;
  17. if (prevProps.organization === organization) {
  18. return;
  19. }
  20. // if there is no org in context, SidebarDropdown uses an org from `withLatestContext`
  21. // (which queries the org index endpoint instead of org details)
  22. // and does not have `access` info
  23. if (organization && typeof organization.access === 'undefined') {
  24. fetchOrganizationDetails(api, organization.slug, {
  25. setActive: true,
  26. loadProjects: true,
  27. });
  28. }
  29. }
  30. render() {
  31. const {organization} = this.props;
  32. if (prefersStackedNav()) {
  33. return (
  34. <Fragment>
  35. <AccountSettingsNavigation organization={organization} />
  36. <SettingsLayout {...this.props}>{this.props.children}</SettingsLayout>
  37. </Fragment>
  38. );
  39. }
  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));