fernandosliborioo's picture
continuar
3129a87 verified
Raw History Blame Contribute Delete
4.15 kB
// Main application script
document.addEventListener('DOMContentLoaded', function() {
initializeDashboard();
setupEventListeners();
});
// Initialize dashboard with mock data
function initializeDashboard() {
// Mock data for demonstration
const mockStats = {
activeUsers: 245,
webhookEvents: 1567,
monthlyRevenue: '$12,450'
};
const mockActivity = [
{
type: 'purchase',
user: 'john@example.com',
plan: 'Premium Plan',
time: '2 hours ago',
status: 'success'
},
{
type: 'cancellation',
user: 'jane@example.com',
plan: 'Basic Plan',
time: '5 hours ago',
status: 'warning'
},
{
type: 'webhook',
user: 'system',
plan: 'N/A',
time: '1 day ago',
status: 'info'
},
{
type: 'upgrade',
user: 'mike@example.com',
plan: 'Enterprise Plan',
time: '2 days ago',
status: 'success'
}
];
// Update dashboard stats
updateDashboardStats(mockStats);
updateRecentActivity(mockActivity);
}
// Update dashboard statistics
function updateDashboardStats(stats) {
const activeUsersElement = document.getElementById('activeUsersCount');
const webhookEventsElement = document.getElementById('webhookEventsCount');
const monthlyRevenueElement = document.getElementById('monthlyRevenue');
if (activeUsersElement) activeUsersElement.textContent = stats.activeUsers;
if (webhookEventsElement) textContent = stats.webhookEvents;
if (monthlyRevenueElement) textContent = stats.monthlyRevenue;
}
// Update recent activity feed
function updateRecentActivity(activities) {
const activityContainer = document.getElementById('recentActivity');
if (!activityContainer) return;
activityContainer.innerHTML = activities.map(activity => `
<div class="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
<div class="flex items-center space-x-4">
<div class="w-3 h-3 rounded-full ${
activity.status === 'success' ? 'bg-green-500' :
activity.status === 'warning' ? 'bg-yellow-500' : 'bg-blue-500'
}"></div>
<div>
<p class="font-medium text-gray-800">
${activity.user} - ${activity.type}
</p>
<p class="text-sm text-gray-600">${activity.plan}</p>
</div>
</div>
<div class="text-right">
<p class="text-sm text-gray-600">${activity.time}</p>
<span class="inline-block px-2 py-1 text-xs font-medium rounded ${
activity.status === 'success' ? 'bg-green-100 text-green-800' :
activity.status === 'warning' ? 'bg-yellow-100 text-yellow-800' : 'bg-blue-100 text-blue-800'
}">
${activity.status}
</span>
</div>
</div>
`).join('');
}
// Setup event listeners
function setupEventListeners() {
// Add any global event listeners here
console.log('Event listeners initialized');
}
// Utility function to format dates
function formatDate(date) {
return new Date(date).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric'
});
}
// API integration functions (for future use)
async function fetchDashboardData() {
try {
// This would be replaced with actual API calls
const response = await fetch('/api/dashboard');
if (!response.ok) throw new Error('Failed to fetch dashboard data');
return await response.json();
} catch (error) {
console.error('Error fetching dashboard data:', error);
return null;
}
}
// Export functions for use in other modules
window.HotmartFlow = {
initializeDashboard,
updateDashboardStats,
updateRecentActivity,
fetchDashboardData
};