Skip to content

Commit 9d47192

Browse files
committed
V14: Integrations (HubSpot/Forms)
- update UI implementation
1 parent 3e8c892 commit 9d47192

File tree

10 files changed

+347
-65
lines changed

10 files changed

+347
-65
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Umbraco.Cms.Web.Common.Authorization;
9+
using Umbraco.Cms.Web.Common.Routing;
10+
using Umbraco.Forms.Core.Services;
11+
12+
namespace Umbraco.Forms.Integrations.Crm.Hubspot.Api.Management.Controllers.Forms
13+
{
14+
[BackOfficeRoute($"{Constants.ManagementApi.RootPath}/v{{version:apiVersion}}/forms")]
15+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.FormGroupName)]
16+
[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)]
17+
public class FormControllerBase : HubspotControllerBase
18+
{
19+
protected readonly IFormService FormService;
20+
21+
public FormControllerBase(IFormService formService)
22+
{
23+
FormService = formService;
24+
}
25+
}
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Umbraco.Forms.Core.Models;
9+
using Umbraco.Forms.Core.Services;
10+
11+
namespace Umbraco.Forms.Integrations.Crm.Hubspot.Api.Management.Controllers.Forms
12+
{
13+
public class GetFormFieldsController : FormControllerBase
14+
{
15+
public GetFormFieldsController(IFormService formService) : base(formService)
16+
{
17+
}
18+
19+
[HttpGet("fields")]
20+
[ProducesResponseType(typeof(List<Field>), StatusCodes.Status200OK)]
21+
public IActionResult GetFormFields(string formId)
22+
{
23+
List<Field> formFields = new List<Field>();
24+
var result = FormService.Get(new Guid(formId));
25+
if (result != null)
26+
{
27+
formFields = result.AllFields;
28+
}
29+
return Ok(formFields);
30+
}
31+
}
32+
}

src/Umbraco.Forms.Integrations.Crm.Hubspot/Client/generated/services.gen.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import type { CancelablePromise } from './core/CancelablePromise';
44
import { OpenAPI } from './core/OpenAPI';
55
import { request as __request } from './core/request';
6-
import type { IsAuthorizationConfiguredResponse, GetAuthenticationUrlResponse, AuthorizeData, AuthorizeResponse, DeauthorizeResponse, GetAllResponse } from './types.gen';
6+
import type { IsAuthorizationConfiguredResponse, GetAuthenticationUrlResponse, AuthorizeData, AuthorizeResponse, DeauthorizeResponse, GetAllResponse, GetFormFieldsData, GetFormFieldsResponse } from './types.gen';
77

88
export class ContactsService {
99
/**
@@ -65,4 +65,23 @@ export class ContactsService {
6565
});
6666
}
6767

68+
}
69+
70+
export class FormsService {
71+
/**
72+
* @param data The data for the request.
73+
* @param data.formId
74+
* @returns unknown OK
75+
* @throws ApiError
76+
*/
77+
public static getFormFields(data: GetFormFieldsData = {}): CancelablePromise<GetFormFieldsResponse> {
78+
return __request(OpenAPI, {
79+
method: 'GET',
80+
url: '/umbraco/hubspot/management/api/v1/forms/fields',
81+
query: {
82+
formId: data.formId
83+
}
84+
});
85+
}
86+
6887
}

src/Umbraco.Forms.Integrations.Crm.Hubspot/Client/generated/types.gen.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export type AggregateException = {
1414
readonly message: string;
1515
};
1616

17+
export type AllowedUploadType = {
18+
type: string;
19+
name: string;
20+
checked: string;
21+
};
22+
1723
export type Assembly = {
1824
readonly definedTypes: Array<(TypeInfo)>;
1925
readonly exportedTypes: Array<(Type)>;
@@ -161,6 +167,33 @@ export type Exception = {
161167
readonly stackTrace?: string | null;
162168
};
163169

170+
export type Field = {
171+
caption: string;
172+
tooltip?: string | null;
173+
/**
174+
* @deprecated
175+
*/
176+
placeholder?: string | null;
177+
cssClass?: string | null;
178+
alias: string;
179+
id: string;
180+
fieldTypeId: string;
181+
prevalueSourceId: string;
182+
dataSourceFieldKey?: string | null;
183+
containsSensitiveData: boolean;
184+
mandatory: boolean;
185+
regex?: string | null;
186+
requiredErrorMessage?: string | null;
187+
invalidErrorMessage?: string | null;
188+
condition?: FieldCondition | null;
189+
settings: {
190+
[key: string]: (string);
191+
};
192+
preValues: Array<(FieldPrevalue)>;
193+
allowedUploadTypes?: Array<(AllowedUploadType)> | null;
194+
allowMultipleFileUploads: boolean;
195+
};
196+
164197
export enum FieldAttributes {
165198
PRIVATE_SCOPE = 'PrivateScope',
166199
PRIVATE = 'Private',
@@ -183,6 +216,50 @@ export enum FieldAttributes {
183216
RESERVED_MASK = 'ReservedMask'
184217
}
185218

219+
export type FieldCondition = {
220+
id: string;
221+
enabled: boolean;
222+
actionType: FieldConditionActionType;
223+
logicType: FieldConditionLogicType;
224+
rules: Array<(FieldConditionRule)>;
225+
};
226+
227+
export enum FieldConditionActionType {
228+
SHOW = 'Show',
229+
HIDE = 'Hide'
230+
}
231+
232+
export enum FieldConditionLogicType {
233+
ALL = 'All',
234+
ANY = 'Any'
235+
}
236+
237+
export type FieldConditionRule = {
238+
id: string;
239+
field: string;
240+
operator: FieldConditionRuleOperator;
241+
value: string;
242+
};
243+
244+
export enum FieldConditionRuleOperator {
245+
IS = 'Is',
246+
IS_NOT = 'IsNot',
247+
GREATER_THEN = 'GreaterThen',
248+
LESS_THEN = 'LessThen',
249+
CONTAINS = 'Contains',
250+
CONTAINS_IGNORE_CASE = 'ContainsIgnoreCase',
251+
STARTS_WITH = 'StartsWith',
252+
STARTS_WITH_IGNORE_CASE = 'StartsWithIgnoreCase',
253+
ENDS_WITH = 'EndsWith',
254+
ENDS_WITH_IGNORE_CASE = 'EndsWithIgnoreCase',
255+
NOT_CONTAINS = 'NotContains',
256+
NOT_CONTAINS_IGNORE_CASE = 'NotContainsIgnoreCase',
257+
NOT_STARTS_WITH = 'NotStartsWith',
258+
NOT_STARTS_WITH_IGNORE_CASE = 'NotStartsWithIgnoreCase',
259+
NOT_ENDS_WITH = 'NotEndsWith',
260+
NOT_ENDS_WITH_IGNORE_CASE = 'NotEndsWithIgnoreCase'
261+
}
262+
186263
export type FieldInfo = {
187264
readonly name: string;
188265
readonly declaringType?: Type | null;
@@ -215,6 +292,11 @@ export type FieldInfo = {
215292
readonly fieldHandle: RuntimeFieldHandle;
216293
};
217294

295+
export type FieldPrevalue = {
296+
value: string;
297+
caption?: string | null;
298+
};
299+
218300
export enum GenericParameterAttributes {
219301
NONE = 'None',
220302
COVARIANT = 'Covariant',
@@ -745,6 +827,12 @@ export type DeauthorizeResponse = AuthorizationResult;
745827

746828
export type GetAllResponse = Array<(Property)>;
747829

830+
export type GetFormFieldsData = {
831+
formId?: string;
832+
};
833+
834+
export type GetFormFieldsResponse = Array<(Field)>;
835+
748836
export type $OpenApiTs = {
749837
'/umbraco/hubspot/management/api/v1/contacts/auth/configured': {
750838
get: {
@@ -797,4 +885,15 @@ export type $OpenApiTs = {
797885
};
798886
};
799887
};
888+
'/umbraco/hubspot/management/api/v1/forms/fields': {
889+
get: {
890+
req: GetFormFieldsData;
891+
res: {
892+
/**
893+
* OK
894+
*/
895+
200: Array<(Field)>;
896+
};
897+
};
898+
};
800899
};

src/Umbraco.Forms.Integrations.Crm.Hubspot/Client/src/context/hubspot.context.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import { UmbContextToken } from "@umbraco-cms/backoffice/context-api";
33
import type { UmbControllerHost } from "@umbraco-cms/backoffice/controller-api";
44
import { HubspotRepository } from "../repository/hubspot.repository";
55
import { type AuthorizeData } from "@umbraco-integrations/hubspot/generated";
6+
import { UmbObjectState } from "@umbraco-cms/backoffice/observable-api";
67

78
export class HubspotContext extends UmbControllerBase{
89
#repository: HubspotRepository;
910

11+
#settingsModel = new UmbObjectState<string | undefined>(undefined);
12+
settingsModel = this.#settingsModel.asObservable();
13+
1014
constructor(host: UmbControllerHost) {
1115
super(host);
1216

@@ -19,15 +23,16 @@ export class HubspotContext extends UmbControllerBase{
1923
}
2024

2125
async isAuthorizationConfigured() {
22-
return await this.#repository.isAuthorizationConfigured();
26+
const { data } = await this.#repository.isAuthorizationConfigured();
27+
this.#settingsModel.setValue(data);
2328
}
2429

2530
async getAuthenticationUrl() {
2631
return await this.#repository.getAuthenticationUrl();
2732
}
2833

29-
async authorize(authData: AuthorizeData) {
30-
return await this.#repository.authorize(authData);
34+
async authorize(code: string) {
35+
return await this.#repository.authorize(code);
3136
}
3237

3338
async deauthorize() {
@@ -37,6 +42,10 @@ export class HubspotContext extends UmbControllerBase{
3742
async getAll() {
3843
return await this.#repository.getAll();
3944
}
45+
46+
async getFormFields(formId : string) {
47+
return await this.#repository.getFormFields(formId);
48+
}
4049
}
4150

4251
export default HubspotContext;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface HubspotMappingValue {
2+
formField: string;
3+
hubspotField: string;
4+
appendValue: boolean;
5+
}

0 commit comments

Comments
 (0)