timeout-upgrade-prompt-new.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import { Trans, useTranslation } from 'react-i18next'
  2. import { useDetachCompileContext } from '../../../shared/context/detach-compile-context'
  3. import StartFreeTrialButton from '../../../shared/components/start-free-trial-button'
  4. import { memo, useCallback, useMemo, useState } from 'react'
  5. import PdfLogEntry from './pdf-log-entry'
  6. import * as eventTracking from '../../../infrastructure/event-tracking'
  7. import getMeta from '@/utils/meta'
  8. import { populateEditorRedesignSegmentation } from '@/shared/hooks/use-editor-analytics'
  9. import CompileTimeoutPaywallModal from '@/features/pdf-preview/components/compile-timeout-paywall-modal'
  10. import { isSplitTestEnabled } from '@/utils/splitTestUtils'
  11. import { useSplitTest } from '@/shared/context/split-test-context'
  12. function TimeoutUpgradePromptNew() {
  13. const { isProjectOwner } = useDetachCompileContext()
  14. const isCompileTimeoutTargetPlansEnabled = isSplitTestEnabled(
  15. 'compile-timeout-target-plans'
  16. )
  17. const [showCompileTimeoutPaywall, setShowCompileTimeoutPaywall] =
  18. useState(false)
  19. const { compileTimeout } = getMeta('ol-compileSettings')
  20. const sharedSegmentation = useMemo(
  21. () =>
  22. populateEditorRedesignSegmentation({
  23. 'is-owner': isProjectOwner,
  24. compileTime: compileTimeout,
  25. location: 'logs',
  26. }),
  27. [isProjectOwner, compileTimeout]
  28. )
  29. return (
  30. <>
  31. <CompileTimeout
  32. isProjectOwner={isProjectOwner}
  33. segmentation={sharedSegmentation}
  34. onShowPaywallModal={() => setShowCompileTimeoutPaywall(true)}
  35. isCompileTimeoutTargetPlansEnabled={isCompileTimeoutTargetPlansEnabled}
  36. />
  37. <CompileTimeoutPaywallModal
  38. show={showCompileTimeoutPaywall}
  39. onHide={() => setShowCompileTimeoutPaywall(false)}
  40. />
  41. </>
  42. )
  43. }
  44. type CompileTimeoutProps = {
  45. isProjectOwner: boolean
  46. segmentation: eventTracking.Segmentation
  47. onShowPaywallModal: () => void
  48. isCompileTimeoutTargetPlansEnabled: boolean
  49. }
  50. const CompileTimeout = memo(function CompileTimeout({
  51. isProjectOwner,
  52. segmentation,
  53. onShowPaywallModal,
  54. isCompileTimeoutTargetPlansEnabled,
  55. }: CompileTimeoutProps) {
  56. const { t } = useTranslation()
  57. const { variant } = useSplitTest('compile-timeout-cta')
  58. let ctaLabel = ''
  59. switch (variant) {
  60. case 'explore-plans':
  61. ctaLabel = t('explore_plans')
  62. break
  63. case 'get-more-compile-time':
  64. ctaLabel = t('get_more_compile_time')
  65. break
  66. case 'upgrade-now':
  67. ctaLabel = t('upgrade_now')
  68. break
  69. case 'subscribe-now':
  70. ctaLabel = t('subscribe_now')
  71. break
  72. default:
  73. ctaLabel = t('start_free_trial')
  74. break
  75. }
  76. const extraSearchParams = useMemo(() => {
  77. return {
  78. itm_content: 'new-editor',
  79. }
  80. }, [])
  81. const handleFreeTrialClick = useCallback(
  82. (event: React.MouseEvent<HTMLButtonElement>) => {
  83. if (isCompileTimeoutTargetPlansEnabled) {
  84. event.preventDefault()
  85. event.stopPropagation()
  86. onShowPaywallModal()
  87. }
  88. },
  89. [isCompileTimeoutTargetPlansEnabled, onShowPaywallModal]
  90. )
  91. return (
  92. <PdfLogEntry
  93. autoExpand
  94. headerTitle={t('your_compile_timed_out')}
  95. formattedContent={
  96. getMeta('ol-ExposedSettings').enableSubscriptions && (
  97. <>
  98. <p>
  99. {isProjectOwner
  100. ? t('your_project_exceeded_compile_timeout_limit_on_free_plan')
  101. : t('this_project_exceeded_compile_timeout_limit_on_free_plan')}
  102. </p>
  103. {isProjectOwner ? (
  104. <p>
  105. <strong>{t('upgrade_for_more_compile_time')}</strong>{' '}
  106. {t('plus_additional_collaborators_and_more')}
  107. </p>
  108. ) : (
  109. <Trans
  110. i18nKey="tell_the_project_owner_and_ask_them_to_upgrade"
  111. components={[
  112. // eslint-disable-next-line react/jsx-key
  113. <strong />,
  114. ]}
  115. />
  116. )}
  117. {isProjectOwner && (
  118. <p className="text-center">
  119. <StartFreeTrialButton
  120. source="compile-timeout"
  121. buttonProps={{ variant: 'primary', className: 'w-100' }}
  122. segmentation={segmentation}
  123. extraSearchParams={extraSearchParams}
  124. handleClick={handleFreeTrialClick}
  125. >
  126. {ctaLabel}
  127. </StartFreeTrialButton>
  128. </p>
  129. )}
  130. </>
  131. )
  132. }
  133. // @ts-ignore
  134. entryAriaLabel={t('your_compile_timed_out')}
  135. level="error"
  136. />
  137. )
  138. })
  139. export default memo(TimeoutUpgradePromptNew)