mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Add status message to feature availability reload.
This commit is contained in:
parent
723e2cf275
commit
8e71665ec4
4 changed files with 42 additions and 6 deletions
|
@ -25,3 +25,17 @@
|
|||
.ppcp-button-apm {
|
||||
@include apm-button.button;
|
||||
}
|
||||
|
||||
.ppcp-status-text {
|
||||
padding-top: 4px;
|
||||
|
||||
.error {
|
||||
color: red;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.success {
|
||||
color: green;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -355,11 +355,25 @@ document.addEventListener(
|
|||
}
|
||||
|
||||
// Logic to handle the "Check available features" button.
|
||||
((props) => {
|
||||
const $btn = jQuery(props.button);
|
||||
(($, props, anchor) => {
|
||||
const $btn = $(props.button);
|
||||
|
||||
const printStatus = (message, showSpinner) => {
|
||||
const html = message + (showSpinner ? '<span class="spinner is-active" style="float: none;"></span>' : '');
|
||||
$btn.siblings('.ppcp-status-text').html(html);
|
||||
};
|
||||
|
||||
// If the reload comes from a successful refresh.
|
||||
if (typeof URLSearchParams === 'function' && (new URLSearchParams(window.location.search)).get('feature-refreshed')) {
|
||||
printStatus('<span class="success">✔️ ' + props.messages.success + '</span>');
|
||||
$('html, body').animate({
|
||||
scrollTop: $(anchor).offset().top
|
||||
}, 500);
|
||||
}
|
||||
|
||||
$btn.click(async () => {
|
||||
$btn.prop('disabled', true);
|
||||
printStatus(props.messages.waiting, true);
|
||||
|
||||
const response = await fetch(
|
||||
props.endpoint,
|
||||
|
@ -380,14 +394,18 @@ document.addEventListener(
|
|||
const responseData = await response.json();
|
||||
|
||||
if (!responseData.success) {
|
||||
alert(responseData.data.message);
|
||||
printStatus(responseData.data.message);
|
||||
$btn.prop('disabled', false);
|
||||
} else {
|
||||
window.location.reload();
|
||||
window.location.href += (window.location.href.indexOf('?') > -1 ? '&' : '?') + "feature-refreshed=1#";
|
||||
}
|
||||
});
|
||||
|
||||
})(PayPalCommerceGatewaySettings.ajax.refresh_feature_status);
|
||||
})(
|
||||
jQuery,
|
||||
PayPalCommerceGatewaySettings.ajax.refresh_feature_status,
|
||||
'#field-credentials_feature_onboarding_heading'
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
|
|
|
@ -244,6 +244,10 @@ class SettingsPageAssets {
|
|||
'endpoint' => \WC_AJAX::get_endpoint( RefreshFeatureStatusEndpoint::ENDPOINT ),
|
||||
'nonce' => wp_create_nonce( RefreshFeatureStatusEndpoint::nonce() ),
|
||||
'button' => '.ppcp-refresh-feature-status',
|
||||
'messages' => array(
|
||||
'waiting' => __( 'Checking features...', 'woocommerce-paypal-payments' ),
|
||||
'success' => __( 'Feature status refreshed.', 'woocommerce-paypal-payments' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
@ -393,7 +393,7 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'refresh_feature_status' => array(
|
||||
'title' => __( 'Refresh feature availability status', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-text',
|
||||
'text' => '<button type="button" class="button ppcp-refresh-feature-status">' . esc_html__( 'Check available features', 'woocommerce-paypal-payments' ) . '</button>',
|
||||
'text' => '<button type="button" class="button ppcp-refresh-feature-status">' . esc_html__( 'Check available features', 'woocommerce-paypal-payments' ) . '</button><div class="ppcp-status-text"></div>',
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue