270 lines
15 KiB
HTML
270 lines
15 KiB
HTML
{% extends "admin/base.html" %}
|
|
|
|
{% block title %}Users Management - LetzShop Admin{% endblock %}
|
|
|
|
{% block page_title %}Users Management{% endblock %}
|
|
|
|
{% block content %}
|
|
<div x-data="adminUsers()" x-init="init()">
|
|
<!-- Header Section with Search and Actions -->
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 mb-6">
|
|
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
|
<!-- Search Bar -->
|
|
<div class="flex-1 max-w-md">
|
|
<div class="relative">
|
|
<input
|
|
type="text"
|
|
x-model="filters.search"
|
|
@input="debouncedSearch()"
|
|
placeholder="Search users by name, email, or username..."
|
|
class="w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white"
|
|
>
|
|
<div class="absolute left-3 top-2.5" x-html="$icon('search', 'w-5 h-5 text-gray-400')"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Filter and Action Buttons -->
|
|
<div class="flex gap-3">
|
|
<!-- Role Filter -->
|
|
<select
|
|
x-model="filters.role"
|
|
@change="loadUsers()"
|
|
class="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white"
|
|
>
|
|
<option value="">All Roles</option>
|
|
<option value="customer">Customer</option>
|
|
<option value="vendor">Vendor</option>
|
|
<option value="admin">Admin</option>
|
|
</select>
|
|
|
|
<!-- Status Filter -->
|
|
<select
|
|
x-model="filters.is_active"
|
|
@change="loadUsers()"
|
|
class="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white"
|
|
>
|
|
<option value="">All Status</option>
|
|
<option value="true">Active</option>
|
|
<option value="false">Inactive</option>
|
|
</select>
|
|
|
|
<!-- Add User Button -->
|
|
<button
|
|
@click="openCreateModal()"
|
|
class="flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
|
|
>
|
|
<span x-html="$icon('user-plus', 'w-5 h-5')"></span>
|
|
<span>Add User</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Statistics Cards -->
|
|
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-6">
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<p class="text-sm text-gray-600 dark:text-gray-400">Total Users</p>
|
|
<p class="text-2xl font-bold text-gray-900 dark:text-white" x-text="stats.total"></p>
|
|
</div>
|
|
<div class="p-3 bg-blue-100 dark:bg-blue-900 rounded-lg" x-html="$icon('users', 'w-8 h-8 text-blue-600 dark:text-blue-400')"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<p class="text-sm text-gray-600 dark:text-gray-400">Active Users</p>
|
|
<p class="text-2xl font-bold text-green-600 dark:text-green-400" x-text="stats.active"></p>
|
|
</div>
|
|
<div class="p-3 bg-green-100 dark:bg-green-900 rounded-lg" x-html="$icon('user-check', 'w-8 h-8 text-green-600 dark:text-green-400')"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<p class="text-sm text-gray-600 dark:text-gray-400">Vendors</p>
|
|
<p class="text-2xl font-bold text-purple-600 dark:text-purple-400" x-text="stats.vendors"></p>
|
|
</div>
|
|
<div class="p-3 bg-purple-100 dark:bg-purple-900 rounded-lg" x-html="$icon('store', 'w-8 h-8 text-purple-600 dark:text-purple-400')"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6">
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<p class="text-sm text-gray-600 dark:text-gray-400">Admins</p>
|
|
<p class="text-2xl font-bold text-orange-600 dark:text-orange-400" x-text="stats.admins"></p>
|
|
</div>
|
|
<div class="p-3 bg-orange-100 dark:bg-orange-900 rounded-lg" x-html="$icon('shield', 'w-8 h-8 text-orange-600 dark:text-orange-400')"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Users Table -->
|
|
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden">
|
|
<!-- Loading State -->
|
|
<div x-show="loading" class="p-8 text-center">
|
|
<div class="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"></div>
|
|
<p class="mt-2 text-gray-600 dark:text-gray-400">Loading users...</p>
|
|
</div>
|
|
|
|
<!-- Empty State -->
|
|
<div x-show="!loading && users.length === 0" class="p-8 text-center">
|
|
<div class="text-gray-400 dark:text-gray-500 mb-4" x-html="$icon('inbox', 'w-16 h-16 mx-auto')"></div>
|
|
<p class="text-gray-600 dark:text-gray-400">No users found</p>
|
|
</div>
|
|
|
|
<!-- Users Table -->
|
|
<div x-show="!loading && users.length > 0">
|
|
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
|
|
<thead class="bg-gray-50 dark:bg-gray-900">
|
|
<tr>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
|
User
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
|
Email
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
|
Role
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
|
Status
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
|
Registered
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
|
Last Login
|
|
</th>
|
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
|
Actions
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
|
|
<template x-for="user in users" :key="user.id">
|
|
<tr class="hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
|
|
<!-- User Info -->
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<div class="flex items-center">
|
|
<div class="flex-shrink-0 h-10 w-10 bg-gradient-to-br from-blue-500 to-purple-600 rounded-full flex items-center justify-center">
|
|
<span class="text-white font-semibold" x-text="(user.full_name || user.username || 'U').charAt(0).toUpperCase()"></span>
|
|
</div>
|
|
<div class="ml-4">
|
|
<div class="text-sm font-medium text-gray-900 dark:text-white" x-text="user.full_name || 'N/A'"></div>
|
|
<div class="text-sm text-gray-500 dark:text-gray-400" x-text="'@' + user.username"></div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
|
|
<!-- Email -->
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<div class="text-sm text-gray-900 dark:text-white" x-text="user.email"></div>
|
|
</td>
|
|
|
|
<!-- Role -->
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<span
|
|
class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full"
|
|
:class="{
|
|
'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200': user.role === 'customer',
|
|
'bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200': user.role === 'vendor',
|
|
'bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200': user.role === 'admin'
|
|
}"
|
|
x-text="user.role"
|
|
></span>
|
|
</td>
|
|
|
|
<!-- Status -->
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<span
|
|
class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full"
|
|
:class="user.is_active ? 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200' : 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200'"
|
|
x-text="user.is_active ? 'Active' : 'Inactive'"
|
|
></span>
|
|
</td>
|
|
|
|
<!-- Registered -->
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
|
|
<span x-text="Utils.formatDate(user.created_at)"></span>
|
|
</td>
|
|
|
|
<!-- Last Login -->
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
|
|
<span x-text="user.last_login ? Utils.formatDate(user.last_login) : 'Never'"></span>
|
|
</td>
|
|
|
|
<!-- Actions -->
|
|
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
|
<div class="flex justify-end gap-2">
|
|
<button
|
|
@click="viewUser(user)"
|
|
class="text-blue-600 hover:text-blue-900 dark:text-blue-400 dark:hover:text-blue-300"
|
|
title="View Details"
|
|
x-html="$icon('eye', 'w-5 h-5')"
|
|
></button>
|
|
<button
|
|
@click="editUser(user)"
|
|
class="text-yellow-600 hover:text-yellow-900 dark:text-yellow-400 dark:hover:text-yellow-300"
|
|
title="Edit"
|
|
x-html="$icon('edit', 'w-5 h-5')"
|
|
></button>
|
|
<button
|
|
@click="toggleUserStatus(user)"
|
|
:class="user.is_active ? 'text-orange-600 hover:text-orange-900 dark:text-orange-400 dark:hover:text-orange-300' : 'text-green-600 hover:text-green-900 dark:text-green-400 dark:hover:text-green-300'"
|
|
:title="user.is_active ? 'Deactivate' : 'Activate'"
|
|
x-html="$icon(user.is_active ? 'user-x' : 'user-check', 'w-5 h-5')"
|
|
></button>
|
|
<button
|
|
@click="deleteUser(user)"
|
|
class="text-red-600 hover:text-red-900 dark:text-red-400 dark:hover:text-red-300"
|
|
title="Delete"
|
|
x-html="$icon('trash', 'w-5 h-5')"
|
|
></button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</template>
|
|
</tbody>
|
|
</table>
|
|
|
|
<!-- Pagination -->
|
|
<div class="bg-gray-50 dark:bg-gray-900 px-6 py-4 border-t border-gray-200 dark:border-gray-700">
|
|
<div class="flex items-center justify-between">
|
|
<div class="text-sm text-gray-700 dark:text-gray-300">
|
|
Showing <span class="font-medium" x-text="((pagination.page - 1) * pagination.per_page) + 1"></span>
|
|
to <span class="font-medium" x-text="Math.min(pagination.page * pagination.per_page, pagination.total)"></span>
|
|
of <span class="font-medium" x-text="pagination.total"></span> users
|
|
</div>
|
|
<div class="flex gap-2">
|
|
<button
|
|
@click="previousPage()"
|
|
:disabled="pagination.page === 1"
|
|
:class="pagination.page === 1 ? 'opacity-50 cursor-not-allowed' : 'hover:bg-gray-200 dark:hover:bg-gray-700'"
|
|
class="px-3 py-1 border border-gray-300 dark:border-gray-600 rounded-lg text-sm text-gray-700 dark:text-gray-300"
|
|
>
|
|
Previous
|
|
</button>
|
|
<button
|
|
@click="nextPage()"
|
|
:disabled="pagination.page >= pagination.pages"
|
|
:class="pagination.page >= pagination.pages ? 'opacity-50 cursor-not-allowed' : 'hover:bg-gray-200 dark:hover:bg-gray-700'"
|
|
class="px-3 py-1 border border-gray-300 dark:border-gray-600 rounded-lg text-sm text-gray-700 dark:text-gray-300"
|
|
>
|
|
Next
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_scripts %}
|
|
<script src="{{ url_for('static', path='admin/js/users.js') }}"></script>
|
|
{% endblock %} |