| 1 |
import { useEffect, useContext } from 'react'; |
| 2 |
import { OnboardingContext } from '../context/context'; |
| 3 |
|
| 4 |
export default function Connect( props ) { |
| 5 |
const { state, updateState, getStateObjectToUpdate } = useContext( OnboardingContext ); |
| 6 |
|
| 7 |
const connectSuccessCallback = ( data ) => { |
| 8 |
const stateToUpdate = getStateObjectToUpdate( state, 'steps', 'account', 'completed' ); |
| 9 |
|
| 10 |
elementorCommon.config.library_connect.is_connected = true; |
| 11 |
elementorCommon.config.library_connect.current_access_level = data.kits_access_level || data.access_level || 0; |
| 12 |
|
| 13 |
stateToUpdate.isLibraryConnected = true; |
| 14 |
|
| 15 |
updateState( stateToUpdate ); |
| 16 |
}; |
| 17 |
|
| 18 |
useEffect( () => { |
| 19 |
jQuery( props.buttonRef.current ).elementorConnect( { |
| 20 |
success: ( data ) => props.successCallback ? props.successCallback( data ) : connectSuccessCallback( data ), |
| 21 |
error: () => { |
| 22 |
if ( props.errorCallback ) { |
| 23 |
props.errorCallback(); |
| 24 |
} |
| 25 |
}, |
| 26 |
popup: { |
| 27 |
width: 726, |
| 28 |
height: 534, |
| 29 |
}, |
| 30 |
} ); |
| 31 |
}, [] ); |
| 32 |
|
| 33 |
return null; |
| 34 |
} |
| 35 |
|
| 36 |
Connect.propTypes = { |
| 37 |
buttonRef: PropTypes.object.isRequired, |
| 38 |
successCallback: PropTypes.func, |
| 39 |
errorCallback: PropTypes.func, |
| 40 |
}; |
| 41 |
|