successful-subscription.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { useTranslation, Trans } from 'react-i18next'
  2. import { PriceExceptions } from '../shared/price-exceptions'
  3. import PremiumFeaturesLink from '../dashboard/premium-features-link'
  4. import getMeta from '../../../../utils/meta'
  5. import { useSubscriptionDashboardContext } from '../../context/subscription-dashboard-context'
  6. import OLRow from '@/shared/components/ol/ol-row'
  7. import OLCol from '@/shared/components/ol/ol-col'
  8. import OLPageContentCard from '@/shared/components/ol/ol-page-content-card'
  9. import OLNotification from '@/shared/components/ol/ol-notification'
  10. import {
  11. AI_ADD_ON_CODE,
  12. ADD_ON_NAME,
  13. isStandaloneAiPlanCode,
  14. } from '../../data/add-on-codes'
  15. import { PaidSubscription } from '../../../../../../types/subscription/dashboard/subscription'
  16. import { useBroadcastUser } from '@/shared/hooks/user-channel/use-broadcast-user'
  17. function SuccessfulSubscription() {
  18. const { t } = useTranslation()
  19. const { personalSubscription: subscription } =
  20. useSubscriptionDashboardContext()
  21. const postCheckoutRedirect = getMeta('ol-postCheckoutRedirect')
  22. const { appName, adminEmail } = getMeta('ol-ExposedSettings')
  23. useBroadcastUser()
  24. if (!subscription || !('payment' in subscription)) return null
  25. const onAiStandalonePlan = isStandaloneAiPlanCode(subscription.planCode)
  26. return (
  27. <div className="container">
  28. <OLRow>
  29. <OLCol lg={{ span: 8, offset: 2 }}>
  30. <OLPageContentCard>
  31. <div className="page-header">
  32. <h2>{t('thanks_for_subscribing')}</h2>
  33. </div>
  34. <OLNotification
  35. type="success"
  36. content={
  37. <>
  38. {subscription.payment.trialEndsAt && (
  39. <>
  40. <p>
  41. <Trans
  42. i18nKey="next_payment_of_x_collectected_on_y"
  43. values={{
  44. paymentAmmount: subscription.payment.displayPrice,
  45. collectionDate:
  46. subscription.payment.nextPaymentDueAt,
  47. }}
  48. shouldUnescape
  49. tOptions={{ interpolation: { escapeValue: true } }}
  50. components={[<strong />, <strong />]} // eslint-disable-line react/jsx-key
  51. />
  52. </p>
  53. <PriceExceptions subscription={subscription} />
  54. </>
  55. )}
  56. <p>
  57. {t('to_modify_your_subscription_go_to')}&nbsp;
  58. <a href="/user/subscription" rel="noopener noreferrer">
  59. {t('manage_subscription')}.
  60. </a>
  61. </p>
  62. </>
  63. }
  64. />
  65. {subscription.groupPlan && (
  66. <p>
  67. <a
  68. href={`/manage/groups/${subscription._id}/members`}
  69. className="btn btn-primary btn-large"
  70. >
  71. {t('add_your_first_group_member_now')}
  72. </a>
  73. </p>
  74. )}
  75. <ThankYouSection
  76. subscription={subscription}
  77. onAiStandalonePlan={onAiStandalonePlan}
  78. />
  79. <PremiumFeaturesLink subscription={subscription} />
  80. <p>
  81. {t('need_anything_contact_us_at')}&nbsp;
  82. <a href={`mailto:${adminEmail}`} rel="noopener noreferrer">
  83. {adminEmail}
  84. </a>
  85. .
  86. </p>
  87. {!onAiStandalonePlan && (
  88. <p>
  89. <Trans
  90. i18nKey="help_improve_overleaf_fill_out_this_survey"
  91. components={[
  92. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  93. <a
  94. href="https://forms.gle/CdLNX9m6NLxkv1yr5"
  95. target="_blank"
  96. rel="noopener noreferrer"
  97. />,
  98. ]}
  99. />
  100. </p>
  101. )}
  102. <p>
  103. {t('regards')},
  104. <br />
  105. The {appName} Team
  106. </p>
  107. <p>
  108. <a
  109. className="btn btn-primary"
  110. href={postCheckoutRedirect || '/project'}
  111. rel="noopener noreferrer"
  112. >
  113. {t('back_to_your_projects')}
  114. </a>
  115. </p>
  116. </OLPageContentCard>
  117. </OLCol>
  118. </OLRow>
  119. </div>
  120. )
  121. }
  122. function ThankYouSection({
  123. subscription,
  124. onAiStandalonePlan,
  125. }: {
  126. subscription: PaidSubscription
  127. onAiStandalonePlan: boolean
  128. }) {
  129. const { t } = useTranslation()
  130. const hasAiAddon = subscription?.addOns?.some(
  131. addOn => addOn.addOnCode === AI_ADD_ON_CODE
  132. )
  133. if (onAiStandalonePlan) {
  134. return (
  135. <p>
  136. {t('thanks_for_subscribing_to_the_add_on', {
  137. addOnName: ADD_ON_NAME,
  138. })}
  139. </p>
  140. )
  141. }
  142. if (hasAiAddon) {
  143. return (
  144. <p>
  145. {t('thanks_for_subscribing_to_plan_with_add_on', {
  146. planName: subscription.plan.name,
  147. addOnName: ADD_ON_NAME,
  148. })}
  149. </p>
  150. )
  151. }
  152. return (
  153. <p>
  154. {t('thanks_for_subscribing_you_help_sl', {
  155. planName: subscription.plan.name,
  156. })}
  157. </p>
  158. )
  159. }
  160. export default SuccessfulSubscription