Skip to content

Commit c3f0506

Browse files
committed
PR feedback updates
1 parent 2a7e632 commit c3f0506

File tree

13 files changed

+53
-78
lines changed

13 files changed

+53
-78
lines changed

src/Umbraco.Cms.Integrations.Crm.ActiveCampaign/App_Plugins/UmbracoCms.Integrations/Crm/ActiveCampaign/js/configuration.controller.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
umbracoCmsIntegrationsCrmActiveCampaignResource.checkApiAccess().then(function (response) {
55

6+
if (response.isApiConfigurationValid)
7+
vm.account = response.account;
8+
69
vm.status = response.isApiConfigurationValid
7-
? "Connected. Account name: " + response.account
10+
? "Connected. Account name: "
811
: "Invalid API configuration."
912
});
1013
}

src/Umbraco.Cms.Integrations.Crm.ActiveCampaign/App_Plugins/UmbracoCms.Integrations/Crm/ActiveCampaign/js/configuration.directive.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
vm.isApiConfigurationValid = response.isApiConfigurationValid;
1414
if (response.isApiConfigurationValid) {
1515
if ($scope.model.value) {
16-
loadForm();
16+
getFormDetails($scope.model.value);
1717
}
1818

1919
loadForms();
@@ -23,12 +23,15 @@
2323
}
2424
});
2525

26-
vm.saveForm = function (form) {
27-
$scope.model.value = form;
26+
vm.saveForm = function (formId) {
27+
$scope.model.value = formId;
28+
29+
getFormDetails(formId);
2830
}
2931

3032
vm.removeForm = function () {
3133
$scope.model.value = null;
34+
vm.selectedForm = {};
3235
}
3336

3437
vm.openActiveCampaignFormPickerOverlay = function () {
@@ -41,7 +44,7 @@
4144
selectForm: function (form) {
4245

4346
if (form.id !== undefined) {
44-
vm.saveForm(form);
47+
vm.saveForm(form.id);
4548
}
4649

4750
editorService.close();
@@ -54,26 +57,33 @@
5457
editorService.open(options);
5558
};
5659

57-
function loadForm() {
60+
function getFormDetails(id) {
5861
vm.loading = true;
59-
umbracoCmsIntegrationsCrmActiveCampaignResource.getForm($scope.model.value.id).then(function (response) {
60-
if (response.message !== undefined && response.message.length > 0)
62+
umbracoCmsIntegrationsCrmActiveCampaignResource.getForm(id).then(function (response) {
63+
if (response.message !== null && response.message.length > 0)
6164
vm.status = response.message;
65+
else
66+
vm.selectedForm = response.form;
67+
68+
vm.loading = false;
6269
});
6370
}
6471

6572
function loadForms() {
6673
vm.loading = true;
6774
umbracoCmsIntegrationsCrmActiveCampaignResource.getForms().then(function (response) {
6875
vm.formsList = [];
69-
if (response) {
70-
response.data.forEach(item => {
76+
77+
if (response.forms != null) {
78+
response.forms.forEach(item => {
7179
vm.formsList.push({
7280
id: item.id,
7381
name: item.name
7482
});
7583
});
7684
}
85+
else vm.status = response.message;
86+
7787
vm.loading = false;
7888
});
7989
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div ng-controller="Umbraco.Cms.Integrations.Crm.ActiveCampaign.ConfigurationController as vm">
22
<p>
3-
<b>{{ vm.status }}</b>
3+
{{ vm.status }} <b ng-if="vm.account">{{ vm.account }}</b>
44
</p>
55
</div>

src/Umbraco.Cms.Integrations.Crm.ActiveCampaign/App_Plugins/UmbracoCms.Integrations/Crm/ActiveCampaign/views/formpicker.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<umb-load-indicator ng-if="vm.loading">
33
</umb-load-indicator>
44

5-
<umb-node-preview ng-if="model.value"
6-
name="model.value.name"
5+
<umb-node-preview ng-if="vm.selectedForm"
6+
name="vm.selectedForm.name"
77
allow-remove="true" ,
88
on-remove="vm.removeForm()">
99
</umb-node-preview>

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@
2525
</li>
2626
</ul>
2727
</div>
28-
</umb-box-content>
29-
</umb-box>
30-
<umb-box>
31-
<umb-box-header title="ActiveCampaign - Configuration" description="API Access"></umb-box-header>
32-
<umb-box-content>
33-
<div class="acOverlayGroup">
34-
<api-access-configuration></api-access-configuration>
28+
29+
<div ng-if="vm.status" class="alert alert-warning">
30+
{{ vm.status }}
3531
</div>
3632
</umb-box-content>
3733
</umb-box>

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public FormsController(IOptions<ActiveCampaignSettings> options, IHttpClientFact
2626
}
2727

2828
[HttpGet]
29-
public ApiAccessDto CheckApiAccess() => new ApiAccessDto(_settings.BaseUrl, _settings.ApiKey);
29+
public IActionResult CheckApiAccess() => new JsonResult(new ApiAccessDto(_settings.BaseUrl, _settings.ApiKey));
3030

3131
[HttpGet]
32-
public async Task<ResponseDto<IEnumerable<FormDto>>> GetForms()
32+
public async Task<IActionResult> GetForms()
3333
{
3434
var client = _httpClientFactory.CreateClient(Constants.FormsHttpClient);
3535

@@ -38,26 +38,19 @@ public async Task<ResponseDto<IEnumerable<FormDto>>> GetForms()
3838
var content = await response.Content.ReadAsStringAsync();
3939

4040
if (!response.IsSuccessStatusCode)
41-
return new ResponseDto<IEnumerable<FormDto>>
41+
return new JsonResult(new ResponseDto
4242
{
43-
Data = Enumerable.Empty<FormDto>(),
4443
Message = String.IsNullOrEmpty(content)
4544
? response.StatusCode == System.Net.HttpStatusCode.Forbidden
4645
? Constants.Resources.AuthorizationFailed : Constants.Resources.ApiAccessFailed
4746
: JsonNode.Parse(content)["message"].ToString()
48-
};
49-
50-
return new ResponseDto<IEnumerable<FormDto>>
51-
{
52-
Data = string.IsNullOrEmpty(content)
53-
? Enumerable.Empty<FormDto>()
54-
: JsonNode.Parse(content)["forms"].Deserialize<IEnumerable<FormDto>>(),
55-
Message = String.Empty
56-
};
47+
});
48+
49+
return new JsonResult(JsonSerializer.Deserialize<ResponseDto>(content));
5750
}
5851

5952
[HttpGet]
60-
public async Task<ResponseDto<FormDto>?> GetForm(string id)
53+
public async Task<IActionResult> GetForm(string id)
6154
{
6255
var client = _httpClientFactory.CreateClient(Constants.FormsHttpClient);
6356

@@ -71,21 +64,15 @@ public async Task<ResponseDto<IEnumerable<FormDto>>> GetForms()
7164
var content = await response.Content.ReadAsStringAsync();
7265

7366
if (!response.IsSuccessStatusCode)
74-
return new ResponseDto<FormDto>
67+
return new JsonResult(new ResponseDto
7568
{
7669
Message = String.IsNullOrEmpty(content)
7770
? response.StatusCode == System.Net.HttpStatusCode.Forbidden
7871
? Constants.Resources.AuthorizationFailed : Constants.Resources.ApiAccessFailed
7972
: JsonNode.Parse(content)["message"].ToString()
80-
};
81-
82-
return new ResponseDto<FormDto>
83-
{
84-
Data = string.IsNullOrEmpty(content)
85-
? new FormDto()
86-
: JsonNode.Parse(content)["form"].Deserialize<FormDto>(),
87-
Message = String.Empty
88-
};
73+
});
74+
75+
return new JsonResult(JsonSerializer.Deserialize<ResponseDto>(content));
8976
}
9077

9178
}

src/Umbraco.Cms.Integrations.Crm.ActiveCampaign/Editors/ActiveCampaignFormPickerValueConverter.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub
2828
{
2929
if (source == null) return null;
3030

31-
var node = JsonNode.Parse(source.ToString());
32-
3331
return new FormViewModel
3432
{
35-
Id = node["id"].ToString(),
36-
Name = node["name"].ToString(),
33+
Id = source.ToString(),
3734
Account = _settings.BaseUrl.Substring(0, _settings.BaseUrl.IndexOf(".")).Replace("https://", string.Empty)
3835
};
3936
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
using Newtonsoft.Json;
2-
1+

32
namespace Umbraco.Cms.Integrations.Crm.ActiveCampaign.Models.Dtos
43
{
54
public class ApiAccessDto
65
{
7-
private string _baseUrl { get; set; }
6+
private readonly string _baseUrl;
87

9-
private string _apiKey { get; set; }
8+
private readonly string _apiKey;
109

1110
public ApiAccessDto(string baseUrl, string apiKey)
1211
{
1312
_baseUrl = baseUrl;
1413
_apiKey = apiKey;
1514
}
1615

17-
[JsonProperty("account")]
1816
public string Account => IsApiConfigurationValid
1917
? _baseUrl.Substring(0, _baseUrl.IndexOf(".")).Replace("https://", string.Empty)
2018
: string.Empty;
2119

22-
[JsonProperty("isApiConfigurationValid")]
2320
public bool IsApiConfigurationValid => !string.IsNullOrEmpty(_baseUrl) && !string.IsNullOrEmpty(_apiKey);
2421
}
2522
}

src/Umbraco.Cms.Integrations.Crm.ActiveCampaign/Models/Dtos/FormDto.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
using Newtonsoft.Json;
2-
using System.Text.Json.Serialization;
1+
using System.Text.Json.Serialization;
32

43
namespace Umbraco.Cms.Integrations.Crm.ActiveCampaign.Models.Dtos
54
{
65
public class FormDto
76
{
8-
[JsonProperty("id")]
97
[JsonPropertyName("id")]
108
public string Id { get; set; }
119

12-
[JsonProperty("name")]
1310
[JsonPropertyName("name")]
1411
public string Name { get; set; }
1512
}

0 commit comments

Comments
 (0)