Nathan
Admin: Enabled User Management & Plan Control. Fixed Stats 0 issue.
28f892f
Raw History Blame Contribute Delete
11.7 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Control Center — ViralFlow AI</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800;900&family=Plus+Jakarta+Sans:wght@300;400;600;700&display=swap" rel="stylesheet">
<script src="https://unpkg.com/lucide@latest"></script>
<style>
:root {
--bg: #020617;
--surface: rgba(15, 23, 42, 0.6);
--accent: #6366f1;
--success: #10b981;
--danger: #ef4444;
--text: #f8fafc;
--text-dim: #94a3b8;
--glass-border: rgba(255, 255, 255, 0.08);
}
* { box-sizing: border-box; transition: all 0.3s ease; }
body {
background: radial-gradient(circle at 50% -20%, #1e1b4b 0%, var(--bg) 80%);
color: var(--text);
font-family: 'Plus Jakarta Sans', sans-serif;
margin: 0; padding: 40px;
}
.glass-panel {
background: var(--surface); backdrop-filter: blur(20px);
border-radius: 32px; border: 1px solid var(--glass-border);
padding: 40px; margin-bottom: 30px;
}
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px; }
h1 { font-family: 'Outfit', sans-serif; font-size: 2.2rem; font-weight: 900; margin: 0; }
.pricing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }
.input-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 10px; font-size: 0.8rem; font-weight: 800; color: var(--text-dim); text-transform: uppercase; }
input {
width: 100%; background: rgba(0,0,0,0.3); border: 1px solid var(--glass-border);
padding: 15px 20px; border-radius: 15px; color: #fff; outline: none;
}
/* --- Toggle Switch --- */
.switch { position: relative; display: inline-block; width: 60px; height: 34px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
position: absolute; cursor: pointer; inset: 0; background-color: #334155;
transition: .4s; border-radius: 34px;
}
.slider:before {
position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px;
background-color: white; transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(26px); }
.admin-table {
width: 100%; border-collapse: collapse; margin-top: 30px;
}
th { text-align: left; padding: 20px; color: var(--text-dim); font-size: 0.8rem; text-transform: uppercase; border-bottom: 1px solid var(--glass-border); }
td { padding: 20px; border-bottom: 1px solid var(--glass-border); }
.badge { padding: 6px 14px; border-radius: 20px; font-size: 0.75rem; font-weight: 900; }
.badge-free { background: rgba(148, 163, 184, 0.1); color: #94a3b8; }
.badge-premium { background: rgba(129, 140, 248, 0.1); color: #818cf8; }
.badge-ultra { background: rgba(245, 158, 11, 0.1); color: #f59e0b; }
.btn-primary {
cursor: pointer; border: none; padding: 14px 28px; border-radius: 18px;
background: var(--accent); color: #fff; font-weight: 800;
}
</style>
</head>
<body>
<div class="header">
<div>
<a href="index.html" style="color: var(--text-dim); text-decoration: none; font-size: 0.9rem; font-weight: 700;">← Exit Admin</a>
<h1>Revenue Control Center 💰</h1>
</div>
<div style="display: flex; gap: 40px;">
<div style="text-align: center;"><div style="font-size: 0.7rem; color: var(--text-dim);">USERS</div><div id="stat-users" style="font-size: 1.8rem; font-weight: 900;">0</div></div>
<div style="text-align: center;"><div style="font-size: 0.7rem; color: var(--text-dim);">CHANNELS</div><div id="stat-active" style="font-size: 1.8rem; font-weight: 900; color: var(--success);">0</div></div>
</div>
</div>
<div class="glass-panel">
<h3 style="margin-top: 0; font-family: 'Outfit', sans-serif;">Advanced Pricing Engine</h3>
<div class="pricing-grid">
<div class="input-group"><label>Monthly Sale Price (₹)</label><input type="number" id="price-monthly"></div>
<div class="input-group"><label>Monthly Old Price (₹)</label><input type="number" id="old-price-monthly"></div>
<div class="input-group"><label>Yearly Sale Price (₹)</label><input type="number" id="price-yearly"></div>
<div class="input-group"><label>Yearly Old Price (₹)</label><input type="number" id="old-price-yearly"></div>
</div>
<div class="pricing-grid" style="margin-top: 20px;">
<div class="input-group"><label>Discount Percent (%)</label><input type="number" id="discount-pct"></div>
<div class="input-group"><label>Sale Badge Text</label><input type="text" id="sale-text"></div>
<div class="input-group">
<label>Monthly Sale Active</label>
<label class="switch"><input type="checkbox" id="m-sale-active"><span class="slider"></span></label>
</div>
<div class="input-group">
<label>Yearly Sale Active</label>
<label class="switch"><input type="checkbox" id="y-sale-active"><span class="slider"></span></label>
</div>
</div>
<div style="text-align: right; margin-top: 20px;">
<button class="btn-primary" onclick="savePricing()">Apply Global Price Changes 🚀</button>
</div>
</div>
<div class="glass-panel" style="padding: 0; overflow: hidden;">
<table class="admin-table">
<thead>
<tr>
<th>Agency Owner</th>
<th>YouTube Channel</th>
<th>Current Tier</th>
<th>Automation Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="user-list"></tbody>
</table>
</div>
<script>
const authToken = localStorage.getItem('saas_token');
async function loadAdminData() {
if (!authToken) { window.location.href = 'index.html'; return; }
const statsRes = await fetch('/api/admin/global-stats', { headers: { 'Authorization': `Bearer ${authToken}` } });
const stats = await statsRes.json();
document.getElementById('stat-users').innerText = stats.totalUsers || 0;
document.getElementById('stat-active').innerText = stats.activeChannels || 0;
const res = await fetch('/api/admin/users', { headers: { 'Authorization': `Bearer ${authToken}` } });
const users = await res.json();
const list = document.getElementById('user-list');
list.innerHTML = users.map(u => `
<tr>
<td style="font-weight: 800;">${u.email}</td>
<td><div style="font-weight: 700;">${u.channels?.[0]?.channel_name || '❌ Unlinked'}</div></td>
<td><span class="badge ${u.plan === 'ultra' ? 'badge-ultra' : (u.plan === 'premium' ? 'badge-premium' : 'badge-free')}">${u.plan?.toUpperCase() || 'FREE'}</span></td>
<td><div style="display: flex; align-items: center; gap: 8px;"><div style="width: 10px; height: 10px; border-radius: 50%; background: ${u.channels?.[0]?.is_active ? 'var(--success)' : '#475569'};"></div>${u.channels?.[0]?.is_active ? 'Active' : 'Offline'}</div></td>
<td>
<div style="display:flex; gap:8px;">
<button onclick="adminAction('${u.id}', 'ultra')" style="background: rgba(245, 158, 11, 0.1); color: #f59e0b; border: 1px solid #f59e0b; padding: 6px 12px; border-radius: 10px; cursor: pointer; font-weight: 800; font-size: 0.7rem;">ULTRA</button>
<button onclick="adminAction('${u.id}', 'pro')" style="background: rgba(99, 102, 241, 0.1); color: var(--accent); border: 1px solid var(--accent); padding: 6px 12px; border-radius: 10px; cursor: pointer; font-weight: 800; font-size: 0.7rem;">PRO</button>
<button onclick="adminAction('${u.id}', 'free')" style="background: rgba(255, 255, 255, 0.05); color: #fff; border: 1px solid var(--glass-border); padding: 6px 12px; border-radius: 10px; cursor: pointer; font-weight: 800; font-size: 0.7rem;">FREE</button>
</div>
</td>
</tr>
`).join('');
}
async function adminAction(userId, plan) {
if (!confirm(`Change user to ${plan.toUpperCase()}?`)) return;
const res = await fetch('/api/admin/update-plan', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${authToken}` },
body: JSON.stringify({ userId, plan })
});
if (res.ok) {
alert("User Plan Updated! 🚀");
loadAdminData();
}
}
async function loadAdminPricing() {
const res = await fetch('/api/platform/pricing');
const p = await res.json();
if (p) {
document.getElementById('price-monthly').value = p.pro_monthly || 0;
document.getElementById('old-price-monthly').value = p.old_pro_monthly || 0;
document.getElementById('price-yearly').value = p.pro_yearly || 0;
document.getElementById('old-price-yearly').value = p.old_pro_yearly || 0;
document.getElementById('discount-pct').value = p.discount_percent || 0;
document.getElementById('sale-text').value = p.discount_text || "";
document.getElementById('m-sale-active').checked = p.m_discount_active || false;
document.getElementById('y-sale-active').checked = p.y_discount_active || false;
}
}
async function savePricing() {
const pricing = {
pro_monthly: parseInt(document.getElementById('price-monthly').value),
old_pro_monthly: parseInt(document.getElementById('old-price-monthly').value),
pro_yearly: parseInt(document.getElementById('price-yearly').value),
old_pro_yearly: parseInt(document.getElementById('old-price-yearly').value),
discount_percent: parseInt(document.getElementById('discount-pct').value),
discount_text: document.getElementById('sale-text').value,
m_discount_active: document.getElementById('m-sale-active').checked,
y_discount_active: document.getElementById('y-sale-active').checked
};
const res = await fetch('/api/admin/pricing', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${authToken}` },
body: JSON.stringify({ pricing })
});
if (res.ok) alert("Global Pricing Engine Updated! ⚡");
}
loadAdminPricing();
loadAdminData();
</script>
</body>
</html>