enableSpendAllocations.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import type {Dispatch} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Client} from 'sentry/api';
  4. import {Button} from 'sentry/components/button';
  5. import Panel from 'sentry/components/panels/panel';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. type Props = {
  9. api: Client;
  10. fetchSpendAllocations: () => Promise<void>;
  11. hasScope: boolean;
  12. orgSlug: string;
  13. setErrors: Dispatch<string | null>;
  14. };
  15. function EnableSpendAllocations({
  16. hasScope,
  17. fetchSpendAllocations,
  18. api,
  19. orgSlug,
  20. setErrors,
  21. }: Props) {
  22. const enableAction = async () => {
  23. try {
  24. // Toggle feature flag
  25. await api.requestPromise(`/organizations/${orgSlug}/spend-allocations/toggle/`, {
  26. method: 'POST',
  27. });
  28. // Create root allocations
  29. await api.requestPromise(`/organizations/${orgSlug}/spend-allocations/index/`, {
  30. method: 'POST',
  31. });
  32. } catch (err) {
  33. if (err.status === 409) {
  34. setErrors('Spend Allocations are already enabled');
  35. }
  36. }
  37. await fetchSpendAllocations();
  38. };
  39. return (
  40. <EnablePanel>
  41. <p>{t('Enable the Spend Allocation feature for your organization')}</p>
  42. {hasScope && (
  43. <Button
  44. aria-label="Get started"
  45. priority="primary"
  46. size="sm"
  47. disabled={!hasScope}
  48. onClick={enableAction}
  49. >
  50. {t('Get Started')}
  51. </Button>
  52. )}
  53. {!hasScope && (
  54. <p>
  55. <strong>
  56. {t('Chat with your organization owner to enable spend allocations')}
  57. </strong>
  58. </p>
  59. )}
  60. </EnablePanel>
  61. );
  62. }
  63. export default EnableSpendAllocations;
  64. const EnablePanel = styled(Panel)`
  65. display: flex;
  66. flex-direction: column;
  67. justify-content: center;
  68. align-items: center;
  69. min-height: 200px;
  70. padding: ${space(4)};
  71. text-align: center;
  72. `;