|
1 |
| -import { html, customElement, property, css, when } from '@umbraco-cms/backoffice/external/lit'; |
| 1 | +import { html, customElement, property, css, when, state, map } from '@umbraco-cms/backoffice/external/lit'; |
2 | 2 | import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry';
|
3 | 3 | import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
|
| 4 | +import { HUBSPOT_CONTEXT_TOKEN } from '@umbraco-integrations/hubspot/context'; |
| 5 | +import { Property } from '@umbraco-integrations/hubspot/generated'; |
4 | 6 |
|
5 | 7 | const elementName = "hubspot-mapping-property-editor";
|
6 | 8 |
|
7 | 9 | @customElement(elementName)
|
8 | 10 | export class HubspotMappingPropertyUiElement extends UmbLitElement implements UmbPropertyEditorUiElement {
|
9 |
| - render() { |
10 |
| - return html` |
11 |
| - <div> |
12 |
| - <uui-select></uui-select> |
13 |
| - </div> |
14 |
| - `; |
| 11 | + #hubspotContext!: typeof HUBSPOT_CONTEXT_TOKEN.TYPE; |
| 12 | + |
| 13 | + @property({ type: String }) |
| 14 | + public value = ""; |
| 15 | + |
| 16 | + @state() |
| 17 | + public hubspotMappingArray : Array<string> = []; |
| 18 | + |
| 19 | + @state() |
| 20 | + private selectedContactField: string = ""; |
| 21 | + |
| 22 | + @state() |
| 23 | + private selectedFormField: string = ""; |
| 24 | + |
| 25 | + @state() |
| 26 | + private hubspotFields: Array<Property> | undefined = []; |
| 27 | + |
| 28 | + @state() |
| 29 | + private formdFields: Array<string> | undefined = []; |
| 30 | + |
| 31 | + constructor() { |
| 32 | + super(); |
| 33 | + this.consumeContext(HUBSPOT_CONTEXT_TOKEN, (context) => { |
| 34 | + if (!context) return; |
| 35 | + this.#hubspotContext = context; |
| 36 | + }); |
| 37 | + } |
| 38 | + |
| 39 | + async connectedCallback() { |
| 40 | + super.connectedCallback(); |
| 41 | + |
| 42 | + if(this.value){ |
| 43 | + this.hubspotMappingArray = JSON.parse(this.value); |
15 | 44 | }
|
| 45 | + |
| 46 | + await this.#getHubspotFields(); |
| 47 | + //await this.#getFormFields(); |
| 48 | + } |
| 49 | + |
| 50 | + async #getHubspotFields(){ |
| 51 | + var result = await this.#hubspotContext.getAll(); |
| 52 | + if (!result) return; |
| 53 | + |
| 54 | + this.hubspotFields = result.data; |
| 55 | + } |
| 56 | + |
| 57 | + // async #getFormFields(){ |
| 58 | + // var formId = window.location.pathname.split("/")[7]; //Get the formid based on current url. |
| 59 | + // var result = await this.#activeCampaignContext.getFormFields(formId); |
| 60 | + |
| 61 | + // if (!result) return; |
| 62 | + |
| 63 | + // this.formdFields = result.data; |
| 64 | + // } |
| 65 | + |
| 66 | + #onDeleteClick(idx: number){ |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + isDisabled(){ |
| 71 | + return false; |
| 72 | + } |
| 73 | + |
| 74 | + #addButtonClick(){ |
| 75 | + this.hubspotMappingArray.push(""); |
| 76 | + } |
| 77 | + |
| 78 | + render() { |
| 79 | + return html` |
| 80 | + <div>Umbraco forms is configured.</div> |
| 81 | +
|
| 82 | + <div> |
| 83 | + ${this.hubspotMappingArray.length > 0 |
| 84 | + ? html` |
| 85 | + <table> |
| 86 | + <thead> |
| 87 | + <tr> |
| 88 | + <th>Form Field</th> |
| 89 | + <th>Hubspot Field</th> |
| 90 | + <th></th> |
| 91 | + </tr> |
| 92 | + </thead> |
| 93 | + <tbody> |
| 94 | + ${map(this.hubspotMappingArray, (mapping, idx) => html` |
| 95 | + <tr> |
| 96 | + <td> |
| 97 | + <uui-select></uui-select> |
| 98 | + </td> |
| 99 | + <td> |
| 100 | + <uui-select></uui-select> |
| 101 | + </td> |
| 102 | + <td> |
| 103 | + <uui-button |
| 104 | + label=${this.localize.term("formProviderWorkflows_delete")} |
| 105 | + look="secondary" |
| 106 | + color="default" |
| 107 | + @click=${() => this.#onDeleteClick(idx)}> |
| 108 | + <uui-icon name="delete"></uui-icon> |
| 109 | + </uui-button> |
| 110 | + </td> |
| 111 | + </tr> |
| 112 | + `)} |
| 113 | + </tbody> |
| 114 | + </table> |
| 115 | + ` |
| 116 | + : html``} |
| 117 | + </div> |
| 118 | +
|
| 119 | + <div class="activecampaign-wf-button"> |
| 120 | + <uui-button look="primary" ?disabled=${this.isDisabled()} label="Add mapping" @click=${this.#addButtonClick}></uui-button> |
| 121 | + </div> |
| 122 | +
|
| 123 | + <div class="activecampaign-wf-button"> |
| 124 | + <uui-button look="primary" ?disabled=${this.isDisabled()} label="De-authorize from Hubspot" @click=${this.#addButtonClick}></uui-button> |
| 125 | + </div> |
| 126 | + `; |
16 | 127 | }
|
| 128 | +} |
17 | 129 |
|
18 | 130 | export default HubspotMappingPropertyUiElement;
|
19 | 131 |
|
|
0 commit comments