@@ -12,8 +12,11 @@ const elementName = "custom-mapping-property-editor";
1212export class CustomMappingPropertyUiElement extends UmbLitElement implements UmbPropertyEditorUiElement {
1313 #activeCampaignContext! : typeof ACTIVECAMPAIGN_CONTEXT_TOKEN . TYPE ;
1414
15- @property ( { attribute : false } )
16- public customMapping : Array < CustomMappingValue > = [ ] ;
15+ @property ( { type : String } )
16+ public value = "" ;
17+
18+ @state ( )
19+ public customMappingArray : Array < CustomMappingValue > = [ ] ;
1720
1821 @state ( )
1922 private selectedCustomField : string = "" ;
@@ -38,6 +41,10 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
3841 async connectedCallback ( ) {
3942 super . connectedCallback ( ) ;
4043
44+ if ( this . value ) {
45+ this . customMappingArray = JSON . parse ( this . value ) ;
46+ }
47+
4148 await this . #getCustomFields( ) ;
4249 await this . #getFormFields( ) ;
4350 }
@@ -50,7 +57,8 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
5057 }
5158
5259 async #getFormFields( ) {
53- var result = await this . #activeCampaignContext. getFormFields ( "f595361a-37f9-44da-80ca-6a22d699d923" ) ;
60+ var formId = window . location . pathname . split ( "/" ) [ 7 ] ; //Get the formid based on current url.
61+ var result = await this . #activeCampaignContext. getFormFields ( formId ) ;
5462
5563 if ( ! result ) return ;
5664
@@ -66,29 +74,38 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
6674 }
6775
6876 #addButtonClick( ) {
69- this . customMapping . push ( {
70- customField : this . selectedCustomField ,
77+ this . customMappingArray . push ( {
78+ customField : {
79+ id : this . selectedCustomField ,
80+ title : this . getSelectedCustomFieldCaption ( ) !
81+ } ,
7182 formField : {
7283 id : this . selectedFormField ,
73- value : this . getSelectedFieldCaption ( ) !
84+ value : this . getSelectedFormFieldCaption ( ) !
7485 }
7586 } ) ;
7687
88+ this . value = JSON . stringify ( this . customMappingArray ) ;
7789 this . requestUpdate ( ) ;
7890 this . dispatchEvent ( new CustomEvent ( 'property-value-change' ) ) ;
7991 }
8092
81- getSelectedFieldCaption ( ) {
93+ getSelectedFormFieldCaption ( ) {
8294 return this . formdFields ?. find ( f => f . id == this . selectedFormField ) ?. caption ;
8395 }
8496
97+ getSelectedCustomFieldCaption ( ) {
98+ return this . customFields ?. find ( f => f . id == this . selectedCustomField ) ?. title ;
99+ }
100+
85101 isDisabled ( ) {
86102 return ! this . selectedCustomField || ! this . selectedFormField ;
87103 }
88104
89105 #onDeleteClick( idx : number ) {
90- this . customMapping . splice ( idx , 1 ) ;
106+ this . customMappingArray . splice ( idx , 1 ) ;
91107
108+ this . value = JSON . stringify ( this . customMappingArray ) ;
92109 this . requestUpdate ( ) ;
93110 this . dispatchEvent ( new CustomEvent ( 'property-value-change' ) ) ;
94111 }
@@ -97,7 +114,7 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
97114 return html `
98115 <div>
99116 <uui- select
100- placeholder= "Select contact field"
117+ placeholder= ${ this . localize . term ( "formProviderWorkflows_SelectCustomField" ) }
101118 @change = ${ ( e : UUISelectEvent ) => this . #onCustomSelectChange( e ) }
102119 .options = ${
103120 this . customFields ?. map ( ( ft ) => ( {
@@ -106,7 +123,7 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
106123 selected : ft . id === this . selectedCustomField ,
107124 } ) ) ?? [ ] } > </ uui- select>
108125 <uui- select
109- placeholder= "Select form field"
126+ placeholder= ${ this . localize . term ( "formProviderWorkflows_SelectFormField" ) }
110127 @change = ${ ( e : UUISelectEvent ) => this . #onFormFieldSelectChange( e ) }
111128 .options = ${
112129 this . formdFields ?. map ( ( ft ) => ( {
@@ -117,36 +134,40 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
117134 </ div>
118135
119136 <div class= "activecampaign-wf-button" >
120- <uui- butto n look= "primary" ?dis abled= ${ this . isDisabled ( ) } label= "Add mapping" @click = ${ this . #addButtonClick} > </ uui- butto n>
137+ <uui- butto n look= "primary" ?dis abled= ${ this . isDisabled ( ) } label= ${ this . localize . term ( "formProviderWorkflows_AddMapping" ) } @click = ${ this . #addButtonClick} > </ uui- butto n>
121138 </ div>
122139
123140 <div class= "activecampaign-wf-table" >
124- <table>
125- <thead>
126- <tr>
127- <th> Custom Field </ th>
128- <th> Form Field </ th>
129- <th> </ th>
130- </ tr>
131- </ thead>
132- <tbody>
133- ${ map ( this . customMapping , ( mapping , idx ) => html `
134- <tr>
135- <td> ${ mapping . customField } </ td>
136- <td> ${ mapping . formField ?. value } </ td>
137- <td>
138- <uui- butto n
139- label= ${ this . localize . term ( "formProviderWorkflows_delete" ) }
140- look= "secondary"
141- color = "default"
142- @click = ${ ( ) => this . #onDeleteClick( idx ) } >
143- <uui- icon name= "delete" > </ uui- icon>
144- </ uui- butto n>
145- </ td>
146- </ tr>
147- ` ) }
148- </ tbody>
149- </ table>
141+ ${ this . customMappingArray . length > 0
142+ ? html `
143+ <table>
144+ <thead>
145+ <tr>
146+ <th> ${ this . localize . term ( "formProviderWorkflows_CustomField" ) } </ th>
147+ <th> ${ this . localize . term ( "formProviderWorkflows_FormField" ) } </ th>
148+ <th> </ th>
149+ </ tr>
150+ </ thead>
151+ <tbody>
152+ ${ map ( this . customMappingArray , ( mapping , idx ) => html `
153+ <tr>
154+ <td> ${ mapping . customField ?. title } </ td>
155+ <td> ${ mapping . formField ?. value } </ td>
156+ <td>
157+ <uui- butto n
158+ label= ${ this . localize . term ( "formProviderWorkflows_delete" ) }
159+ look= "secondary"
160+ color = "default"
161+ @click = ${ ( ) => this . #onDeleteClick( idx ) } >
162+ <uui- icon name= "delete" > </ uui- icon>
163+ </ uui- butto n>
164+ </ td>
165+ </ tr>
166+ ` ) }
167+ </ tbody>
168+ </ table>
169+ `
170+ : html `` }
150171 </ div>
151172 ` ;
152173 }
0 commit comments