renderEmailValue.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import type {MultiValueProps, OptionTypeBase} from 'react-select';
  2. import {components as selectComponents} from 'react-select';
  3. import styled from '@emotion/styled';
  4. import LoadingIndicator from 'sentry/components/loadingIndicator';
  5. import {Tooltip} from 'sentry/components/tooltip';
  6. import {IconCheckmark, IconWarning} from 'sentry/icons';
  7. import {space} from 'sentry/styles/space';
  8. import type {InviteStatus} from './types';
  9. function renderEmailValue<Option extends OptionTypeBase>(
  10. status: InviteStatus[string],
  11. valueProps: MultiValueProps<Option>
  12. ) {
  13. const {children, ...props} = valueProps;
  14. const error = status?.error;
  15. const emailLabel =
  16. status === undefined ? (
  17. children
  18. ) : (
  19. <Tooltip disabled={!error} title={error}>
  20. <EmailLabel>
  21. {children}
  22. {!status.sent && !status.error && <SendingIndicator />}
  23. {status.error && <IconWarning legacySize="10px" />}
  24. {status.sent && <IconCheckmark legacySize="10px" color="success" />}
  25. </EmailLabel>
  26. </Tooltip>
  27. );
  28. return (
  29. <selectComponents.MultiValue {...props}>{emailLabel}</selectComponents.MultiValue>
  30. );
  31. }
  32. const EmailLabel = styled('div')`
  33. display: inline-grid;
  34. grid-auto-flow: column;
  35. gap: ${space(0.5)};
  36. align-items: center;
  37. `;
  38. const SendingIndicator = styled(LoadingIndicator)`
  39. margin: 0;
  40. .loading-indicator {
  41. border-width: 2px;
  42. }
  43. `;
  44. SendingIndicator.defaultProps = {
  45. hideMessage: true,
  46. size: 14,
  47. };
  48. export default renderEmailValue;