Skip to content

Commit b9e1b72

Browse files
committed
Move region to config settings. Notifications updates.
1 parent d1c15da commit b9e1b72

File tree

11 files changed

+38
-68
lines changed

11 files changed

+38
-68
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
1-
@inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco.Cms.Integrations.Crm.Hubspot.Models.ViewModels.HubspotFormViewModel>
1+
@using System.Configuration
2+
@inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco.Cms.Integrations.Crm.Hubspot.Models.ViewModels.HubspotFormViewModel>
23

34
@{
4-
var hbsptScriptPath = Model.EuRegion ? "//js-eu1.hsforms.net/forms/shell.js" : "//js.hsforms.net/forms/shell.js";
5+
var region = ConfigurationManager.AppSettings["Umbraco.Cms.Integrations.Crm.Hubspot.Region"];
6+
7+
var hbsptScriptPath = string.IsNullOrEmpty(region) ? "//js.hsforms.net/forms/shell.js" : "//js-eu1.hsforms.net/forms/shell.js";
58
}
69

710
<script charset="utf-8" type="text/javascript" src="@hbsptScriptPath"></script>
8-
@if (Model.EuRegion)
9-
{
10-
<script>
11-
hbspt.forms.create({
12-
region: "eu1",
13-
portalId: "@Model.PortalId",
14-
formId: "@Model.Id"
15-
});
16-
</script>
17-
}
18-
else
19-
{
20-
<script>
11+
<script>
2112
hbspt.forms.create({
13+
region: "@region",
2214
portalId: "@Model.PortalId",
2315
formId: "@Model.Id"
2416
});
25-
</script>
26-
}
27-
17+
</script>

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/formpicker.controller.js

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
angular.module("umbraco")
22
.controller("Umbraco.Cms.Integrations.Crm.Hubspot.FormPickerController",
3-
function ($scope, editorService, notificationsService, umbracoCmsIntegrationsCrmHubspotResource) {
3+
function ($scope, editorService, notificationsService, umbracoCmsIntegrationsCrmHubspotService, umbracoCmsIntegrationsCrmHubspotResource) {
44

55
const oauthName = "OAuth";
66

@@ -10,24 +10,10 @@
1010
vm.searchTerm = "";
1111
vm.error = "";
1212
vm.isValid = true;
13-
vm.euRegion = false;
14-
15-
const configDescription = {
16-
API: "An API key is configured and will be used to connect to your HubSpot account.",
17-
OAuth:
18-
"No API key is configured. To connect to your HubSpot account using OAuth click 'Connect', select your account and agree to the permissions.",
19-
None: "No API or OAuth configuration could be found. Please review your settings before continuing.",
20-
OAuthConnected:
21-
"OAuth is configured and an access token is available to connect to your HubSpot account. To revoke, click 'Revoke'"
22-
};
2313

2414
// check configuration
2515
checkConfiguration(loadForms);
2616

27-
vm.toggleRegion = function() {
28-
vm.euRegion = !vm.euRegion;
29-
}
30-
3117
vm.remove = function () {
3218
$scope.model.value = null;
3319
};
@@ -38,14 +24,11 @@
3824

3925
vm.openHubspotFormPickerOverlay = function () {
4026
var options = {
41-
title: "Hubspot forms",
27+
title: "HubSpot forms",
4228
subtitle: "Select a form",
4329
view: "/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/views/formpickereditor.html",
4430
size: "medium",
45-
pickForm: function (form, euRegion) {
46-
47-
form.euRegion = euRegion;
48-
31+
pickForm: function (form) {
4932
vm.saveForm(form);
5033

5134
editorService.close();
@@ -64,14 +47,14 @@
6447
vm.status = {
6548
isValid: response.isValid === true,
6649
type: response.type,
67-
description: configDescription[response.type.value],
50+
description: umbracoCmsIntegrationsCrmHubspotService.configDescription[response.type.value],
6851
useOAuth: response.isValid === true && response.type.value === oauthName
6952
};
7053

7154
if (response.isValid === false) {
7255
vm.loading = false;
73-
vm.error = configDescription.None;
74-
notificationsService.warning("Hubspot API", configDescription.None);
56+
vm.error = umbracoCmsIntegrationsCrmHubspotService.configDescription.None;
57+
notificationsService.warning("HubSpot API", umbracoCmsIntegrationsCrmHubspotService.configDescription.None);
7558
} else {
7659
callback();
7760
}
@@ -84,7 +67,7 @@
8467
umbracoCmsIntegrationsCrmHubspotResource.validateAccessToken().then(function (response) {
8568
if (response.isExpired === true || response.isValid === false) {
8669
vm.loading = false;
87-
notificationsService.warning("Hubspot API", "Invalid access token. Please review OAuth settings of the editor.");
70+
notificationsService.warning("HubSpot API", "Invalid access token. Please review OAuth settings of the editor.");
8871
return;
8972
}
9073

@@ -93,7 +76,7 @@
9376
vm.hubspotFormsList = data.forms;
9477

9578
if (data.isValid === false || data.isExpired === true) {
96-
notificationsService.error("Hubspot API", "Invalid access token. Please review OAuth settings of the editor.");
79+
notificationsService.error("HubSpot API", "Invalid access token. Please review OAuth settings of the editor.");
9780
}
9881
});
9982
});
@@ -105,7 +88,7 @@
10588
vm.hubspotFormsList = data.forms;
10689

10790
if (data.isValid === false || data.isExpired === true) {
108-
notificationsService.error("Hubspot API", "Invalid API key");
91+
notificationsService.error("HubSpot API", "Invalid API key");
10992
}
11093
});
11194

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/settings.controller.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
function settingsController($scope, notificationsService, umbracoCmsIntegrationsCrmHubspotResource) {
1+
function settingsController($scope, notificationsService, umbracoCmsIntegrationsCrmHubspotService, umbracoCmsIntegrationsCrmHubspotResource) {
22

33
var vm = this;
44

55
const oauthName = "OAuth";
6-
const configDescription = {
7-
API: "An API key is configured and will be used to connect to your HubSpot account.",
8-
OAuth:
9-
"No API key is configured. To connect to your HubSpot account using OAuth click 'Connect', select your account and agree to the permissions.",
10-
None: "No API or OAuth configuration could be found. Please review your settings before continuing.",
11-
OAuthConnected:
12-
"OAuth is configured and an access token is available to connect to your HubSpot account. To revoke, click 'Revoke'"
13-
};
146

157
vm.oauthSetup = {};
168
vm.status = {};
17-
189

1910
$scope.$on('formSubmitting', function () {
2011

@@ -29,18 +20,16 @@
2920
vm.status = {
3021
isValid: response.isValid === true,
3122
type: response.type,
32-
description: configDescription[response.type.value],
23+
description: umbracoCmsIntegrationsCrmHubspotService.configDescription[response.type.value],
3324
useOAuth: response.isValid === true && response.type.value === oauthName
3425
};
3526

3627
if (vm.status.useOAuth) {
3728
validateOAuthSetup();
3829
}
3930

40-
if (response.isValid === true) {
41-
notificationsService.success("Configuration", `${response.type.value} setup is configured.`);
42-
} else {
43-
notificationsService.warning("Configuration",
31+
if (response.isValid !== true) {
32+
notificationsService.warning("HubSpot Configuration",
4433
"Invalid setup. Please review the API/OAuth settings.");
4534
}
4635
});
@@ -66,6 +55,8 @@
6655

6756
umbracoCmsIntegrationsCrmHubspotResource.getAccessToken(event.data.code).then(function (response) {
6857
vm.oauthSetup.isConnected = true;
58+
vm.status.description = umbracoCmsIntegrationsCrmHubspotService.configDescription.OAuthConnected;
59+
notificationsService.success("HubSpot Configuration", "OAuth connected.");
6960
});
7061

7162
}
@@ -81,8 +72,12 @@
8172
isAccessTokenValid: response.isValid
8273
}
8374

75+
if (vm.oauthSetup.isConnected === true && vm.oauthSetup.isAccessTokenValid === true) {
76+
vm.status.description = umbracoCmsIntegrationsCrmHubspotService.configDescription.OAuthConnected;
77+
}
78+
8479
// refresh access token
85-
if (vm.oauthSetup.isExpired === true) {
80+
if (vm.oauthSetup.isAccessTokenExpired === true) {
8681
umbracoCmsIntegrationsCrmHubspotResource.refreshAccessToken().then(function (response) {
8782
});
8883
}

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/package.manifest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"javascript": [
33
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/formpicker.controller.js",
44
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/settings.controller.js",
5-
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/hubspot.resource.js"
5+
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/hubspot.resource.js",
6+
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/js/hubspot.service.js"
67
],
78
"css": [
89
"~/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/css/styles.css"

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/views/formpickereditor.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
</div>
1212
</div>
1313
<div class="hsOverlayGroup">
14-
<umb-toggle checked="vm.euRegion" show-labels="true" label-on="EU Region" label-off="US Region" on-click="vm.toggleRegion()">
15-
</umb-toggle>
1614
<ul class="hsFormsList">
1715
<li ng-repeat="form in vm.hubspotFormsList | orderBy:'name' | filter:vm.searchTerm" ng-click="model.pickForm(form, vm.euRegion)" class="ng-scope" role="button" tabindex="0">
1816
<a href="" ng-attr-title="form.name">

src/Umbraco.Cms.Integrations.Crm.Hubspot/Configuration/AppSettingsConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ namespace Umbraco.Cms.Integrations.Crm.Hubspot.Configuration
44
public static class AppSettingsConstants
55
{
66
public static string UmbracoCmsIntegrationsCrmHubspotApiKey = "Umbraco.Cms.Integrations.Crm.Hubspot.ApiKey";
7+
8+
public static string UmbracoCmsIntegrationsCrmHubspotRegion = "Umbraco.Cms.Integrations.Crm.Hubspot.Region";
79
}
810
}

src/Umbraco.Cms.Integrations.Crm.Hubspot/Controllers/FormsController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ public async Task<ResponseDto> GetAllOAuth()
160160
[HttpGet]
161161
public HubspotFormPickerSettings CheckConfiguration()
162162
{
163+
if (string.IsNullOrEmpty(_appSettings[AppSettingsConstants.UmbracoCmsIntegrationsCrmHubspotRegion]))
164+
return new HubspotFormPickerSettings();
165+
163166
return
164167
!string.IsNullOrEmpty(_appSettings[AppSettingsConstants.UmbracoCmsIntegrationsCrmHubspotApiKey])
165168
? new HubspotFormPickerSettings { IsValid = true, Type = ConfigurationType.Api}

src/Umbraco.Cms.Integrations.Crm.Hubspot/Editors/FormPickerValueConverter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub
2424
var jObject = JObject.Parse(source.ToString());
2525
var jformId = jObject["id"];
2626
var jportalId = jObject["portalId"];
27-
var jeuRegion = jObject["euRegion"];
2827

2928
if (jformId != null && jportalId != null)
3029
{
3130
var hubspotFormViewModel = new HubspotFormViewModel
3231
{
3332
Id = jformId.Value<string>(),
34-
PortalId = jportalId.Value<string>(),
35-
EuRegion = jeuRegion.Value<bool>()
33+
PortalId = jportalId.Value<string>()
3634
};
3735
return hubspotFormViewModel;
3836
}

src/Umbraco.Cms.Integrations.Crm.Hubspot/Models/ViewModels/HubspotFormViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ public class HubspotFormViewModel
55
public string PortalId { get; set; }
66

77
public string Id { get; set; }
8-
9-
public bool EuRegion { get; set; }
108
}
119
}

src/Umbraco.Cms.Integrations.Crm.Hubspot/Umbraco.Cms.Integrations.Crm.Hubspot.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30+
<None Remove="App_Plugins\UmbracoCms.Integrations\Crm\Hubspot\js\hubspot.service.js" />
3031
<None Remove="App_Plugins\UmbracoCms.Integrations\Crm\Hubspot\js\settings.controller.js" />
3132
<None Remove="App_Plugins\UmbracoCms.Integrations\Crm\Hubspot\Render\HubspotForm.cshtml" />
3233
<None Remove="App_Plugins\UmbracoCms.Integrations\Crm\Hubspot\views\formpickereditor.html" />

0 commit comments

Comments
 (0)