added sync button, improved UI
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
// public/js/dashboard.js
|
||||
$(document).ready(function() {
|
||||
console.log(base_url);
|
||||
function fetchDashboardStats() {
|
||||
$.ajax({
|
||||
url: base_url + '/api/dashboard/stats',
|
||||
@@ -83,4 +82,53 @@ $(document).ready(function() {
|
||||
|
||||
// Todo: Refresh data every 5 minutes (300000 ms) automatically without page reload
|
||||
// setInterval(fetchDashboardStats, 300000);
|
||||
|
||||
$('#syncTriggerBtn').on('click', function() {
|
||||
let btn = $(this);
|
||||
let icon = $('#syncIcon');
|
||||
let text = $('#syncText');
|
||||
|
||||
// Disable button and add spinning effect
|
||||
btn.prop('disabled', true);
|
||||
icon.addClass('spinner-border spinner-border-sm');
|
||||
text.text('Syncing...');
|
||||
|
||||
$.ajax({
|
||||
url: base_url + '/api/subscriptions/sync',
|
||||
method: 'POST',
|
||||
data: {
|
||||
_token: $('meta[name="csrf-token"]').attr('content')
|
||||
},
|
||||
success: function(response) {
|
||||
// Use SweetAlert2 for a clean success alert
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Synchronized!',
|
||||
text: response.message,
|
||||
timer: 2000,
|
||||
showConfirmButton: false
|
||||
});
|
||||
|
||||
// Refresh dashboard data instantly to reflect updated counts
|
||||
fetchDashboardStats();
|
||||
},
|
||||
error: function(xhr) {
|
||||
let errorMsg = xhr.responseJSON && xhr.responseJSON.message
|
||||
? xhr.responseJSON.message
|
||||
: 'An unexpected error occurred during synchronization.';
|
||||
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Sync Failed',
|
||||
text: errorMsg
|
||||
});
|
||||
},
|
||||
complete: function() {
|
||||
// Restore button state
|
||||
btn.prop('disabled', false);
|
||||
icon.removeClass('spinner-border spinner-border-sm');
|
||||
text.text('Sync Now');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user