inviteRequestRow.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Tag from 'sentry/components/badge/tag';
  4. import {Button} from 'sentry/components/button';
  5. import Confirm from 'sentry/components/confirm';
  6. import type {InviteModalRenderFunc} from 'sentry/components/modals/memberInviteModalCustomization';
  7. import {InviteModalHook} from 'sentry/components/modals/memberInviteModalCustomization';
  8. import PanelItem from 'sentry/components/panels/panelItem';
  9. import RoleSelectControl from 'sentry/components/roleSelectControl';
  10. import TeamSelector from 'sentry/components/teamSelector';
  11. import {Tooltip} from 'sentry/components/tooltip';
  12. import {IconCheckmark, IconClose} from 'sentry/icons';
  13. import {t, tct} from 'sentry/locale';
  14. import {space} from 'sentry/styles/space';
  15. import type {Member, Organization, OrgRole} from 'sentry/types/organization';
  16. type Props = {
  17. allRoles: OrgRole[];
  18. inviteRequest: Member;
  19. inviteRequestBusy: {[key: string]: boolean};
  20. onApprove: (inviteRequest: Member) => void;
  21. onDeny: (inviteRequest: Member) => void;
  22. onUpdate: (data: Partial<Member>) => void;
  23. organization: Organization;
  24. };
  25. function InviteRequestRow({
  26. inviteRequest,
  27. inviteRequestBusy,
  28. organization,
  29. onApprove,
  30. onDeny,
  31. onUpdate,
  32. allRoles,
  33. }: Props) {
  34. const role = allRoles.find(r => r.id === inviteRequest.role);
  35. const roleDisallowed = !role?.isAllowed;
  36. const {access} = organization;
  37. const canApprove = access.includes('member:admin');
  38. const hookRenderer: InviteModalRenderFunc = ({sendInvites, canSend, headerInfo}) => (
  39. <StyledPanelItem>
  40. <div>
  41. <h5 style={{marginBottom: space(0.5)}}>
  42. <UserName>{inviteRequest.email}</UserName>
  43. </h5>
  44. {inviteRequest.inviteStatus === 'requested_to_be_invited' ? (
  45. inviteRequest.inviterName && (
  46. <Description>
  47. <Tooltip
  48. title={t(
  49. 'An existing member has asked to invite this user to your organization'
  50. )}
  51. >
  52. {tct('Requested by [inviterName]', {
  53. inviterName: inviteRequest.inviterName,
  54. })}
  55. </Tooltip>
  56. </Description>
  57. )
  58. ) : (
  59. <JoinRequestIndicator
  60. tooltipText={t('This user has asked to join your organization.')}
  61. >
  62. {t('Join request')}
  63. </JoinRequestIndicator>
  64. )}
  65. </div>
  66. {canApprove ? (
  67. <StyledRoleSelectControl
  68. name="role"
  69. disableUnallowed
  70. onChange={r => onUpdate({role: r.value})}
  71. value={inviteRequest.role}
  72. roles={allRoles}
  73. aria-label={t('Role: %s', role?.name)}
  74. />
  75. ) : (
  76. <div>{inviteRequest.roleName}</div>
  77. )}
  78. {canApprove ? (
  79. <TeamSelectControl
  80. name="teams"
  81. placeholder={t('None')}
  82. onChange={teams => onUpdate({teams: (teams || []).map(team => team.value)})}
  83. value={inviteRequest.teams}
  84. clearable
  85. multiple
  86. />
  87. ) : (
  88. <div>{inviteRequest.teams.join(', ')}</div>
  89. )}
  90. <ButtonGroup>
  91. <Button
  92. size="sm"
  93. busy={inviteRequestBusy[inviteRequest.id]}
  94. onClick={() => onDeny(inviteRequest)}
  95. icon={<IconClose />}
  96. disabled={!canApprove}
  97. title={
  98. canApprove
  99. ? undefined
  100. : t('This request needs to be reviewed by a privileged user')
  101. }
  102. >
  103. {t('Deny')}
  104. </Button>
  105. <Confirm
  106. onConfirm={sendInvites}
  107. disableConfirmButton={!canSend}
  108. disabled={!canApprove || roleDisallowed}
  109. message={
  110. <Fragment>
  111. {tct('Are you sure you want to invite [email] to your organization?', {
  112. email: inviteRequest.email,
  113. })}
  114. {headerInfo}
  115. </Fragment>
  116. }
  117. >
  118. <Button
  119. priority="primary"
  120. size="sm"
  121. busy={inviteRequestBusy[inviteRequest.id]}
  122. title={
  123. canApprove
  124. ? roleDisallowed
  125. ? t(
  126. `You do not have permission to approve a user of this role.
  127. Select a different role to approve this user.`
  128. )
  129. : undefined
  130. : t('This request needs to be reviewed by a privileged user')
  131. }
  132. icon={<IconCheckmark />}
  133. >
  134. {t('Approve')}
  135. </Button>
  136. </Confirm>
  137. </ButtonGroup>
  138. </StyledPanelItem>
  139. );
  140. return (
  141. <InviteModalHook
  142. willInvite
  143. organization={organization}
  144. onSendInvites={() => onApprove(inviteRequest)}
  145. >
  146. {hookRenderer}
  147. </InviteModalHook>
  148. );
  149. }
  150. const JoinRequestIndicator = styled(Tag)`
  151. text-transform: uppercase;
  152. `;
  153. const StyledPanelItem = styled(PanelItem)`
  154. display: grid;
  155. grid-template-columns: minmax(150px, auto) minmax(100px, 140px) 220px max-content;
  156. gap: ${space(2)};
  157. align-items: center;
  158. `;
  159. const UserName = styled('div')`
  160. font-size: ${p => p.theme.fontSizeLarge};
  161. overflow: hidden;
  162. text-overflow: ellipsis;
  163. `;
  164. const Description = styled('div')`
  165. display: block;
  166. color: ${p => p.theme.subText};
  167. font-size: 14px;
  168. overflow: hidden;
  169. text-overflow: ellipsis;
  170. `;
  171. const StyledRoleSelectControl = styled(RoleSelectControl)`
  172. max-width: 140px;
  173. `;
  174. const TeamSelectControl = styled(TeamSelector)`
  175. max-width: 220px;
  176. .Select-value-label {
  177. max-width: 150px;
  178. word-break: break-all;
  179. }
  180. `;
  181. const ButtonGroup = styled('div')`
  182. display: inline-grid;
  183. grid-template-columns: repeat(2, max-content);
  184. gap: ${space(1)};
  185. `;
  186. export default InviteRequestRow;