noProjectMessage.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. /* TODO: replace with I/O when finished */
  4. import img from 'sentry-images/spot/hair-on-fire.svg';
  5. import Button from 'app/components/button';
  6. import ButtonBar from 'app/components/buttonBar';
  7. import PageHeading from 'app/components/pageHeading';
  8. import {t} from 'app/locale';
  9. import ConfigStore from 'app/stores/configStore';
  10. import space from 'app/styles/space';
  11. import {LightWeightOrganization, Organization, Project} from 'app/types';
  12. type Props = React.PropsWithChildren<{
  13. organization: LightWeightOrganization | Organization;
  14. projects?: Project[];
  15. loadingProjects?: boolean;
  16. superuserNeedsToBeProjectMember?: boolean;
  17. }>;
  18. export default function NoProjectMessage({
  19. children,
  20. organization,
  21. projects,
  22. loadingProjects,
  23. superuserNeedsToBeProjectMember,
  24. }: Props) {
  25. const orgSlug = organization.slug;
  26. const canCreateProject = organization.access.includes('project:write');
  27. const canJoinTeam = organization.access.includes('team:read');
  28. let orgHasProjects = false;
  29. let hasProjectAccess = false;
  30. if ('projects' in organization) {
  31. const {isSuperuser} = ConfigStore.get('user');
  32. orgHasProjects = organization.projects.length > 0;
  33. hasProjectAccess =
  34. isSuperuser && !superuserNeedsToBeProjectMember
  35. ? organization.projects.some(p => p.hasAccess)
  36. : organization.projects.some(p => p.isMember && p.hasAccess);
  37. } else {
  38. hasProjectAccess = projects ? projects.length > 0 : false;
  39. orgHasProjects = hasProjectAccess;
  40. }
  41. if (hasProjectAccess || loadingProjects) {
  42. return <Fragment>{children}</Fragment>;
  43. }
  44. // If the organization has some projects, but the user doesn't have access to
  45. // those projects, the primary action is to Join a Team. Otherwise the primary
  46. // action is to create a project.
  47. const joinTeamAction = (
  48. <Button
  49. title={canJoinTeam ? undefined : t('You do not have permission to join a team.')}
  50. disabled={!canJoinTeam}
  51. priority={orgHasProjects ? 'primary' : 'default'}
  52. to={`/settings/${orgSlug}/teams/`}
  53. >
  54. {t('Join a Team')}
  55. </Button>
  56. );
  57. const createProjectAction = (
  58. <Button
  59. title={
  60. canCreateProject
  61. ? undefined
  62. : t('You do not have permission to create a project.')
  63. }
  64. disabled={!canCreateProject}
  65. priority={orgHasProjects ? 'default' : 'primary'}
  66. to={`/organizations/${orgSlug}/projects/new/`}
  67. >
  68. {t('Create project')}
  69. </Button>
  70. );
  71. return (
  72. <Wrapper>
  73. <HeightWrapper>
  74. <img src={img} height={350} alt={t('Nothing to see')} />
  75. <Content>
  76. <StyledPageHeading>{t('Remain Calm')}</StyledPageHeading>
  77. <HelpMessage>{t('You need at least one project to use this view')}</HelpMessage>
  78. <Actions gap={1}>
  79. {!orgHasProjects ? (
  80. createProjectAction
  81. ) : (
  82. <Fragment>
  83. {joinTeamAction}
  84. {createProjectAction}
  85. </Fragment>
  86. )}
  87. </Actions>
  88. </Content>
  89. </HeightWrapper>
  90. </Wrapper>
  91. );
  92. }
  93. const StyledPageHeading = styled(PageHeading)`
  94. font-size: 28px;
  95. margin-bottom: ${space(1.5)};
  96. `;
  97. const HelpMessage = styled('div')`
  98. margin-bottom: ${space(2)};
  99. `;
  100. const Flex = styled('div')`
  101. display: flex;
  102. `;
  103. const Wrapper = styled(Flex)`
  104. flex: 1;
  105. align-items: center;
  106. justify-content: center;
  107. `;
  108. const HeightWrapper = styled(Flex)`
  109. height: 350px;
  110. `;
  111. const Content = styled(Flex)`
  112. flex-direction: column;
  113. justify-content: center;
  114. margin-left: 40px;
  115. `;
  116. const Actions = styled(ButtonBar)`
  117. width: fit-content;
  118. `;