Skip to content

Commit 0c98dbb

Browse files
committed
UI updates and added loader on connect page.
1 parent dd0c828 commit 0c98dbb

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

js/admin.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
(function ($) {
33
const params = window.mailchimp_sf_admin_params || {};
44
const oauthBaseUrl = 'https://woocommerce.mailchimpapp.com';
5+
const spinner = '.mailchimp-sf-oauth-connect-wrapper .spinner';
6+
const errorSelector = '.mailchimp-sf-oauth-section .oauth-error';
57

68
/**
79
* Open Mailchimp OAuth popup.
@@ -31,7 +33,6 @@
3133
if (popup.closed) {
3234
// Clear interval.
3335
window.clearInterval(oauthInterval);
34-
// TODO: Hide/show error/loading messages.
3536

3637
// Check status of OAuth connection.
3738
$.post(`${oauthBaseUrl}/api/status/${token}`, function (statusData) {
@@ -52,18 +53,30 @@
5253
'Error calling OAuth finish endpoint. Data:',
5354
finishResponse,
5455
);
56+
if (finishResponse.data && finishResponse.data.message) {
57+
$(errorSelector).html(finishResponse.data.message);
58+
} else {
59+
$(errorSelector).html(params.generic_error);
60+
}
61+
$(errorSelector).show();
5562
}
5663
}).fail(function () {
5764
console.error('Error calling OAuth finish endpoint.');
65+
$(errorSelector).html(params.generic_error);
66+
$(errorSelector).show();
5867
});
5968
} else {
6069
console.log(
6170
'Error calling OAuth status endpoint. No credentials provided at login popup? Data:',
6271
statusData,
6372
);
6473
}
74+
$(spinner).removeClass('is-active');
6575
}).fail(function () {
76+
$(errorSelector).html(params.generic_error);
77+
$(errorSelector).show();
6678
console.error('Error calling OAuth status endpoint.');
79+
$(spinner).removeClass('is-active');
6780
});
6881
}
6982
}, 250);
@@ -73,7 +86,10 @@
7386
$(window).on('load', function () {
7487
// Mailchimp OAuth connection.
7588
$('#mailchimp_sf_oauth_connect').click(function () {
76-
$('.mailchimp-sf-oauth-section .oauth-error').html('');
89+
$(errorSelector).hide();
90+
$(errorSelector).html('');
91+
$(spinner).addClass('is-active');
92+
7793
$.post(
7894
params.ajax_url,
7995
{
@@ -85,23 +101,19 @@
85101
// Open Mailchimp OAuth popup.
86102
openMailChimpOauthPopup(response.data.token);
87103
} else {
88-
// eslint-disable-next-line no-console
89-
console.error(response.data);
90104
if (response.data && response.data.message) {
91-
$('.mailchimp-sf-oauth-section .oauth-error').html(
92-
response.data.message,
93-
);
105+
$(errorSelector).html(response.data.message);
94106
} else {
95-
$('.mailchimp-sf-oauth-section .oauth-error').html(
96-
'An error occurred. Please try again.',
97-
);
107+
$(errorSelector).html(params.generic_error);
98108
}
109+
$(errorSelector).show();
110+
$(spinner).removeClass('is-active');
99111
}
100112
},
101113
).fail(function () {
102-
$('.mailchimp-sf-oauth-section .oauth-error').html(
103-
'An error occurred. Please try again.',
104-
);
114+
$(errorSelector).html(params.generic_error);
115+
$(errorSelector).show();
116+
$(spinner).removeClass('is-active');
105117
});
106118
});
107119
});

views/setup_page.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@
3939
<?php
4040
echo wp_kses(
4141
__(
42-
'To get started, we\'ll need to access your Mailchimp account with an <a href="http://kb.mailchimp.com/integrations/api-integrations/about-api-keys">API Key</a>. Paste your Mailchimp API key, and click <strong>Connect</strong> to continue.',
42+
'To get started, we\'ll need to connect your Mailchimp account. Click <strong>Connect Account</strong> to continue.',
4343
'mailchimp'
4444
),
4545
[
46-
'a' => [
47-
'href' => [],
48-
],
4946
'strong' => [],
5047
]
5148
);
@@ -60,7 +57,7 @@
6057
);
6158
?>
6259
</p>
63-
<div class="mc-section">
60+
<div class="mc-section"> <!-- TODO:remove this -->
6461
<table class="widefat mc-widefat mc-api">
6562
<form method="POST" action="">
6663
<tr valign="top">
@@ -75,11 +72,20 @@
7572
</tr>
7673
</form>
7774
</table>
78-
<div class="mailchimp-sf-oauth-section">
79-
<!-- TODO: Update design and content here -->
80-
<button class="button" id="mailchimp_sf_oauth_connect" href="#"><?php esc_html_e( 'Connect Account', 'mailchimp' ); ?></button>
81-
<p><span class="oauth-error"></span></p>
82-
</div>
75+
</div>
76+
<div class="mc-section mailchimp-sf-oauth-section">
77+
<table class="widefat mc-widefat mc-api">
78+
<tr valign="top">
79+
<th scope="row" class="mailchimp-connect"><?php esc_html_e( 'Connect to Mailchimp', 'mailchimp' ); ?></th>
80+
<td>
81+
<div class="mailchimp-sf-oauth-connect-wrapper">
82+
<span class="spinner"></span>
83+
<button class="button" id="mailchimp_sf_oauth_connect" href="#"><?php esc_html_e( 'Connect Account', 'mailchimp' ); ?></button>
84+
</div>
85+
</td>
86+
</tr>
87+
</table>
88+
<p class="oauth-error error_msg" style="display:none;"></p>
8389
</div>
8490
</div>
8591

0 commit comments

Comments
 (0)