noProjectMessage.tsx 3.4 KB

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