decideCheckout.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {Component} from 'react';
  2. import ErrorBoundary from 'sentry/components/errorBoundary';
  3. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  4. import type {Organization} from 'sentry/types/organization';
  5. import withOrganization from 'sentry/utils/withOrganization';
  6. import {PlanTier} from 'getsentry/types';
  7. import AMCheckout from 'getsentry/views/amCheckout';
  8. type Props = {
  9. organization: Organization;
  10. } & RouteComponentProps<Record<PropertyKey, unknown>, unknown>;
  11. type State = {
  12. tier: string | null;
  13. };
  14. class DecideCheckout extends Component<Props, State> {
  15. state: State = {
  16. tier: null,
  17. };
  18. onToggleLegacy = (tier: string) => {
  19. this.setState({tier});
  20. };
  21. render() {
  22. const {tier} = this.state;
  23. const props = {...this.props, onToggleLegacy: this.onToggleLegacy};
  24. const hasAm3Feature = props.organization?.features?.includes('am3-billing');
  25. const hasPartnerMigrationFeature = props.organization?.features.includes(
  26. 'partner-billing-migration'
  27. );
  28. if (hasAm3Feature || hasPartnerMigrationFeature) {
  29. return (
  30. <ErrorBoundary errorTag={{checkout: PlanTier.AM3}}>
  31. <AMCheckout checkoutTier={PlanTier.AM3} {...props} />
  32. </ErrorBoundary>
  33. );
  34. }
  35. if (tier !== PlanTier.AM1) {
  36. return (
  37. <ErrorBoundary errorTag={{checkout: PlanTier.AM2}}>
  38. <AMCheckout checkoutTier={PlanTier.AM2} {...props} />
  39. </ErrorBoundary>
  40. );
  41. }
  42. return (
  43. <ErrorBoundary errorTag={{checkout: PlanTier.AM1}}>
  44. <AMCheckout checkoutTier={PlanTier.AM1} {...props} />
  45. </ErrorBoundary>
  46. );
  47. }
  48. }
  49. export default withOrganization(DecideCheckout);