disabledRateLimits.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import PanelAlert from 'sentry/components/panels/panelAlert';
  4. import {IconBusiness} from 'sentry/icons';
  5. import {t, tct} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {Hooks} from 'sentry/types/hooks';
  8. import type {Organization} from 'sentry/types/organization';
  9. import {openUpsellModal} from 'getsentry/actionCreators/modal';
  10. import LearnMoreButton from 'getsentry/components/features/learnMoreButton';
  11. import PlanFeature from 'getsentry/components/features/planFeature';
  12. import {displayPlanName} from 'getsentry/utils/billing';
  13. type Props = {
  14. features: string[];
  15. organization: Organization;
  16. };
  17. function DisabledAlert({organization, features}: Props) {
  18. return (
  19. <PlanFeature {...{organization, features}}>
  20. {({plan}) => (
  21. <StyledPanelAlert type="muted" showIcon>
  22. <Container>
  23. <span>
  24. {plan !== null
  25. ? tct(
  26. 'Custom Rate Limits are available to [planRequirement] and above.',
  27. {
  28. planRequirement: (
  29. <strong>{t('%s plans', displayPlanName(plan))}</strong>
  30. ),
  31. }
  32. )
  33. : t('Custom Rate Limits are not available on your plan.')}
  34. </span>
  35. <Button
  36. size="sm"
  37. priority="primary"
  38. icon={<IconBusiness />}
  39. data-test-id="rate-limit-upsell"
  40. onClick={() =>
  41. openUpsellModal({
  42. organization,
  43. source: 'feature.rate_limits',
  44. defaultSelection: 'event-volume',
  45. })
  46. }
  47. >
  48. {t('Learn More')}
  49. </Button>
  50. <LearnMoreButton
  51. organization={organization}
  52. source="feature.rate_limits"
  53. size="sm"
  54. external
  55. href="https://docs.sentry.io/accounts/quotas/#id1"
  56. >
  57. {t('Documentation')}
  58. </LearnMoreButton>
  59. </Container>
  60. </StyledPanelAlert>
  61. )}
  62. </PlanFeature>
  63. );
  64. }
  65. const StyledPanelAlert = styled(PanelAlert)`
  66. align-items: center;
  67. `;
  68. const Container = styled('div')`
  69. display: grid;
  70. grid-template-columns: 1fr max-content max-content;
  71. gap: ${space(1)};
  72. align-items: center;
  73. `;
  74. type HookProps = Parameters<Hooks['feature-disabled:rate-limits']>[0];
  75. function DisabledRateLimits(props: HookProps) {
  76. if (typeof props.children === 'function') {
  77. return props.children({
  78. ...props,
  79. renderDisabled: DisabledAlert,
  80. });
  81. }
  82. return props.children;
  83. }
  84. export default DisabledRateLimits;