diff --git a/corehq/apps/analytics/static/analytix/js/cta_forms.js b/corehq/apps/analytics/static/analytix/js/cta_forms.js index 7658f14b2c55..21bfa3bc18f2 100644 --- a/corehq/apps/analytics/static/analytix/js/cta_forms.js +++ b/corehq/apps/analytics/static/analytix/js/cta_forms.js @@ -5,7 +5,6 @@ hqDefine('analytix/js/cta_forms', [ 'underscore', 'hqwebapp/js/initial_page_data', 'hqwebapp/js/assert_properties', - 'intl-tel-input/build/js/intlTelInput.min', 'hqwebapp/js/bootstrap3/validators.ko', // needed for validation of startDate and endDate ], function ( $, @@ -13,26 +12,15 @@ hqDefine('analytix/js/cta_forms', [ _, initialPageData, assertProperties, - intlTelInput, ) { let hubspotCtaForm = function (config) { let self = {}; assertProperties.assertRequired(config, [ 'hubspotFormId', - 'showContactMethod', - 'showPreferredLanguage', - 'useWhatsApp', - 'useGoogleHangouts', 'nextButtonText', - 'phoneNumberSelector', 'submitCallbackFn', ]); - self.showContactMethod = ko.observable(config.showContactMethod); - self.showPreferredLanguage = ko.observable(config.showPreferredLanguage); - - self.useWhatsApp = ko.observable(config.useWhatsApp); - self.useGoogleHangouts = ko.observable(config.useGoogleHangouts); self.nextButtonText = ko.observable(config.nextButtonText); self.firstname = ko.observable() @@ -56,6 +44,13 @@ hqDefine('analytix/js/cta_forms', [ params: true, }, }); + self.jobtitle = ko.observable() + .extend({ + required: { + message: gettext("Please enter your job title."), + params: true, + }, + }); self.email = ko.observable() .extend({ required: { @@ -67,55 +62,28 @@ hqDefine('analytix/js/cta_forms', [ emailRFC2822: true, }); - self.preferred_method_of_contact = ko.observable(); - - self.phone = ko.observable(); - - self.skype__c = ko.observable(); - self.preferred_whatsapp_number = ko.observable(); - - self.showPhoneNumber = ko.computed(function () { - return self.preferred_method_of_contact() === "Phone"; - }); - self.showSkype = ko.computed(function () { - return self.preferred_method_of_contact() === "Skype"; - }); - self.showWhatsApp = ko.computed(function () { - return self.preferred_method_of_contact() === "WhatsApp"; - }); - - self.language__c = ko.observable(); + self.language = ko.observable(); + self.discoverySource = ko.observable(); + self.otherSource = ko.observable(); self.areMainFieldsValid = ko.computed(function () { return _.every([ self.firstname, self.lastname, self.company, + self.jobtitle, self.email, ], function (prop) { return prop() !== undefined && prop.isValid(); }); }); - self.areContactFieldsValid = ko.computed(function () { - if (!self.showContactMethod()) { - return true; - } - if (!self.preferred_method_of_contact()) { - return false; - } - let isWhatsAppValid = self.showWhatsApp() && !!self.preferred_whatsapp_number(), - isPhoneValid = self.showPhoneNumber() && !!self.phone(), - isSkypeValid = self.showSkype() && !!self.skype__c(); - return isWhatsAppValid || isPhoneValid || isSkypeValid; - }); - self.isLanguageFieldValid = ko.computed(function () { - return !self.showPreferredLanguage() || !!self.language__c(); + return !!self.language(); }); self.isFormReadyToSubmit = ko.computed(function () { - return self.areContactFieldsValid() && self.areMainFieldsValid() && self.isLanguageFieldValid(); + return self.areMainFieldsValid() && self.isLanguageFieldValid(); }); self.isSubmitDisabled = ko.computed(function () { @@ -127,53 +95,23 @@ hqDefine('analytix/js/cta_forms', [ return !!self.errorMessage(); }); - var phoneNumberWidget = intlTelInput(config.phoneNumberSelector.get(0), { - containerClass: "w-100", - separateDialCode: true, - loadUtils: () => import("intl-tel-input/utils"), - initialCountry: "auto", - geoIpLookup: function (success) { - $.get("https://ipinfo.io", function () {}, "jsonp").always(function (resp) { - var countryCode = (resp && resp.country) ? resp.country : ""; - if (!countryCode) { - countryCode = "us"; - } - success(countryCode); - }); - }, - }); - - self.getFullPhoneNumber = function () { - return phoneNumberWidget.getNumber(); - }; - self.submitForm = function () { let submitData = { hubspot_form_id: config.hubspotFormId, firstname: self.firstname(), lastname: self.lastname(), company: self.company(), + jobtitle: self.jobtitle(), email: self.email(), + preferred_language: self.language(), + marketing_purposes___how_did_you_hear_about_us_: self.discoverySource(), + if_other___how_did_you_hear_about_us_: self.otherSource(), // needed for hubspot context page_url: window.location.href, page_name: document.title, }; - if (self.showContactMethod()) { - submitData.preferred_method_of_contact = self.preferred_method_of_contact(); - } - if (self.showPhoneNumber()) { - submitData.phone = self.phone(); - } - if (self.showWhatsApp()) { - submitData.preferred_whatsapp_number = self.preferred_whatsapp_number(); - } - if (self.showSkype()) { - submitData.skype__c = self.skype__c(); - } - if (self.showPreferredLanguage()) { - submitData.language__c = self.language__c(); - } + $.ajax({ method: 'post', url: initialPageData.reverse("submit_hubspot_cta_form"), diff --git a/corehq/apps/analytics/static/analytix/js/hubspot.js b/corehq/apps/analytics/static/analytix/js/hubspot.js index 4a065f2cd07f..cd5339917448 100644 --- a/corehq/apps/analytics/static/analytix/js/hubspot.js +++ b/corehq/apps/analytics/static/analytix/js/hubspot.js @@ -44,28 +44,15 @@ hqDefine('analytix/js/hubspot', [ * Activates the Hubspot Request Demo form */ _utils.loadDemoForm = function () { - let isTrial = _get('isDemoTrial'), - isVariant = _get('demoABv2') && _get('demoABv2').version === 'variant', - $modal = $('#cta-form-get-demo'), + let $modal = $('#cta-form-get-demo'), $form = $('#get-demo-cta-form-content'), hasInteractedWithForm = false, - formId, + formId = "f6ebf161-fccf-4083-9a72-5839a0c8ac8c", demoForm; - if (isTrial) { - formId = isVariant ? "c2381f55-9bd9-4f27-8476-82900e58bfd6" : "4474515e-fea6-4154-b3cf-1fe42b1c1333"; - } else { - formId = isVariant ? "f6ebf161-fccf-4083-9a72-5839a0c8ac8c" : "d1897875-a5bb-4b63-9b9c-3d8fdbbe8274"; - } - demoForm = ctaForms.hubspotCtaForm({ hubspotFormId: formId, - showContactMethod: isVariant, - showPreferredLanguage: false, - useWhatsApp: false, - useGoogleHangouts: true, nextButtonText: gettext("Submit Request"), - phoneNumberSelector: $form.find('input[name="phone"]'), submitCallbackFn: function () { $('#get-demo-cta-success').fadeIn(); $('#get-demo-cta-form-content').addClass('hidden').addClass('d-none'); // todo after bootstrap 5 migration diff --git a/corehq/apps/analytics/templates/analytics/forms/bootstrap3/hubspot_cta_form.html b/corehq/apps/analytics/templates/analytics/forms/bootstrap3/hubspot_cta_form.html index d26151000c46..2c5d0e9bbbb2 100644 --- a/corehq/apps/analytics/templates/analytics/forms/bootstrap3/hubspot_cta_form.html +++ b/corehq/apps/analytics/templates/analytics/forms/bootstrap3/hubspot_cta_form.html @@ -15,10 +15,12 @@ {% trans "First name" %}*