noProjectMessage.tsx 3.4 KB

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