organizationLayout.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import styled from '@emotion/styled';
  2. import {Alert} from 'sentry/components/alert';
  3. import HookOrDefault from 'sentry/components/hookOrDefault';
  4. import LoadingError from 'sentry/components/loadingError';
  5. import LoadingTriangle from 'sentry/components/loadingTriangle';
  6. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  7. import {ORGANIZATION_FETCH_ERROR_TYPES} from 'sentry/constants';
  8. import {t} from 'sentry/locale';
  9. import OrganizationStore from 'sentry/stores/organizationStore';
  10. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  11. import {space} from 'sentry/styles/space';
  12. import {useEnsureOrganization} from './organizationContext';
  13. interface OrganizationLayoutProps {
  14. children: React.ReactNode;
  15. }
  16. const OrganizationHeader = HookOrDefault({
  17. hookName: 'component:organization-header',
  18. });
  19. /**
  20. * Renders the organization page layout
  21. */
  22. function OrganizationLayout({children}: OrganizationLayoutProps) {
  23. const {organization, loading, error, errorType} = useLegacyStore(OrganizationStore);
  24. useEnsureOrganization();
  25. if (loading) {
  26. return <LoadingTriangle>{t('Loading data for your organization.')}</LoadingTriangle>;
  27. }
  28. if (error) {
  29. const errorBody =
  30. errorType === ORGANIZATION_FETCH_ERROR_TYPES.ORG_NO_ACCESS ? (
  31. <Alert type="error" data-test-id="org-access-error">
  32. {t('You do not have access to this organization.')}
  33. </Alert>
  34. ) : errorType === ORGANIZATION_FETCH_ERROR_TYPES.ORG_NOT_FOUND ? (
  35. <Alert type="error" data-test-id="org-loading-error">
  36. {t('The organization you were looking for was not found.')}
  37. </Alert>
  38. ) : (
  39. <LoadingError />
  40. );
  41. return <ErrorWrapper>{errorBody}</ErrorWrapper>;
  42. }
  43. return (
  44. <SentryDocumentTitle noSuffix title={organization?.name ?? 'Sentry'}>
  45. <div className="app">
  46. {organization && <OrganizationHeader organization={organization} />}
  47. {children}
  48. </div>
  49. </SentryDocumentTitle>
  50. );
  51. }
  52. const ErrorWrapper = styled('div')`
  53. padding: ${space(3)};
  54. `;
  55. export default OrganizationLayout;