call.hook
2 years ago
call.webhook
2 years ago
getresponse
2 years ago
insert.post
2 years ago
mailchimp
2 years ago
redirect.to.page
2 years ago
register.user
2 years ago
save.record
2 years ago
send.email
2 years ago
update.user
2 years ago
base-action-component.js
2 years ago
integration-component.js
2 years ago
base-action-component.js
78 lines
| 1 | export default class BaseActionComponent extends wp.element.Component { |
| 2 | |
| 3 | addPlaceholderForSelect( array, label = '--' ) { |
| 4 | return [ |
| 5 | { label }, |
| 6 | ...array, |
| 7 | ]; |
| 8 | } |
| 9 | |
| 10 | onChangeSetting( value, key ) { |
| 11 | this.props.onChange( { |
| 12 | ...this.props.settings, |
| 13 | [ key ]: value, |
| 14 | } ); |
| 15 | }; |
| 16 | |
| 17 | onChangeSettingObj( value ) { |
| 18 | this.props.onChange( { |
| 19 | ...this.props.settings, |
| 20 | ...value, |
| 21 | } ); |
| 22 | }; |
| 23 | |
| 24 | getFieldDefault( name ) { |
| 25 | const source = 'fields_map'; |
| 26 | |
| 27 | return this.getFieldByName( |
| 28 | { name, source }, |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | getFieldMeta( name ) { |
| 33 | const source = 'meta_fields_map'; |
| 34 | |
| 35 | return this.getFieldByName( |
| 36 | { name, source }, |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | getFieldByName( { source, name } ) { |
| 41 | const settings = this.props.settings; |
| 42 | |
| 43 | if ( typeof settings[ source ] !== 'undefined' && typeof settings[ source ][ name ] !== 'undefined' ) { |
| 44 | return settings[ source ][ name ]; |
| 45 | } |
| 46 | return ''; |
| 47 | } |
| 48 | |
| 49 | onChangeFieldMap( value, nameField ) { |
| 50 | const source = 'fields_map'; |
| 51 | |
| 52 | this.changeFieldsMap( |
| 53 | { value, nameField, source }, |
| 54 | ); |
| 55 | }; |
| 56 | |
| 57 | onChangeMetaFieldMap( value, nameField ) { |
| 58 | const source = 'meta_fields_map'; |
| 59 | |
| 60 | this.changeFieldsMap( |
| 61 | { value, nameField, source }, |
| 62 | ); |
| 63 | }; |
| 64 | |
| 65 | changeFieldsMap( { source, nameField, value } ) { |
| 66 | const fieldsMap = Object.assign( |
| 67 | {}, |
| 68 | this.props.settings[ source ], |
| 69 | { [ nameField ]: value }, |
| 70 | ); |
| 71 | |
| 72 | this.props.onChange( { |
| 73 | ...this.props.settings, |
| 74 | [ source ]: fieldsMap, |
| 75 | } ); |
| 76 | } |
| 77 | |
| 78 | } |