emailValue.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 {IconWarning} from 'sentry/icons';
  7. import {space} from 'sentry/styles/space';
  8. import type {InviteStatus} from './types';
  9. function EmailValue<Option extends OptionTypeBase>({
  10. status,
  11. valueProps,
  12. }: {
  13. status: InviteStatus[string];
  14. valueProps: MultiValueProps<Option>;
  15. }) {
  16. const {children, ...props} = valueProps;
  17. const error = 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 hideMessage size={14} />}
  26. {status.error && <IconWarning legacySize="10px" />}
  27. </EmailLabel>
  28. </Tooltip>
  29. );
  30. return (
  31. <selectComponents.MultiValue {...props}>{emailLabel}</selectComponents.MultiValue>
  32. );
  33. }
  34. const EmailLabel = styled('div')`
  35. display: inline-grid;
  36. grid-auto-flow: column;
  37. gap: ${space(0.5)};
  38. align-items: center;
  39. `;
  40. const SendingIndicator = styled(LoadingIndicator)`
  41. margin: 0;
  42. .loading-indicator {
  43. border-width: 2px;
  44. }
  45. `;
  46. export default EmailValue;