From 2ee90c9ca6aa32bdfb1937c701a0d68ca5bc2e23 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 2 Nov 2021 11:34:25 +0100 Subject: [PATCH] Merge pull request #5641 from overleaf/jpa-survey-notification-2 [web] implement institutional leavers survey logic in frontend only GitOrigin-RevId: e1002ee6f75ba3865c955eefa8482af0c72bb825 --- .../views/user/settings/user-affiliations.pug | 13 ++++++ .../controllers/UserAffiliationsController.js | 40 +++++++++++++++++++ services/web/locales/en.json | 2 + 3 files changed, 55 insertions(+) diff --git a/services/web/app/views/user/settings/user-affiliations.pug b/services/web/app/views/user/settings/user-affiliations.pug index ebeb6ade14..cacbdd43a7 100644 --- a/services/web/app/views/user/settings/user-affiliations.pug +++ b/services/web/app/views/user/settings/user-affiliations.pug @@ -158,6 +158,19 @@ form.row( div(ng-class="{'alert alert-info': reconfirmationRemoveEmail === userEmail.email}") +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( ng-if="!ui.showAddEmailUI && !ui.isMakingRequest" ) diff --git a/services/web/frontend/js/main/affiliations/controllers/UserAffiliationsController.js b/services/web/frontend/js/main/affiliations/controllers/UserAffiliationsController.js index efb7b0b85b..9c6f955b81 100644 --- a/services/web/frontend/js/main/affiliations/controllers/UserAffiliationsController.js +++ b/services/web/frontend/js/main/affiliations/controllers/UserAffiliationsController.js @@ -22,6 +22,24 @@ export default App.controller( $scope.reconfirmationRemoveEmail = getMeta('ol-reconfirmationRemoveEmail') $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 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( 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) { diff --git a/services/web/locales/en.json b/services/web/locales/en.json index 0012b9c83a..200d62bd25 100644 --- a/services/web/locales/en.json +++ b/services/web/locales/en.json @@ -1508,6 +1508,8 @@ "skip_to_content": "Skip to content", "logging_out": "Logging out", "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", "official": "Official", "template_approved_by_publisher": "This template has been approved by the publisher",