blockButton.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import type {BaseButtonProps} from 'sentry/components/button';
  2. import {Button} from 'sentry/components/button';
  3. import Confirm from 'sentry/components/confirm';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {IconNot, IconPlay} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import type {OpenConfirmOptions} from '../../../components/confirm';
  8. export interface BlockButtonProps
  9. extends BaseButtonProps,
  10. Pick<OpenConfirmOptions, 'message'> {
  11. hasAccess: boolean;
  12. isBlocked: boolean;
  13. onConfirm: () => void;
  14. }
  15. export function BlockButton({isBlocked, onConfirm, ...props}: BlockButtonProps) {
  16. const button = (
  17. <Button
  18. {...props}
  19. icon={isBlocked ? <IconPlay size="xs" /> : <IconNot size="xs" />}
  20. disabled={!props.hasAccess || props.disabled}
  21. >
  22. {isBlocked ? t('Unblock') : t('Block')}
  23. </Button>
  24. );
  25. return (
  26. <Confirm
  27. priority="danger"
  28. onConfirm={onConfirm}
  29. message={props.message}
  30. confirmText={isBlocked ? t('Unblock') : t('Block')}
  31. >
  32. {props.hasAccess ? (
  33. button
  34. ) : (
  35. <Tooltip title={t('You do not have permissions to edit metrics.')}>
  36. {button}
  37. </Tooltip>
  38. )}
  39. </Confirm>
  40. );
  41. }