gsBillingNavigationConfig.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {Component} from 'react';
  2. import {t} from 'sentry/locale';
  3. import HookStore from 'sentry/stores/hookStore';
  4. import type {Scope} from 'sentry/types/core';
  5. import type {Organization} from 'sentry/types/organization';
  6. import type {
  7. NavigationItem,
  8. NavigationProps,
  9. NavigationSection,
  10. } from 'sentry/views/settings/types';
  11. import withSubscription from 'getsentry/components/withSubscription';
  12. import type {Subscription} from 'getsentry/types';
  13. type Props = {
  14. organization: Organization;
  15. subscription: Subscription;
  16. };
  17. type NavProps = NavigationProps & {
  18. access?: Set<Scope>;
  19. };
  20. class GSBillingNavigationConfig extends Component<Props> {
  21. componentDidMount() {
  22. // Clear store before adding since this can be called multiple times
  23. HookStore.remove('settings:organization-navigation-config', this.getConfig);
  24. HookStore.add('settings:organization-navigation-config', this.getConfig);
  25. }
  26. componentWillUnmount() {
  27. HookStore.remove('settings:organization-navigation-config', this.getConfig);
  28. }
  29. getConfig = (organization: Organization): NavigationSection => {
  30. const {subscription} = this.props;
  31. const membersCanViewSubscriptionInfo = subscription.canSelfServe;
  32. const prefix = '/settings/:orgId';
  33. const items: NavigationItem[] = [
  34. {
  35. path: `${prefix}/billing/`,
  36. title: t('Subscription'),
  37. show: ({access}: NavProps) =>
  38. access?.has('org:billing') || membersCanViewSubscriptionInfo,
  39. id: 'subscription',
  40. },
  41. {
  42. path: `${prefix}/subscription/spend-allocations/`,
  43. title: t('Spend Allocations'),
  44. show: () => organization.features.includes('spend-allocations'),
  45. id: 'spend-allocations',
  46. description: t('Guarantee monthly event volume to your priority projects.'),
  47. },
  48. {
  49. path: `${prefix}/spike-protection/`,
  50. title: t('Spike Protection'),
  51. id: 'spike',
  52. },
  53. {
  54. path: `${prefix}/subscription/redeem-code/`,
  55. title: t('Redeem Promo Code'),
  56. id: 'promo',
  57. },
  58. {
  59. path: `${prefix}/legal/`,
  60. title: t('Legal & Compliance'),
  61. id: 'legal',
  62. },
  63. ];
  64. return {
  65. name: t('Usage & Billing'),
  66. items,
  67. };
  68. };
  69. render() {
  70. return null;
  71. }
  72. }
  73. export default withSubscription(GSBillingNavigationConfig, {noLoader: true});