upsell.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import * as Sentry from '@sentry/react';
  2. import {
  3. addErrorMessage,
  4. addLoadingMessage,
  5. addSuccessMessage,
  6. } from 'sentry/actionCreators/indicator';
  7. import type {Client} from 'sentry/api';
  8. import {t, tct} from 'sentry/locale';
  9. import type {Organization} from 'sentry/types/organization';
  10. import {handleXhrErrorResponse} from 'sentry/utils/handleXhrErrorResponse';
  11. import TrialRequestedActions from 'getsentry/actions/trialRequestedActions';
  12. export async function sendReplayOnboardRequest({
  13. api,
  14. orgSlug,
  15. onSuccess,
  16. onError,
  17. currentPlan,
  18. }: {
  19. api: Client;
  20. currentPlan: 'am2-beta' | 'am2-non-beta' | 'am1-beta' | 'am1-non-beta';
  21. data?: Record<string, any>;
  22. onError?: () => void;
  23. onSuccess?: () => void;
  24. orgSlug?: Organization['slug'];
  25. }) {
  26. try {
  27. await api.requestPromise(`/organizations/${orgSlug}/replay-onboard-request/`, {
  28. method: 'POST',
  29. data: {
  30. name: currentPlan,
  31. },
  32. });
  33. addSuccessMessage(
  34. tct('An owner has been [annoyed] notified!', {annoyed: <s>annoyed</s>})
  35. );
  36. onSuccess?.();
  37. } catch (error) {
  38. const message = t('Oh shit');
  39. handleXhrErrorResponse(message, error);
  40. addErrorMessage(message);
  41. onError?.();
  42. }
  43. }
  44. export function sendUpgradeRequest({
  45. organization,
  46. type,
  47. ...rest
  48. }: {
  49. api: Client;
  50. organization: Organization;
  51. data?: Record<string, any>;
  52. handleSuccess?: () => void;
  53. type?: string;
  54. }) {
  55. const endpoint = `/organizations/${organization.slug}/plan-upgrade-request/`;
  56. const data = {type};
  57. return sendBasicRequest({
  58. endpoint,
  59. data,
  60. ...rest,
  61. });
  62. }
  63. export function sendTrialRequest({
  64. organization,
  65. handleSuccess,
  66. ...rest
  67. }: {
  68. api: Client;
  69. organization: Organization;
  70. handleSuccess?: () => void;
  71. }) {
  72. const endpoint = `/organizations/${organization.slug}/trial-request/`;
  73. return sendBasicRequest({
  74. endpoint,
  75. data: {},
  76. handleSuccess: () => {
  77. // show confirmation through trialStartedSidebarItem
  78. TrialRequestedActions.requested();
  79. handleSuccess?.();
  80. },
  81. ...rest,
  82. });
  83. }
  84. export async function sendBetaCronsTrialOptIn({
  85. api,
  86. organization,
  87. onSuccess,
  88. }: {
  89. api: Client;
  90. organization: Organization;
  91. onSuccess?: () => void;
  92. }) {
  93. const endpoint = `/customers/${organization.slug}/`;
  94. try {
  95. addLoadingMessage();
  96. await api.requestPromise(endpoint, {
  97. method: 'PUT',
  98. data: {
  99. cronsBetaOptIn: true,
  100. },
  101. });
  102. addSuccessMessage(t('Success!'));
  103. onSuccess?.();
  104. } catch (error) {
  105. const message = t('Failed to opt-in');
  106. handleXhrErrorResponse(message, error);
  107. addErrorMessage(message);
  108. }
  109. }
  110. export function sendAddEventsRequest({
  111. organization,
  112. eventTypes,
  113. notificationType,
  114. ...rest
  115. }: {
  116. api: Client;
  117. organization: Organization;
  118. eventTypes?: string[];
  119. handleSuccess?: () => void;
  120. notificationType?: string;
  121. }) {
  122. const endpoint = `/organizations/${organization.slug}/event-limit-increase-request/`;
  123. const data = {types: eventTypes, notificationType};
  124. return sendBasicRequest({
  125. endpoint,
  126. data,
  127. ...rest,
  128. });
  129. }
  130. async function sendBasicRequest({
  131. api,
  132. endpoint,
  133. data,
  134. handleSuccess,
  135. }: {
  136. api: Client;
  137. data: Record<string, any>;
  138. endpoint: string;
  139. handleSuccess?: () => void;
  140. }) {
  141. try {
  142. addLoadingMessage(t('Requesting\u2026'));
  143. await api.requestPromise(endpoint, {
  144. method: 'POST',
  145. data,
  146. });
  147. addSuccessMessage(t('Request Sent'));
  148. handleSuccess?.();
  149. } catch (err) {
  150. addErrorMessage(t('Unable to send request'));
  151. Sentry.captureException(err);
  152. }
  153. }