cronsOnDemandStepWarning.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {Alert} from 'sentry/components/core/alert';
  2. import {DATA_CATEGORY_INFO} from 'sentry/constants';
  3. import {tct} from 'sentry/locale';
  4. import {DataCategoryExact} from 'sentry/types/core';
  5. import type {Organization} from 'sentry/types/organization';
  6. import {useApiQuery} from 'sentry/utils/queryClient';
  7. import {
  8. type MonitorCountResponse,
  9. type Plan,
  10. PlanTier,
  11. type Subscription,
  12. } from 'getsentry/types';
  13. interface Props {
  14. activePlan: Plan;
  15. currentOnDemand: number;
  16. // TODO(davidenwang): Once modals have access to OrganizationContext, delete this in favor of useOrganization
  17. organization: Organization;
  18. subscription: Subscription;
  19. }
  20. export function CronsOnDemandStepWarning({
  21. currentOnDemand,
  22. activePlan,
  23. organization,
  24. subscription,
  25. }: Props) {
  26. const cronCategoryName = DATA_CATEGORY_INFO[DataCategoryExact.MONITOR_SEAT].plural;
  27. const cronsBucket = activePlan.planCategories[cronCategoryName]?.[0];
  28. const cronsPrice = cronsBucket?.onDemandPrice;
  29. const reserved = cronsBucket?.events;
  30. const queryKey = [`/organizations/${organization.slug}/monitor-count/`] as const;
  31. const {data, isPending} = useApiQuery<MonitorCountResponse>(queryKey, {
  32. staleTime: 0,
  33. });
  34. if (isPending || !data || !cronsPrice || !reserved) {
  35. return null;
  36. }
  37. const numCrons = data.enabledMonitorCount;
  38. const currentUsage = (numCrons - reserved) * cronsPrice;
  39. const overBudget = currentUsage > currentOnDemand;
  40. if (!overBudget) {
  41. return null;
  42. }
  43. return (
  44. <Alert.Container>
  45. <Alert type="warning" showIcon>
  46. {tct(
  47. "These changes will take effect at the start of your next billing cycle. Heads up that you're currently using $[currentUsageDollars] of Cron Monitors. These monitors will be turned off at the start of your next billing cycle unless you increase your [budgetType] budget.",
  48. {
  49. currentUsageDollars: currentUsage / 100,
  50. budgetType:
  51. subscription.planTier === PlanTier.AM3 ? 'pay-as-you-go' : 'on-demand',
  52. }
  53. )}
  54. </Alert>
  55. </Alert.Container>
  56. );
  57. }