From 8b00a496e7c0e01fc0bd7b2fddfd14db36664c2b Mon Sep 17 00:00:00 2001
From: Alexandre Bourdin <abourdin@users.noreply.github.com>
Date: Wed, 22 Feb 2023 13:18:01 +0100
Subject: [PATCH] Merge pull request #11881 from
 overleaf/ab-custom-subscription-react-dash

[web] Add a contact support message for custom subsbcriptions on React dash

GitOrigin-RevId: e2a2bb27b4f1e70cbbe62f4c837fe63d81a820c2
---
 .../views/subscriptions/dashboard-react.pug   | 13 ++++---
 .../web/frontend/extracted-translations.json  |  1 +
 ...ontact-support-for-custom-subscription.tsx | 12 ++++++
 .../dashboard/subscription-dashboard.tsx      |  7 +++-
 .../subscription-dashboard-context.tsx        |  4 ++
 services/web/locales/en.json                  |  1 +
 .../dashboard/subscription-dashboard.test.tsx | 39 ++++++++++++++++++-
 .../render-with-subscription-dash-context.tsx |  5 ++-
 8 files changed, 72 insertions(+), 10 deletions(-)
 create mode 100644 services/web/frontend/js/features/subscription/components/dashboard/contact-support-for-custom-subscription.tsx

diff --git a/services/web/app/views/subscriptions/dashboard-react.pug b/services/web/app/views/subscriptions/dashboard-react.pug
index 3b21ea8584..04c6368794 100644
--- a/services/web/app/views/subscriptions/dashboard-react.pug
+++ b/services/web/app/views/subscriptions/dashboard-react.pug
@@ -7,12 +7,13 @@ block head-scripts
 	script(type="text/javascript", nonce=scriptNonce, src="https://js.recurly.com/v4/recurly.js")
 
 block append meta
-	meta(name="ol-managedGroupSubscriptions", data-type="json" content=managedGroupSubscriptions)
-	meta(name="ol-memberGroupSubscriptions", data-type="json" content=memberGroupSubscriptions)
-	meta(name="ol-managedInstitutions", data-type="json", content=managedInstitutions)
-	meta(name="ol-managedPublishers", data-type="json" content=managedPublishers)
-	meta(name="ol-planCodesChangingAtTermEnd", data-type="json", content=planCodesChangingAtTermEnd)
-	meta(name="ol-currentInstitutionsWithLicence", data-type="json" content=currentInstitutionsWithLicence)
+	meta(name="ol-managedGroupSubscriptions" data-type="json" content=managedGroupSubscriptions)
+	meta(name="ol-memberGroupSubscriptions" data-type="json" content=memberGroupSubscriptions)
+	meta(name="ol-managedInstitutions" data-type="json" content=managedInstitutions)
+	meta(name="ol-managedPublishers" data-type="json" content=managedPublishers)
+	meta(name="ol-planCodesChangingAtTermEnd" data-type="json", content=planCodesChangingAtTermEnd)
+	meta(name="ol-currentInstitutionsWithLicence" data-type="json" content=currentInstitutionsWithLicence)
+	meta(name="ol-hasSubscription" data-type="boolean" content=hasSubscription)
 	meta(name="ol-plans", data-type="json" content=plans)
 	if (personalSubscription && personalSubscription.recurly)
 		meta(name="ol-recurlyApiKey" content=settings.apis.recurly.publicKey)
diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json
index f554ad0d40..2d27bcdb04 100644
--- a/services/web/frontend/extracted-translations.json
+++ b/services/web/frontend/extracted-translations.json
@@ -911,6 +911,7 @@
   "you_are_a_manager_of_commons_at_institution_x": "",
   "you_are_a_manager_of_publisher_x": "",
   "you_are_a_manager_of_x_plan_as_member_of_group_subscription_y_administered_by_z": "",
+  "you_are_on_a_paid_plan_contact_support_to_find_out_more": "",
   "you_are_on_x_plan_as_a_confirmed_member_of_institution_y": "",
   "you_are_on_x_plan_as_member_of_group_subscription_y_administered_by_z": "",
   "you_can_now_log_in_sso": "",
diff --git a/services/web/frontend/js/features/subscription/components/dashboard/contact-support-for-custom-subscription.tsx b/services/web/frontend/js/features/subscription/components/dashboard/contact-support-for-custom-subscription.tsx
new file mode 100644
index 0000000000..5875d8893d
--- /dev/null
+++ b/services/web/frontend/js/features/subscription/components/dashboard/contact-support-for-custom-subscription.tsx
@@ -0,0 +1,12 @@
+import { Trans } from 'react-i18next'
+
+export default function ContactSupport() {
+  return (
+    <p>
+      <Trans
+        i18nKey="you_are_on_a_paid_plan_contact_support_to_find_out_more"
+        components={[<a href="/contact" />]} // eslint-disable-line react/jsx-key, jsx-a11y/anchor-has-content
+      />
+    </p>
+  )
+}
diff --git a/services/web/frontend/js/features/subscription/components/dashboard/subscription-dashboard.tsx b/services/web/frontend/js/features/subscription/components/dashboard/subscription-dashboard.tsx
index 72c44388ff..e4e687d6fa 100644
--- a/services/web/frontend/js/features/subscription/components/dashboard/subscription-dashboard.tsx
+++ b/services/web/frontend/js/features/subscription/components/dashboard/subscription-dashboard.tsx
@@ -1,4 +1,5 @@
 import { useTranslation } from 'react-i18next'
+import ContactSupport from './contact-support-for-custom-subscription'
 import GroupSubscriptionMemberships from './group-subscription-memberships'
 import InstitutionMemberships from './institution-memberships'
 import FreePlan from './free-plan'
@@ -10,7 +11,8 @@ import { useSubscriptionDashboardContext } from '../../context/subscription-dash
 
 function SubscriptionDashboard() {
   const { t } = useTranslation()
-  const { hasDisplayedSubscription } = useSubscriptionDashboardContext()
+  const { hasDisplayedSubscription, hasSubscription } =
+    useSubscriptionDashboardContext()
 
   return (
     <div className="container">
@@ -27,7 +29,8 @@ function SubscriptionDashboard() {
             <ManagedPublishers />
             <GroupSubscriptionMemberships />
             <InstitutionMemberships />
-            {!hasDisplayedSubscription && <FreePlan />}
+            {!hasDisplayedSubscription &&
+              (hasSubscription ? <ContactSupport /> : <FreePlan />)}
           </div>
         </div>
       </div>
diff --git a/services/web/frontend/js/features/subscription/context/subscription-dashboard-context.tsx b/services/web/frontend/js/features/subscription/context/subscription-dashboard-context.tsx
index 800bf4e1cd..e57b3272e4 100644
--- a/services/web/frontend/js/features/subscription/context/subscription-dashboard-context.tsx
+++ b/services/web/frontend/js/features/subscription/context/subscription-dashboard-context.tsx
@@ -47,6 +47,7 @@ type SubscriptionDashboardContextValue = {
   updateManagedInstitution: (institution: ManagedInstitution) => void
   modalIdShown?: SubscriptionDashModalIds
   personalSubscription?: Subscription
+  hasSubscription: boolean
   plans: Plan[]
   planCodeToChangeTo?: string
   queryingGroupPlanToChangeToPrice: boolean
@@ -121,6 +122,7 @@ export function SubscriptionDashboardProvider({
     ManagedInstitution[]
   >(getMeta('ol-managedInstitutions'))
   const managedPublishers = getMeta('ol-managedPublishers')
+  const hasSubscription = getMeta('ol-hasSubscription')
   const recurlyApiKey = getMeta('ol-recurlyApiKey')
 
   const hasDisplayedSubscription = Boolean(
@@ -247,6 +249,7 @@ export function SubscriptionDashboardProvider({
       updateManagedInstitution,
       modalIdShown,
       personalSubscription,
+      hasSubscription,
       plans,
       planCodeToChangeTo,
       queryingGroupPlanToChangeToPrice,
@@ -282,6 +285,7 @@ export function SubscriptionDashboardProvider({
       updateManagedInstitution,
       modalIdShown,
       personalSubscription,
+      hasSubscription,
       plans,
       planCodeToChangeTo,
       queryingGroupPlanToChangeToPrice,
diff --git a/services/web/locales/en.json b/services/web/locales/en.json
index dd92a4c0f9..15bac77170 100644
--- a/services/web/locales/en.json
+++ b/services/web/locales/en.json
@@ -1687,6 +1687,7 @@
   "you_are_a_manager_of_publisher_x": "You are a <0>manager</0> of <0>__publisherName__</0>",
   "you_are_a_manager_of_x_plan_as_member_of_group_subscription_y_administered_by_z": "You are a <1>manager</1> of the <0>__planName__</0> group subscription <1>__groupName__</1> administered by <1>__adminEmail__</1>",
   "you_are_about_to_upgrade": "You are about to upgrade to the __planName__",
+  "you_are_on_a_paid_plan_contact_support_to_find_out_more": "You’re on an __appName__ Paid plan. <0>Contact support</0> to find out more.",
   "you_are_on_x_plan_as_a_confirmed_member_of_institution_y": "You are on our <0>__planName__</0> plan as a <1>confirmed member</1> of <1>__institutionName__</1>",
   "you_are_on_x_plan_as_member_of_group_subscription_y_administered_by_z": "You are on our <0>__planName__</0> plan as a <1>member</1> of the group subscription <1>__groupName__</1> administered by <1>__adminEmail__</1>",
   "you_can_now_log_in_sso": "You can now log in through your institution and may receive <0>free __appName__ Professional features</0>!",
diff --git a/services/web/test/frontend/features/subscription/components/dashboard/subscription-dashboard.test.tsx b/services/web/test/frontend/features/subscription/components/dashboard/subscription-dashboard.test.tsx
index 796956dcff..99f3db1b58 100644
--- a/services/web/test/frontend/features/subscription/components/dashboard/subscription-dashboard.test.tsx
+++ b/services/web/test/frontend/features/subscription/components/dashboard/subscription-dashboard.test.tsx
@@ -12,12 +12,49 @@ describe('<SubscriptionDashboard />', function () {
   })
 
   describe('Free Plan', function () {
-    it('does not render the "Get the most out of your" subscription text', function () {
+    beforeEach(function () {
       renderWithSubscriptionDashContext(<SubscriptionDashboard />)
+    })
+
+    it('does not render the "Get the most out of your" subscription text', function () {
       const text = screen.queryByText('Get the most out of your', {
         exact: false,
       })
       expect(text).to.be.null
     })
+
+    it('does not render the contact support message', function () {
+      const text = screen.queryByText(
+        `You’re on an Overleaf Paid plan. Contact`,
+        {
+          exact: false,
+        }
+      )
+      expect(text).to.be.null
+    })
+  })
+
+  describe('Custom subscription', function () {
+    it('renders the contact support message', function () {
+      renderWithSubscriptionDashContext(<SubscriptionDashboard />, {
+        metaTags: [
+          {
+            name: 'ol-currentInstitutionsWithLicence',
+            value: [],
+          },
+          {
+            name: 'ol-hasSubscription',
+            value: true,
+          },
+        ],
+      })
+
+      screen.getByText(`You’re on an Overleaf Paid plan.`, {
+        exact: false,
+      })
+      screen.getByText(`Contact support`, {
+        exact: false,
+      })
+    })
   })
 })
diff --git a/services/web/test/frontend/features/subscription/helpers/render-with-subscription-dash-context.tsx b/services/web/test/frontend/features/subscription/helpers/render-with-subscription-dash-context.tsx
index f3bea0700f..5dbe9a18c5 100644
--- a/services/web/test/frontend/features/subscription/helpers/render-with-subscription-dash-context.tsx
+++ b/services/web/test/frontend/features/subscription/helpers/render-with-subscription-dash-context.tsx
@@ -6,7 +6,10 @@ import { groupPriceByUsageTypeAndSize, plans } from '../fixtures/plans'
 export function renderWithSubscriptionDashContext(
   component: React.ReactElement,
   options?: {
-    metaTags?: { name: string; value: string | object | Array<object> }[]
+    metaTags?: {
+      name: string
+      value: string | object | Array<object> | boolean
+    }[]
     recurlyNotLoaded?: boolean
     queryingRecurly?: boolean
     currencyCode?: string