inviteRequestRow.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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: any) =>
  83. onUpdate({teams: (teams || []).map((team: any) => team.value)})
  84. }
  85. value={inviteRequest.teams}
  86. clearable
  87. multiple
  88. />
  89. ) : (
  90. <div>{inviteRequest.teams.join(', ')}</div>
  91. )}
  92. <ButtonGroup>
  93. <Button
  94. size="sm"
  95. busy={inviteRequestBusy[inviteRequest.id]}
  96. onClick={() => onDeny(inviteRequest)}
  97. icon={<IconClose />}
  98. disabled={!canApprove}
  99. title={
  100. canApprove
  101. ? undefined
  102. : t('This request needs to be reviewed by a privileged user')
  103. }
  104. >
  105. {t('Deny')}
  106. </Button>
  107. <Confirm
  108. onConfirm={sendInvites}
  109. disableConfirmButton={!canSend}
  110. disabled={!canApprove || roleDisallowed}
  111. message={
  112. <Fragment>
  113. {tct('Are you sure you want to invite [email] to your organization?', {
  114. email: inviteRequest.email,
  115. })}
  116. {headerInfo}
  117. </Fragment>
  118. }
  119. >
  120. <Button
  121. priority="primary"
  122. size="sm"
  123. busy={inviteRequestBusy[inviteRequest.id]}
  124. title={
  125. canApprove
  126. ? roleDisallowed
  127. ? t(
  128. `You do not have permission to approve a user of this role.
  129. Select a different role to approve this user.`
  130. )
  131. : undefined
  132. : t('This request needs to be reviewed by a privileged user')
  133. }
  134. icon={<IconCheckmark />}
  135. >
  136. {t('Approve')}
  137. </Button>
  138. </Confirm>
  139. </ButtonGroup>
  140. </StyledPanelItem>
  141. );
  142. return (
  143. <InviteModalHook
  144. willInvite
  145. organization={organization}
  146. onSendInvites={() => onApprove(inviteRequest)}
  147. >
  148. {hookRenderer}
  149. </InviteModalHook>
  150. );
  151. }
  152. const JoinRequestIndicator = styled(Tag)`
  153. text-transform: uppercase;
  154. `;
  155. const StyledPanelItem = styled(PanelItem)`
  156. display: grid;
  157. grid-template-columns: minmax(150px, auto) minmax(100px, 140px) 220px max-content;
  158. gap: ${space(2)};
  159. align-items: center;
  160. `;
  161. const UserName = styled('div')`
  162. font-size: ${p => p.theme.fontSizeLarge};
  163. overflow: hidden;
  164. text-overflow: ellipsis;
  165. `;
  166. const Description = styled('div')`
  167. display: block;
  168. color: ${p => p.theme.subText};
  169. font-size: 14px;
  170. overflow: hidden;
  171. text-overflow: ellipsis;
  172. `;
  173. const StyledRoleSelectControl = styled(RoleSelectControl)`
  174. max-width: 140px;
  175. `;
  176. const TeamSelectControl = styled(TeamSelector)`
  177. max-width: 220px;
  178. .Select-value-label {
  179. max-width: 150px;
  180. word-break: break-all;
  181. }
  182. `;
  183. const ButtonGroup = styled('div')`
  184. display: inline-grid;
  185. grid-template-columns: repeat(2, max-content);
  186. gap: ${space(1)};
  187. `;
  188. export default InviteRequestRow;