diff --git a/_inc/jetpack-jitm.js b/_inc/jetpack-jitm.js index 17017245ef3c4..832b2f5b5feb1 100644 --- a/_inc/jetpack-jitm.js +++ b/_inc/jetpack-jitm.js @@ -62,12 +62,14 @@ jQuery( document ).ready( function( $ ) { ctaClasses += ' is-primary'; } + var ajaxAction = envelope.CTA.ajax_action; + html += '
'; html += '' + + '" ' + + ( ajaxAction ? 'data-ajax-action="' + ajaxAction + '"' : '' ) + + '>' + envelope.CTA.message + ''; html += '
'; @@ -176,6 +180,24 @@ jQuery( document ).ready( function( $ ) { }, 2000 ); } ); } ); + + // Handle CTA ajax actions. + $template.find( '.jitm-button[data-ajax-action]' ).click( function( e ) { + e.preventDefault(); + var button = $( this ); + button.attr( 'disabled', true ); + $.post( window.ajaxurl, { + action: button.data( 'ajax-action' ), + _nonce: $el.data( 'ajax-nonce' ), + } ) + .done( function() { + $template.fadeOut( 'slow' ); + } ) + .fail( function() { + button.attr( 'disabled', false ); + } ); + return false; + } ); }; var reFetch = function() { diff --git a/bin/phpcs-whitelist.js b/bin/phpcs-whitelist.js index d6e7a27f6120c..ebcff2e67e599 100644 --- a/bin/phpcs-whitelist.js +++ b/bin/phpcs-whitelist.js @@ -40,6 +40,7 @@ module.exports = [ 'modules/widgets/contact-info.php', 'modules/widgets/social-icons.php', 'modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php', + 'modules/wpcom-tos/wpcom-tos.php', 'packages', 'tests/e2e/plugins/e2e-plan-data-interceptor.php', ]; diff --git a/modules/module-extras.php b/modules/module-extras.php index 562c9c7b9690d..2828213a61d3a 100644 --- a/modules/module-extras.php +++ b/modules/module-extras.php @@ -46,6 +46,7 @@ 'simple-payments/simple-payments.php', 'woocommerce-analytics/wp-woocommerce-analytics.php', 'wpcom-block-editor/class-jetpack-wpcom-block-editor.php', + 'wpcom-tos/wpcom-tos.php', ); // Add connected features to our existing list if the site is currently connected. diff --git a/modules/wpcom-tos/wpcom-tos.php b/modules/wpcom-tos/wpcom-tos.php new file mode 100644 index 0000000000000..6de6ae32d0229 --- /dev/null +++ b/modules/wpcom-tos/wpcom-tos.php @@ -0,0 +1,41 @@ + 'POST', + ), + array( + 'action' => 'accept_tos', + ) + ); + + if ( is_wp_error( $response ) ) { + wp_send_json_error( array( 'message' => __( 'Could not accept the Terms of Service. Please try again later.', 'jetpack' ) ) ); + wp_die(); + } + + wp_send_json_success( $response ); + + wp_die(); +} + +add_action( 'wp_ajax_jetpack_accept_tos', __NAMESPACE__ . '\accept_tos' ); diff --git a/packages/jitm/src/class-jitm.php b/packages/jitm/src/class-jitm.php index 8a66b5e087422..c437528b3f899 100644 --- a/packages/jitm/src/class-jitm.php +++ b/packages/jitm/src/class-jitm.php @@ -344,6 +344,7 @@ public function ajax_message() { ?>