replayOnboardingCTA.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import type {ReactNode} from 'react';
  2. import {Fragment, useCallback, useEffect, useState} from 'react';
  3. import styled from '@emotion/styled';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import {Button, LinkButton} from 'sentry/components/core/button';
  6. import {SidebarPanelKey} from 'sentry/components/sidebar/types';
  7. import {t} from 'sentry/locale';
  8. import SidebarPanelStore from 'sentry/stores/sidebarPanelStore';
  9. import type {Organization} from 'sentry/types/organization';
  10. import useApi from 'sentry/utils/useApi';
  11. import useDismissAlert from 'sentry/utils/useDismissAlert';
  12. import {
  13. openAM2UpsellModal,
  14. openAM2UpsellModalSamePrice,
  15. } from 'getsentry/actionCreators/modal';
  16. import {sendReplayOnboardRequest} from 'getsentry/actionCreators/upsell';
  17. import usePreviewData from 'getsentry/components/upgradeNowModal/usePreviewData';
  18. import withSubscription from 'getsentry/components/withSubscription';
  19. import type {Subscription} from 'getsentry/types';
  20. import {PlanTier} from 'getsentry/types';
  21. import trackGetsentryAnalytics from 'getsentry/utils/trackGetsentryAnalytics';
  22. import {redirectToManage} from './upgradeNowModal/utils';
  23. type ReplayOnboardingCTAUpsellProps = {
  24. organization: Organization;
  25. subscription: Subscription;
  26. };
  27. function ReplayOnboardingCTAUpsell({
  28. organization,
  29. subscription,
  30. }: ReplayOnboardingCTAUpsellProps) {
  31. const hasBillingAccess = organization.access?.includes('org:billing');
  32. const api = useApi();
  33. const {dismiss, isDismissed} = useDismissAlert({
  34. key: `${organization.id}:dismiss-replay-update-plan-button`,
  35. expirationDays: 14,
  36. });
  37. useEffect(() => {
  38. trackGetsentryAnalytics('replay.list_page.viewed', {
  39. organization,
  40. surface: 'replay_onboarding_banner',
  41. planTier: subscription.planTier,
  42. canSelfServe: subscription.canSelfServe,
  43. channel: subscription.channel,
  44. has_billing_scope: organization.access?.includes('org:billing'),
  45. });
  46. }, [organization, subscription]);
  47. const onEmailOwner = useCallback(async () => {
  48. await sendReplayOnboardRequest({
  49. orgSlug: organization.slug,
  50. api,
  51. currentPlan: 'am1-non-beta',
  52. onSuccess: () => {
  53. dismiss();
  54. trackGetsentryAnalytics('replay.list_page.sent_email', {
  55. organization,
  56. surface: 'replay_onboarding_banner',
  57. planTier: subscription.planTier,
  58. canSelfServe: subscription.canSelfServe,
  59. channel: subscription.channel,
  60. has_billing_scope: organization.access?.includes('org:billing'),
  61. });
  62. },
  63. });
  64. }, [api, organization, subscription, dismiss]);
  65. const [didClickOpenModal, setDidClickOpenModal] = useState<boolean>();
  66. const previewData = usePreviewData({
  67. organization,
  68. subscription,
  69. enabled: !subscription.canSelfServe || !hasBillingAccess,
  70. });
  71. const handleOpenModal = useCallback(() => {
  72. setDidClickOpenModal(true);
  73. }, []);
  74. // Once we have 1) previewData, and 2) the user clicked the button; then open the modal
  75. useEffect(() => {
  76. if (!didClickOpenModal || previewData.loading) {
  77. return;
  78. }
  79. if (previewData.error) {
  80. if (hasBillingAccess) {
  81. // Redirect the user to the subscriptions page, where they will find important information.
  82. // If they wish to update their plan, we ask them to contact our sales/support team.
  83. redirectToManage(organization);
  84. }
  85. return;
  86. }
  87. setDidClickOpenModal(false);
  88. const onComplete = () => {
  89. dismiss();
  90. trackGetsentryAnalytics('replay.list_page.open_modal', {
  91. organization,
  92. surface: 'replay_onboarding_banner',
  93. planTier: subscription.planTier,
  94. canSelfServe: subscription.canSelfServe,
  95. channel: subscription.channel,
  96. has_billing_scope: hasBillingAccess,
  97. has_price_change: previewData.previewData.billedAmount !== 0,
  98. });
  99. };
  100. if (hasBillingAccess && previewData.previewData.billedAmount === 0) {
  101. openAM2UpsellModalSamePrice({
  102. organization,
  103. subscription,
  104. onComplete: () => {
  105. window.location.hash = 'replay-sidequest';
  106. SidebarPanelStore.activatePanel(SidebarPanelKey.REPLAYS_ONBOARDING);
  107. onComplete();
  108. },
  109. surface: 'replay',
  110. ...previewData,
  111. });
  112. } else {
  113. openAM2UpsellModal({
  114. organization,
  115. subscription,
  116. isActionDisabled: isDismissed,
  117. onComplete,
  118. surface: 'replay',
  119. ...previewData,
  120. });
  121. }
  122. }, [
  123. dismiss,
  124. didClickOpenModal,
  125. hasBillingAccess,
  126. isDismissed,
  127. organization,
  128. previewData,
  129. subscription,
  130. ]);
  131. const onClickManageSubscription = useCallback(() => {
  132. trackGetsentryAnalytics('replay.list_page.manage_sub', {
  133. organization,
  134. surface: 'replay_onboarding_banner',
  135. planTier: subscription.planTier,
  136. canSelfServe: subscription.canSelfServe,
  137. channel: subscription.channel,
  138. has_billing_scope: organization.access?.includes('org:billing'),
  139. });
  140. }, [organization, subscription]);
  141. if (!subscription.canSelfServe) {
  142. // Two cases:
  143. // 1. Touch sales -> They need to call sales.
  144. // 2. Managed/Partner accounts, that are not AM2 -> no update path. They're stuck for now.
  145. // In either case the Subscription Overview page has a note about what options are available.
  146. return (
  147. <Fragment>
  148. <h3>{t('Get to the root cause faster')}</h3>
  149. {subscription.channel === 'sales' ? null : (
  150. <p>{t('Your current plan doesn’t support Session Replay.')}</p>
  151. )}
  152. <p>
  153. {t(
  154. 'Session Replay is a video-like reproduction of user interactions including page visits, mouse movements, clicks, and scrolls on a site or web app.'
  155. )}
  156. </p>
  157. <ButtonList gap={1}>
  158. <LinkButton
  159. to={`/settings/${organization.slug}/billing/overview/?referrer=replay_onboard-managed-cta`}
  160. onClick={onClickManageSubscription}
  161. priority="primary"
  162. >
  163. {t('Manage Subscription')}
  164. </LinkButton>
  165. <LinkButton href="https://docs.sentry.io/product/session-replay/" external>
  166. {t('Read Docs')}
  167. </LinkButton>
  168. </ButtonList>
  169. </Fragment>
  170. );
  171. }
  172. if ([PlanTier.MM1, PlanTier.MM2].includes(subscription.planTier as PlanTier)) {
  173. // MM1 & MM2 plans have no direct update path into AM2, prices could be wildly different
  174. // Members get an email, owners get to Manage Subscription
  175. return (
  176. <Fragment>
  177. <h3>{t('Get to the root cause faster')}</h3>
  178. <p>
  179. {t(
  180. 'Update to the latest version of your plan to get access to Session Replay and get video-like reproduction of user interactions including page visits, mouse movements, clicks, and scrolls on a site or web app.'
  181. )}
  182. </p>
  183. <ButtonList gap={1}>
  184. {hasBillingAccess ? (
  185. <LinkButton
  186. to={`/settings/${organization.slug}/billing/overview/?referrer=replay_onboard_mmx-cta`}
  187. onClick={onClickManageSubscription}
  188. priority="primary"
  189. >
  190. {t('Manage Subscription')}
  191. </LinkButton>
  192. ) : (
  193. <Button disabled={isDismissed} onClick={onEmailOwner} priority="primary">
  194. {t('Request to Update Plan')}
  195. </Button>
  196. )}
  197. <LinkButton href="https://docs.sentry.io/product/session-replay/" external>
  198. {t('Read Docs')}
  199. </LinkButton>
  200. </ButtonList>
  201. </Fragment>
  202. );
  203. }
  204. // AM1 orgs get a Modal which includes the one-click "Update Now" button
  205. return (
  206. <Fragment>
  207. <h3>{t('Get to the root cause faster')}</h3>
  208. <p>
  209. {t(
  210. 'Update to the latest version of your plan to get access to Session Replay and get video-like reproduction of user interactions including page visits, mouse movements, clicks, and scrolls on a site or web app.'
  211. )}
  212. </p>
  213. {hasBillingAccess ? null : (
  214. <p>{t('Notify your organization owner to start using Session Replay.')}</p>
  215. )}
  216. <ButtonList gap={1}>
  217. {hasBillingAccess ? (
  218. <Button
  219. onClick={handleOpenModal}
  220. priority="primary"
  221. disabled={didClickOpenModal && previewData.loading}
  222. >
  223. {t('Set Up Replays')}
  224. </Button>
  225. ) : (
  226. <Button disabled={isDismissed} onClick={onEmailOwner} priority="primary">
  227. {t('Notify Owner')}
  228. </Button>
  229. )}
  230. <LinkButton href="https://docs.sentry.io/product/session-replay/" external>
  231. {t('Read Docs')}
  232. </LinkButton>
  233. </ButtonList>
  234. </Fragment>
  235. );
  236. }
  237. const ButtonList = styled(ButtonBar)`
  238. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  239. `;
  240. type ReplayOnboardingCTAProps = {
  241. children: ReactNode;
  242. organization: Organization;
  243. subscription: Subscription;
  244. };
  245. /**
  246. * The majority of orgs have the replays feature, so we check for that first
  247. */
  248. function ReplayOnboardingCTA(props: ReplayOnboardingCTAProps) {
  249. const hasReplaysFeature = props.organization.features.includes('session-replay');
  250. if (hasReplaysFeature) {
  251. // AM2 orgs are ready to go, show the open source "Setup Replay SDK onboarding" panel
  252. // Also, any org that is trialing any AM2 plan is ready to go
  253. return <Fragment>{props.children}</Fragment>;
  254. }
  255. return <ReplayOnboardingCTAUpsell {...props} />;
  256. }
  257. export default withSubscription(ReplayOnboardingCTA, {noLoader: true});