Spaces:
Running

xopro1 / admin.html
xoproject1's picture
create complete working backend with database for product management + writing- + add/remove product +all other features a web apps's backend must have - Follow Up Deployment
0819992 verified
Raw History Blame Contribute Delete
23.3 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Panel | MindBloom</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<style>
.sidebar {
width: 280px;
transition: all 0.3s ease;
}
.main-content {
margin-left: 280px;
transition: all 0.3s ease;
}
.collapsed .sidebar {
width: 80px;
}
.collapsed .main-content {
margin-left: 80px;
}
.nav-item:hover {
background-color: rgba(139, 92, 246, 0.1);
}
.active-nav {
background-color: rgba(139, 92, 246, 0.2);
border-left: 4px solid #8b5cf6;
}
.table-row:hover {
background-color: #f9fafb;
}
</style>
</head>
<body class="bg-gray-100 font-sans antialiased">
<div class="flex" id="admin-layout">
<!-- Sidebar -->
<div class="sidebar bg-white shadow-lg fixed h-full overflow-y-auto">
<div class="p-6 border-b border-gray-200">
<div class="flex items-center justify-between">
<div class="flex items-center">
<i data-feather="heart" class="text-purple-600 h-6 w-6"></i>
<span class="ml-2 text-xl font-bold text-gray-900">Admin</span>
</div>
<button id="toggle-sidebar" class="text-gray-600 hover:text-purple-600">
<i data-feather="chevron-left"></i>
</button>
</div>
</div>
<nav class="mt-6">
<div class="px-4 space-y-1">
<a href="#dashboard" class="nav-item active-nav flex items-center px-4 py-3 text-gray-700 rounded-lg">
<i data-feather="grid" class="h-5 w-5"></i>
<span class="ml-3">Dashboard</span>
</a>
<a href="#products" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
<i data-feather="shopping-bag" class="h-5 w-5"></i>
<span class="ml-3">Products</span>
</a>
<a href="#content" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
<i data-feather="file-text" class="h-5 w-5"></i>
<span class="ml-3">Content</span>
</a>
<a href="#therapy" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
<i data-feather="activity" class="h-5 w-5"></i>
<span class="ml-3">Therapy</span>
</a>
<a href="#users" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
<i data-feather="users" class="h-5 w-5"></i>
<span class="ml-3">Users</span>
</a>
<a href="#settings" class="nav-item flex items-center px-4 py-3 text-gray-700 rounded-lg">
<i data-feather="settings" class="h-5 w-5"></i>
<span class="ml-3">Settings</span>
</a>
</div>
</nav>
<div class="absolute bottom-0 w-full p-4 border-t border-gray-200">
<button class="w-full flex items-center justify-center px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700">
<i data-feather="log-out" class="h-4 w-4 mr-2"></i>
<span>Logout</span>
</button>
</div>
</div>
<!-- Main Content -->
<div class="main-content w-full min-h-screen">
<!-- Header -->
<header class="bg-white shadow-sm">
<div class="flex items-center justify-between p-6">
<h1 class="text-2xl font-bold text-gray-900">Dashboard</h1>
<div class="flex items-center space-x-4">
<div class="relative">
<input type="text" placeholder="Search..." class="pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-600 focus:border-transparent">
<i data-feather="search" class="absolute left-3 top-2.5 h-5 w-5 text-gray-400"></i>
</div>
<div class="flex items-center space-x-3">
<button class="p-2 text-gray-600 hover:text-purple-600">
<i data-feather="bell"></i>
</button>
<div class="w-10 h-10 bg-purple-600 rounded-full flex items-center justify-center text-white font-semibold">
A
</div>
</div>
</div>
</div>
</header>
<!-- Dashboard Content -->
<main class="p-6">
<!-- Stats Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
<div class="bg-white rounded-lg shadow p-6" data-aos="fade-up">
<div class="flex items-center">
<div class="p-3 bg-purple-100 rounded-lg">
<i data-feather="users" class="h-6 w-6 text-purple-600"></i>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Total Users</p>
<p class="text-2xl font-bold text-gray-900">1,248</p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6" data-aos="fade-up" data-aos-delay="100">
<div class="flex items-center">
<div class="p-3 bg-green-100 rounded-lg">
<i data-feather="shopping-bag" class="h-6 w-6 text-green-600"></i>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Products</p>
<p class="text-2xl font-bold text-gray-900">89</p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6" data-aos="fade-up" data-aos-delay="200">
<div class="flex items-center">
<div class="p-3 bg-blue-100 rounded-lg">
<i data-feather="file-text" class="h-6 w-6 text-blue-600"></i>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Articles</p>
<p class="text-2xl font-bold text-gray-900">156</p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6" data-aos="fade-up" data-aos-delay="300">
<div class="flex items-center">
<div class="p-3 bg-orange-100 rounded-lg">
<i data-feather="calendar" class="h-6 w-6 text-orange-600"></i>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Sessions</p>
<p class="text-2xl font-bold text-gray-900">324</p>
</div>
</div>
</div>
</div>
<!-- Recent Products -->
<div class="bg-white rounded-lg shadow mb-8" data-aos="fade-up">
<div class="p-6 border-b border-gray-200">
<h2 class="text-lg font-semibold text-gray-900">Recent Products</h2>
</div>
<div class="p-6">
<table class="w-full">
<thead>
<tr class="text-left text-sm text-gray-500">
<th class="pb-4">Product</th>
<th class="pb-4">Category</th>
<th class="pb-4">Price</th>
<th class="pb-4">Status</th>
<th class="pb-4 text-right">Actions</th>
</tr>
</thead>
<tbody>
<tr class="table-row border-b border-gray-200">
<td class="py-4">
<div class="flex items-center">
<img src="http://static.photos/cosmetic/64x64/1" alt="Product" class="w-10 h-10 rounded-lg object-cover">
<div class="ml-4">
<p class="font-medium text-gray-900">Calming Face Serum</p>
<p class="text-sm text-gray-600">SKU: MB-SER-001</p>
</div>
</div>
</td>
<td class="py-4">Skincare</td>
<td class="py-4">$42.99</td>
<td class="py-4">
<span class="px-2 py-1 text-xs font-semibold bg-green-100 text-green-800 rounded-full">Active</span>
</td>
<td class="py-4 text-right">
<div class="flex justify-end space-x-2">
<button class="p-1 text-blue-600 hover:text-blue-800">
<i data-feather="edit" class="h-4 w-4"></i>
</button>
<button class="p-1 text-red-600 hover:text-red-800">
<i data-feather="trash" class="h-4 w-4"></i>
</button>
</div>
</td>
</tr>
<tr class="table-row border-b border-gray-200">
<td class="py-4">
<div class="flex items-center">
<img src="http://static.photos/cosmetic/64x64/2" alt="Product" class="w-10 h-10 rounded-lg object-cover">
<div class="ml-4">
<p class="font-medium text-gray-900">Mindful Lip Balm</p>
<p class="text-sm text-gray-600">SKU: MB-LIP-002</p>
</div>
</div>
</td>
<td class="py-4">Beauty</td>
<td class="py-4">$18.50</td>
<td class="py-4">
<span class="px-2 py-1 text-xs font-semibold bg-green-100 text-green-800 rounded-full">Active</span>
</td>
<td class="py-4 text-right">
<div class="flex justify-end space-x-2">
<button class="p-1 text-blue-600 hover:text-blue-800">
<i data-feather="edit" class="h-4 w-4"></i>
</button>
<button class="p-1 text-red-600 hover:text-red-800">
<i data-feather="trash" class="h-4 w-4"></i>
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="p-6 border-t border-gray-200">
<button class="w-full bg-purple-600 text-white py-2 px-4 rounded-lg hover:bg-purple-700">
Add New Product
</button>
</div>
</div>
<!-- Quick Actions -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="bg-white rounded-lg shadow p-6" data-aos="fade-up">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Create New Content</h3>
<div class="space-y-3">
<button class="w-full flex items-center justify-between p-4 border border-gray-200 rounded-lg hover:border-purple-600 hover:bg-purple-50">
<span>Write Article</span>
<i data-feather="arrow-right" class="h-5 w-5"></i>
</button>
<button class="w-full flex items-center justify-between p-4 border border-gray-200 rounded-lg hover:border-purple-600 hover:bg-purple-50">
<span>Add Therapy Session</span>
<i data-feather="arrow-right" class="h-5 w-5"></i>
</button>
<button class="w-full flex items-center justify-between p-4 border border-gray-200 rounded-lg hover:border-purple-600 hover:bg-purple-50">
<span>Create Beauty Guide</span>
<i data-feather="arrow-right" class="h-5 w-5"></i>
</button>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6" data-aos="fade-up" data-aos-delay="100">
<h3 class="text-lg font-semibold text-gray-900 mb-4">System Status</h3>
<div class="space-y-4">
<div class="flex items-center justify-between">
<span class="text-gray-600">Database</span>
<span class="px-2 py-1 text-xs font-semibold bg-green-100 text-green-800 rounded-full">Online</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600">Storage</span>
<span class="text-sm text-gray-900">2.4GB / 10GB used</span>
</div>
<div class="flex items-center justify-between">
<span class="text-gray-600">Last Backup</span>
<span class="text-sm text-gray-900">2 hours ago</span>
</div>
<div class="pt-4">
<button class="w-full bg-gray-100 text-gray-700 py-2 px-4 rounded-lg hover:bg-gray-200">
Run System Check
</button>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
<script>
let authToken = localStorage.getItem('authToken');
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
// Check authentication
if (!authToken || !currentUser) {
window.location.href = 'login.html';
}
AOS.init({
duration: 800,
easing: 'ease-in-out',
once: true
});
feather.replace();
// Toggle sidebar
document.getElementById('toggle-sidebar').addEventListener('click', function() {
document.getElementById('admin-layout').classList.toggle('collapsed');
const icon = this.querySelector('i');
if (document.getElementById('admin-layout').classList.contains('collapsed')) {
icon.setAttribute('data-feather', 'chevron-right');
} else {
icon.setAttribute('data-feather', 'chevron-left');
}
feather.replace();
});
// Navigation active state
document.querySelectorAll('.nav-item').forEach(item => {
item.addEventListener('click', function() {
document.querySelectorAll('.nav-item').forEach(i => i.classList.remove('active-nav'));
this.classList.add('active-nav');
});
});
// Logout functionality
document.querySelector('button[onclick="logout()"]').addEventListener('click', logout);
function logout() {
localStorage.removeItem('authToken');
localStorage.removeItem('currentUser');
window.location.href = 'login.html';
}
// Load dashboard data
async function loadDashboardData() {
try {
const response = await fetch('/api/admin/stats', {
headers: {
'Authorization': `Bearer ${authToken}`
}
});
if (response.status === 401) {
logout();
return;
}
const data = await response.json();
// Update stats cards
document.querySelector('[data-stat="users"]').textContent = data.totalUsers.toLocaleString();
document.querySelector('[data-stat="products"]').textContent = data.totalProducts.toLocaleString();
document.querySelector('[data-stat="articles"]').textContent = data.totalArticles.toLocaleString();
document.querySelector('[data-stat="sessions"]').textContent = data.publishedArticles.toLocaleString();
} catch (error) {
console.error('Error loading dashboard data:', error);
}
}
// Load products
async function loadProducts() {
try {
const response = await fetch('/api/products?limit=5', {
headers: {
'Authorization': `Bearer ${authToken}`
}
});
if (response.status === 401) {
logout();
return;
}
const data = await response.json();
const productsTable = document.getElementById('products-table-body');
productsTable.innerHTML = data.products.map(product => `
<tr class="table-row border-b border-gray-200">
<td class="py-4">
<div class="flex items-center">
<img src="${product.image || 'http://static.photos/cosmetic/64x64/1'}" alt="${product.name}" class="w-10 h-10 rounded-lg object-cover">
<div class="ml-4">
<p class="font-medium text-gray-900">${product.name}</p>
<p class="text-sm text-gray-600">SKU: ${product.sku}</p>
</div>
</div>
</td>
<td class="py-4">${product.category}</td>
<td class="py-4">${product.price.toFixed(2)}</td>
<td class="py-4">
<span class="px-2 py-1 text-xs font-semibold ${product.status === 'active' ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'} rounded-full">
${product.status}
</span>
</td>
<td class="py-4 text-right">
<div class="flex justify-end space-x-2">
<button onclick="editProduct('${product._id}')" class="p-1 text-blue-600 hover:text-blue-800">
<i data-feather="edit" class="h-4 w-4"></i>
</button>
<button onclick="deleteProduct('${product._id}')" class="p-1 text-red-600 hover:text-red-800">
<i data-feather="trash" class="h-4 w-4"></i>
</button>
</div>
</td>
</tr>
`).join('');
feather.replace();
} catch (error) {
console.error('Error loading products:', error);
}
}
// Initialize dashboard
loadDashboardData();
loadProducts();
function editProduct(id) {
// Redirect to product edit page or open modal
console.log('Edit product:', id);
}
async function deleteProduct(id) {
if (confirm('Are you sure you want to delete this product?')) {
try {
const response = await fetch(`/api/products/${id}`, {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${authToken}`
}
});
if (response.ok) {
loadProducts();
loadDashboardData();
} else {
alert('Error deleting product');
}
} catch (error) {
console.error('Error deleting product:', error);
}
}
}
</script>
</body>
</html>