inviteButton.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import type {ButtonProps} from 'sentry/components/button';
  2. import {Button} from 'sentry/components/button';
  3. import {t} from 'sentry/locale';
  4. import type {NormalizedInvite} from './types';
  5. interface Props extends Omit<ButtonProps, 'children'> {
  6. invites: NormalizedInvite[];
  7. willInvite: boolean;
  8. }
  9. export default function InviteButton({invites, willInvite, ...buttonProps}: Props) {
  10. const label = buttonLabel(invites, willInvite);
  11. return <Button {...buttonProps}>{label}</Button>;
  12. }
  13. function buttonLabel(invites: NormalizedInvite[], willInvite: boolean) {
  14. if (invites.length > 0) {
  15. const numberInvites = invites.length;
  16. // Note we use `t()` here because `tn()` expects the same # of string formatters
  17. const inviteText =
  18. numberInvites === 1 ? t('Send invite') : t('Send invites (%s)', numberInvites);
  19. const requestText =
  20. numberInvites === 1
  21. ? t('Send invite request')
  22. : t('Send invite requests (%s)', numberInvites);
  23. return willInvite ? inviteText : requestText;
  24. }
  25. return willInvite ? t('Send invite') : t('Send invite request');
  26. }