cronsBannerUpgradeCTA.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {openModal} from 'sentry/actionCreators/modal';
  2. import {Button, LinkButton} from 'sentry/components/button';
  3. import {t} from 'sentry/locale';
  4. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  5. import useApi from 'sentry/utils/useApi';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. import {sendUpgradeRequest} from 'getsentry/actionCreators/upsell';
  8. import type {Subscription} from 'getsentry/types';
  9. import OnDemandBudgetEditModal from 'getsentry/views/onDemandBudgets/onDemandBudgetEditModal';
  10. interface UpgradeCTAProps {
  11. hasBillingAccess: boolean;
  12. }
  13. export function CronsBannerUpgradeCTA({hasBillingAccess}: UpgradeCTAProps) {
  14. const organization = useOrganization();
  15. const api = useApi();
  16. if (hasBillingAccess) {
  17. return (
  18. <LinkButton
  19. href={normalizeUrl(`/settings/${organization.slug}/billing/checkout/`)}
  20. size="xs"
  21. analyticsEventName="Crons: Clicked Trial Banner CTA"
  22. analyticsEventKey="crons.clicked_trial_banner_cta"
  23. analyticsParams={{hasBillingAccess, organization}}
  24. >
  25. {t('Upgrade Now')}
  26. </LinkButton>
  27. );
  28. }
  29. return (
  30. <Button
  31. onClick={() => {
  32. sendUpgradeRequest({api, organization});
  33. }}
  34. size="xs"
  35. analyticsEventName="Crons: Clicked Trial Banner CTA"
  36. analyticsEventKey="crons.clicked_trial_banner_cta"
  37. analyticsParams={{hasBillingAccess, organization}}
  38. >
  39. {t('Request Upgrade')}
  40. </Button>
  41. );
  42. }
  43. interface OnDemandCTAProps {
  44. hasBillingAccess: boolean;
  45. subscription: Subscription;
  46. }
  47. export function CronsBannerOnDemandCTA({
  48. hasBillingAccess,
  49. subscription,
  50. }: OnDemandCTAProps) {
  51. const organization = useOrganization();
  52. const openOnDemandBudgetEditModal = () => {
  53. openModal(
  54. modalProps => (
  55. <OnDemandBudgetEditModal
  56. {...modalProps}
  57. subscription={subscription}
  58. organization={organization}
  59. />
  60. ),
  61. {
  62. closeEvents: 'escape-key',
  63. }
  64. );
  65. };
  66. // Only allow owners, billing roles to edit on demand spend
  67. if (hasBillingAccess) {
  68. return (
  69. <Button
  70. size="xs"
  71. onClick={openOnDemandBudgetEditModal}
  72. analyticsEventName="Crons: Clicked On Demand Banner CTA"
  73. analyticsEventKey="crons.clicked_on_demand_banner_cta"
  74. analyticsParams={{hasBillingAccess, organization}}
  75. >
  76. {t('Update Plan')}
  77. </Button>
  78. );
  79. }
  80. return null;
  81. }