targetedOnboardingHeader.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import styled from '@emotion/styled';
  2. import {LinkButton} from 'sentry/components/button';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import {IconBusiness} from 'sentry/icons';
  6. import {t, tn} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import type {Organization} from 'sentry/types/organization';
  9. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  10. import withOrganization from 'sentry/utils/withOrganization';
  11. import {openUpsellModal} from 'getsentry/actionCreators/modal';
  12. import withSubscription from 'getsentry/components/withSubscription';
  13. import type {Subscription} from 'getsentry/types';
  14. import {getTrialDaysLeft} from 'getsentry/utils/billing';
  15. import trackGetsentryAnalytics from 'getsentry/utils/trackGetsentryAnalytics';
  16. type Props = {
  17. organization: Organization;
  18. source: string;
  19. subscription: Subscription;
  20. };
  21. function TargetedOnboardingHeader({organization, source, subscription}: Props) {
  22. if (!organization) {
  23. return null;
  24. }
  25. const trackClickNeedHelp = () =>
  26. trackGetsentryAnalytics('growth.onboarding_clicked_need_help', {
  27. organization,
  28. source,
  29. });
  30. const trackClickUpgrade = () => {
  31. trackGetsentryAnalytics('growth.onboarding_clicked_upgrade', {
  32. source,
  33. organization,
  34. });
  35. };
  36. // if trial is active, show info on that
  37. // otherwise show help button
  38. const cta = subscription.isTrial ? (
  39. <ActiveTrialWrapper
  40. onClick={() => openUpsellModal({organization, source: 'targeted-onboarding'})}
  41. >
  42. <ActiveTrialHeader>{t('Trial is Active')}</ActiveTrialHeader>
  43. <div>{tn('%s Day Left', '%s Days Left', getTrialDaysLeft(subscription) || 0)}</div>
  44. </ActiveTrialWrapper>
  45. ) : (
  46. <NeedHelpLink href="https://sentry.zendesk.com/hc/en-us" onClick={trackClickNeedHelp}>
  47. {t('Need help?')}
  48. </NeedHelpLink>
  49. );
  50. return (
  51. <HeaderActionBar gap={2}>
  52. <SecondaryCTAWrapper>{cta}</SecondaryCTAWrapper>
  53. <LinkButton
  54. onClick={trackClickUpgrade}
  55. href={normalizeUrl(
  56. `/settings/${organization.slug}/billing/checkout/?referrer=upgrade-${source}`
  57. )}
  58. external
  59. size="sm"
  60. icon={<IconBusiness />}
  61. priority="default"
  62. >
  63. {t('Upgrade Now')}
  64. </LinkButton>
  65. </HeaderActionBar>
  66. );
  67. }
  68. export default withSubscription(withOrganization(TargetedOnboardingHeader), {
  69. noLoader: true,
  70. });
  71. const HeaderActionBar = styled(ButtonBar)`
  72. margin-left: ${space(2)};
  73. `;
  74. const SecondaryCTAWrapper = styled('div')`
  75. @media (max-width: ${p => p.theme.breakpoints.small}) {
  76. display: none;
  77. }
  78. `;
  79. const NeedHelpLink = styled(ExternalLink)`
  80. white-space: nowrap;
  81. `;
  82. const ActiveTrialHeader = styled('div')`
  83. font-size: 14px;
  84. text-transform: uppercase;
  85. color: ${p => p.theme.purple300};
  86. `;
  87. const ActiveTrialWrapper = styled('div')`
  88. cursor: pointer;
  89. line-height: normal;
  90. display: flex;
  91. flex-direction: column;
  92. align-items: end;
  93. `;