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
integration-component.js
81 lines
| 1 | import BaseActionComponent from "./base-action-component"; |
| 2 | |
| 3 | const { getFormFieldsBlocks } = JetFBActions; |
| 4 | |
| 5 | export default class IntegrationComponent extends BaseActionComponent { |
| 6 | |
| 7 | constructor( props ) { |
| 8 | super( props ); |
| 9 | |
| 10 | this.validateAPIKey = this.validateAPIKey.bind( this ); |
| 11 | this.getApiData = this.getApiData.bind( this ); |
| 12 | this.getLists = this.getLists.bind( this ); |
| 13 | |
| 14 | this.formFieldsList = getFormFieldsBlocks( [], '--' ); |
| 15 | |
| 16 | this.state = { |
| 17 | className: [ this.getclassNameValidateButton() ], |
| 18 | }; |
| 19 | } |
| 20 | |
| 21 | validateAPIKey( customApiKey = false ) { |
| 22 | this.setState( { className: [ 'loading' ] } ); |
| 23 | |
| 24 | if ( customApiKey && 'string' === typeof customApiKey ) { |
| 25 | this.getApiData( customApiKey ); |
| 26 | return; |
| 27 | } |
| 28 | const settings = this.props.settings; |
| 29 | this.getApiData( settings.api_key ); |
| 30 | } |
| 31 | |
| 32 | getApiData( apiKey ) { |
| 33 | const self = this; |
| 34 | |
| 35 | if ( ! apiKey ) { |
| 36 | self.onChangeSetting( null, 'isValidAPI' ); |
| 37 | self.setState( { className: [] } ); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | jQuery.ajax( { |
| 42 | url: ajaxurl, |
| 43 | type: 'POST', |
| 44 | data: { |
| 45 | 'action': this.props.source.action, |
| 46 | 'api_key': apiKey |
| 47 | }, |
| 48 | success: function ( response ) { |
| 49 | if ( response.success ) { |
| 50 | self.onChangeSettingObj( { |
| 51 | isValidAPI: true, |
| 52 | data: response.data |
| 53 | } ); |
| 54 | |
| 55 | self.setState( { className: [ 'is-valid' ] } ); |
| 56 | } |
| 57 | else { |
| 58 | self.onChangeSettingObj( { isValidAPI: false } ); |
| 59 | self.setState( { className: [ 'is-invalid' ] } ); |
| 60 | } |
| 61 | }, |
| 62 | error: function () { |
| 63 | self.onChangeSettingObj( { isValidAPI: false } ); |
| 64 | self.setState( { className: [ 'is-invalid' ] } ); |
| 65 | } |
| 66 | } ); |
| 67 | |
| 68 | |
| 69 | } |
| 70 | |
| 71 | getclassNameValidateButton() { |
| 72 | const settings = this.props.settings; |
| 73 | |
| 74 | if ( true === settings.isValidAPI ) { |
| 75 | return 'is-valid'; |
| 76 | } |
| 77 | else if ( false === settings.isValidAPI ) { |
| 78 | return 'is-invalid'; |
| 79 | } |
| 80 | } |
| 81 | } |