Ver código fonte

Merge pull request #5641 from overleaf/jpa-survey-notification-2

[web] implement institutional leavers survey logic in frontend only

GitOrigin-RevId: e1002ee6f75ba3865c955eefa8482af0c72bb825
Jakob Ackermann 5 anos atrás
pai
commit
0ee93793e3

+ 13 - 0
services/web/app/views/user/settings/user-affiliations.pug

@@ -158,6 +158,19 @@ form.row(
 						div(ng-class="{'alert alert-info': reconfirmationRemoveEmail === userEmail.email}")
 						div(ng-class="{'alert alert-info': reconfirmationRemoveEmail === userEmail.email}")
 							+reconfirmAffiliationNotification('/user/settings')
 							+reconfirmAffiliationNotification('/user/settings')
 
 
+				tr(ng-if="showInstitutionalLeaversSurvey")
+					td(colspan="3")
+						div.alert.alert-info
+							button.close.pull-right(ng-click="dismissInstitutionalLeaversSurvey()")
+								span(aria-hidden="true") ×
+								span.sr-only #{translate("close")}
+							strong #{translate('limited_offer')}:
+							|
+							| #{translate('institutional_leavers_survey_notification')}
+							|
+							a.btn-inline-link(href="https://docs.google.com/forms/d/e/1FAIpQLSfYdeeoY5p1d31r5iUx1jw0O-Gd66vcsBi_Ntu3lJRMjV2EJA/viewform")
+								strong #{translate('take_short_survey')}
+
 				tr.affiliations-table-highlighted-row(
 				tr.affiliations-table-highlighted-row(
 					ng-if="!ui.showAddEmailUI && !ui.isMakingRequest"
 					ng-if="!ui.showAddEmailUI && !ui.isMakingRequest"
 				)
 				)

+ 40 - 0
services/web/frontend/js/main/affiliations/controllers/UserAffiliationsController.js

@@ -22,6 +22,24 @@ export default App.controller(
     $scope.reconfirmationRemoveEmail = getMeta('ol-reconfirmationRemoveEmail')
     $scope.reconfirmationRemoveEmail = getMeta('ol-reconfirmationRemoveEmail')
     $scope.reconfirmedViaSAML = getMeta('ol-reconfirmedViaSAML')
     $scope.reconfirmedViaSAML = getMeta('ol-reconfirmedViaSAML')
 
 
+    $scope.showInstitutionalLeaversSurvey = false
+    $scope.dismissInstitutionalLeaversSurvey = () => {
+      try {
+        localStorage.setItem('hideInstitutionalLeaversSurvey', true)
+      } catch (e) {}
+      $scope.showInstitutionalLeaversSurvey = false
+    }
+    function maybeShowInstitutionalLeaversSurvey() {
+      if (localStorage.getItem('hideInstitutionalLeaversSurvey')) return
+      if (
+        localStorage.getItem('showInstitutionalLeaversSurveyUntil') > Date.now()
+      ) {
+        $scope.showInstitutionalLeaversSurvey = true
+      }
+    }
+    maybeShowInstitutionalLeaversSurvey()
+
+    const ONE_WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000
     const LOCAL_AND_DOMAIN_REGEX = /([^@]+)@(.+)/
     const LOCAL_AND_DOMAIN_REGEX = /([^@]+)@(.+)/
     const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA -Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
     const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA -Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
 
 
@@ -202,6 +220,28 @@ export default App.controller(
       return _monitorRequest(
       return _monitorRequest(
         UserAffiliationsDataService.removeUserEmail(userEmail.email)
         UserAffiliationsDataService.removeUserEmail(userEmail.email)
       )
       )
+        .then(() => {
+          if (
+            userEmail.emailHasInstitutionLicence ||
+            (userEmail.affiliation && userEmail.affiliation.pastReconfirmDate)
+          ) {
+            const stillHasLicenseAccess = $scope.userEmails.some(
+              ue => ue.emailHasInstitutionLicence
+            )
+            if (!stillHasLicenseAccess) {
+              try {
+                localStorage.setItem(
+                  'showInstitutionalLeaversSurveyUntil',
+                  Date.now() + ONE_WEEK_IN_MS
+                )
+                maybeShowInstitutionalLeaversSurvey()
+              } catch (e) {}
+            }
+          }
+        })
+        .catch(() => {
+          $scope.userEmails.push(userEmail)
+        })
     }
     }
 
 
     $scope.resendConfirmationEmail = function (userEmail) {
     $scope.resendConfirmationEmail = function (userEmail) {

+ 2 - 0
services/web/locales/en.json

@@ -1508,6 +1508,8 @@
   "skip_to_content": "Skip to content",
   "skip_to_content": "Skip to content",
   "logging_out": "Logging out",
   "logging_out": "Logging out",
   "share_thoughts_on_gallery": "Share your thoughts on the Overleaf Template Gallery!",
   "share_thoughts_on_gallery": "Share your thoughts on the Overleaf Template Gallery!",
+  "institutional_leavers_survey_notification": "Provide some quick feedback to receive a 25% discount on an annual subscription!",
+  "limited_offer": "Limited offer",
   "take_short_survey": "Take a short survey",
   "take_short_survey": "Take a short survey",
   "official": "Official",
   "official": "Official",
   "template_approved_by_publisher": "This template has been approved by the publisher",
   "template_approved_by_publisher": "This template has been approved by the publisher",