renderEmailValue.tsx 1.5 KB

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