Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
eaf22dd
1
Parent(s): 605c53a
Feat: Admin UX Overhaul - Added Info Cards, User Mgmt Actions, and Modals
Browse files
frontend/components/admin/AnalyticsTab.tsx
CHANGED
|
@@ -1,9 +1,6 @@
|
|
| 1 |
-
|
| 2 |
import { useState, useEffect } from 'react'
|
| 3 |
-
import {
|
| 4 |
-
LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer,
|
| 5 |
-
AreaChart, Area
|
| 6 |
-
} from 'recharts'
|
| 7 |
import { Activity, DollarSign, Users, TrendingUp } from 'lucide-react'
|
| 8 |
|
| 9 |
export default function AnalyticsTab() {
|
|
@@ -17,7 +14,7 @@ export default function AnalyticsTab() {
|
|
| 17 |
|
| 18 |
const loadData = async () => {
|
| 19 |
try {
|
| 20 |
-
const headers = { 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` }
|
| 21 |
|
| 22 |
const [revRes, growthRes] = await Promise.all([
|
| 23 |
fetch('/api/v1/admin/analytics/revenue', { headers }),
|
|
@@ -34,11 +31,25 @@ export default function AnalyticsTab() {
|
|
| 34 |
}
|
| 35 |
}
|
| 36 |
|
| 37 |
-
if (loading) return <div>Загрузка аналитики...</div>
|
| 38 |
|
| 39 |
return (
|
| 40 |
<div className="space-y-6">
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
{/* Growth Chart */}
|
| 43 |
<div className="bg-white p-6 rounded-2xl shadow-lg border border-slate-100">
|
| 44 |
<h3 className="text-lg font-bold mb-4 flex items-center gap-2">
|
|
|
|
| 1 |
+
```
|
| 2 |
import { useState, useEffect } from 'react'
|
| 3 |
+
import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, LineChart, Line, CartesianGrid, AreaChart, Area } from 'recharts'
|
|
|
|
|
|
|
|
|
|
| 4 |
import { Activity, DollarSign, Users, TrendingUp } from 'lucide-react'
|
| 5 |
|
| 6 |
export default function AnalyticsTab() {
|
|
|
|
| 14 |
|
| 15 |
const loadData = async () => {
|
| 16 |
try {
|
| 17 |
+
const headers = { 'Authorization': `Bearer ${ localStorage.getItem('auth_token') } ` }
|
| 18 |
|
| 19 |
const [revRes, growthRes] = await Promise.all([
|
| 20 |
fetch('/api/v1/admin/analytics/revenue', { headers }),
|
|
|
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
+
if (loading) return <div className="p-8 text-center">Загрузка аналитики...</div>
|
| 35 |
|
| 36 |
return (
|
| 37 |
<div className="space-y-6">
|
| 38 |
+
{/* Info Card */}
|
| 39 |
+
<div className="bg-gradient-to-r from-purple-50 to-pink-50 border border-purple-100 p-4 rounded-xl flex items-start gap-3">
|
| 40 |
+
<div className="p-2 bg-purple-100 rounded-lg text-purple-600">
|
| 41 |
+
<TrendingUp className="w-5 h-5" />
|
| 42 |
+
</div>
|
| 43 |
+
<div>
|
| 44 |
+
<h3 className="font-bold text-purple-900 text-sm">Аналитика и Доходы</h3>
|
| 45 |
+
<p className="text-xs text-purple-700 mt-1 leading-relaxed">
|
| 46 |
+
Обзор ключевых метрик платформы: рост пользователей и финансовые показатели (MRR).
|
| 47 |
+
Данные обновляются в реальном времени на основе активных подписок.
|
| 48 |
+
</p>
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
+
|
| 52 |
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
| 53 |
{/* Growth Chart */}
|
| 54 |
<div className="bg-white p-6 rounded-2xl shadow-lg border border-slate-100">
|
| 55 |
<h3 className="text-lg font-bold mb-4 flex items-center gap-2">
|
frontend/components/admin/PartnersTab.tsx
CHANGED
|
@@ -111,6 +111,20 @@ export default function PartnersTab() {
|
|
| 111 |
|
| 112 |
return (
|
| 113 |
<div className="space-y-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
{/* Search */}
|
| 115 |
<div className="bg-white rounded-2xl p-4 shadow-sm border border-slate-200">
|
| 116 |
<div className="relative">
|
|
|
|
| 111 |
|
| 112 |
return (
|
| 113 |
<div className="space-y-6">
|
| 114 |
+
{/* Info Card */}
|
| 115 |
+
<div className="bg-gradient-to-r from-amber-50 to-orange-50 border border-amber-100 p-4 rounded-xl flex items-start gap-3">
|
| 116 |
+
<div className="p-2 bg-amber-100 rounded-lg text-amber-600">
|
| 117 |
+
<DollarSign className="w-5 h-5" />
|
| 118 |
+
</div>
|
| 119 |
+
<div>
|
| 120 |
+
<h3 className="font-bold text-amber-900 text-sm">Партнерская Программа</h3>
|
| 121 |
+
<p className="text-xs text-amber-700 mt-1 leading-relaxed">
|
| 122 |
+
Здесь управляются партнеры, которые приводят клиентов. Партнеры получают комиссию с оплат приведенных ими клиентов.
|
| 123 |
+
Вы можете активировать новых партнеров, менять их ставку комиссии или блокировать за нарушения.
|
| 124 |
+
</p>
|
| 125 |
+
</div>
|
| 126 |
+
</div>
|
| 127 |
+
|
| 128 |
{/* Search */}
|
| 129 |
<div className="bg-white rounded-2xl p-4 shadow-sm border border-slate-200">
|
| 130 |
<div className="relative">
|
frontend/components/admin/TenantsTab.tsx
CHANGED
|
@@ -161,6 +161,20 @@ export default function TenantsTab() {
|
|
| 161 |
|
| 162 |
return (
|
| 163 |
<div className="space-y-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
{/* Filters */}
|
| 165 |
<div className="bg-white rounded-2xl shadow p-6 grid grid-cols-1 md:grid-cols-4 gap-4">
|
| 166 |
<div className="md:col-span-2">
|
|
|
|
| 161 |
|
| 162 |
return (
|
| 163 |
<div className="space-y-6">
|
| 164 |
+
{/* Info Card */}
|
| 165 |
+
<div className="bg-gradient-to-r from-emerald-50 to-teal-50 border border-emerald-100 p-4 rounded-xl flex items-start gap-3">
|
| 166 |
+
<div className="p-2 bg-emerald-100 rounded-lg text-emerald-600">
|
| 167 |
+
<Briefcase className="w-5 h-5" />
|
| 168 |
+
</div>
|
| 169 |
+
<div>
|
| 170 |
+
<h3 className="font-bold text-emerald-900 text-sm">Рабочие Пространства (Tenants)</h3>
|
| 171 |
+
<p className="text-xs text-emerald-700 mt-1 leading-relaxed">
|
| 172 |
+
Здесь управляются подписки клиентов. Каждый Tenant — это отдельная компания или инстанс, в котором работают пользователи.
|
| 173 |
+
Вы можете менять тарифный план, продлевать подписку или блокировать доступ всему пространству.
|
| 174 |
+
</p>
|
| 175 |
+
</div>
|
| 176 |
+
</div>
|
| 177 |
+
|
| 178 |
{/* Filters */}
|
| 179 |
<div className="bg-white rounded-2xl shadow p-6 grid grid-cols-1 md:grid-cols-4 gap-4">
|
| 180 |
<div className="md:col-span-2">
|
frontend/components/admin/UsersTab.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
|
| 2 |
import { useState, useEffect } from 'react'
|
| 3 |
-
import { Search, Shield, User as UserIcon, LogIn, Check, X, Ban } from 'lucide-react'
|
| 4 |
import { useToast } from '@/contexts/ToastContext'
|
| 5 |
|
| 6 |
interface User {
|
|
@@ -23,6 +23,17 @@ export default function UsersTab() {
|
|
| 23 |
const [searchQuery, setSearchQuery] = useState('')
|
| 24 |
const toast = useToast()
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
useEffect(() => {
|
| 27 |
loadUsers()
|
| 28 |
}, [])
|
|
@@ -42,29 +53,97 @@ export default function UsersTab() {
|
|
| 42 |
}
|
| 43 |
}
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
const handleImpersonate = async (userId: string) => {
|
| 46 |
if (!confirm('Вы уверены, что хотите войти под этим пользователем?')) return
|
| 47 |
-
|
| 48 |
try {
|
| 49 |
const res = await fetch(`/api/v1/admin/users/${userId}/impersonate`, {
|
| 50 |
method: 'POST',
|
| 51 |
headers: { 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` }
|
| 52 |
})
|
| 53 |
-
|
| 54 |
if (res.ok) {
|
| 55 |
const data = await res.json()
|
| 56 |
-
// Save token and reload page (which will auto-login as new user)
|
| 57 |
localStorage.setItem('auth_token', data.access_token)
|
| 58 |
toast.success('Успех', 'Вход выполнен! Перенаправление...')
|
| 59 |
-
setTimeout(() =>
|
| 60 |
-
window.location.href = '/dashboard'
|
| 61 |
-
}, 1000)
|
| 62 |
-
} else {
|
| 63 |
-
toast.error('Ошибка', 'Не удалось войти')
|
| 64 |
}
|
| 65 |
-
} catch (error) {
|
| 66 |
-
toast.error('Ошибка', 'Ошибка сети')
|
| 67 |
-
}
|
| 68 |
}
|
| 69 |
|
| 70 |
const filteredUsers = users.filter(u =>
|
|
@@ -76,6 +155,22 @@ export default function UsersTab() {
|
|
| 76 |
|
| 77 |
return (
|
| 78 |
<div className="space-y-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
{/* Search */}
|
| 80 |
<div className="bg-white rounded-2xl p-4 shadow-sm border border-slate-200">
|
| 81 |
<div className="relative">
|
|
@@ -84,7 +179,7 @@ export default function UsersTab() {
|
|
| 84 |
type="text"
|
| 85 |
value={searchQuery}
|
| 86 |
onChange={(e) => setSearchQuery(e.target.value)}
|
| 87 |
-
placeholder="Поиск пользователей..."
|
| 88 |
className="w-full pl-10 pr-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500 outline-none"
|
| 89 |
/>
|
| 90 |
</div>
|
|
@@ -96,10 +191,8 @@ export default function UsersTab() {
|
|
| 96 |
<thead className="bg-slate-50">
|
| 97 |
<tr>
|
| 98 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase">Пользователь</th>
|
| 99 |
-
<th className="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase">
|
| 100 |
-
<th className="px-6 py-4 text-
|
| 101 |
-
<th className="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase">Статус</th>
|
| 102 |
-
<th className="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase">Действия</th>
|
| 103 |
</tr>
|
| 104 |
</thead>
|
| 105 |
<tbody className="divide-y divide-slate-100">
|
|
@@ -111,47 +204,55 @@ export default function UsersTab() {
|
|
| 111 |
{user.full_name?.[0] || user.email?.[0]?.toUpperCase() || '?'}
|
| 112 |
</div>
|
| 113 |
<div>
|
| 114 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
<p className="text-xs text-slate-500">{user.email}</p>
|
|
|
|
| 116 |
</div>
|
| 117 |
</div>
|
| 118 |
</td>
|
| 119 |
-
<td className="px-6 py-4 text-sm text-slate-600">
|
| 120 |
-
{user.tenant_name}
|
| 121 |
-
</td>
|
| 122 |
<td className="px-6 py-4">
|
| 123 |
-
<
|
| 124 |
-
? 'bg-
|
| 125 |
-
|
| 126 |
-
}`}>
|
| 127 |
-
{user.is_superuser ? 'ADMIN' : user.role}
|
| 128 |
-
</span>
|
| 129 |
-
{user.partner_status && (
|
| 130 |
-
<span className="ml-2 px-2 py-1 bg-amber-100 text-amber-700 rounded text-xs font-bold">
|
| 131 |
-
PARTNER
|
| 132 |
</span>
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
<span className="text-emerald-600 text-
|
| 139 |
-
|
| 140 |
</span>
|
| 141 |
-
|
| 142 |
-
<span className="text-orange-500 text-xs">Не верифицирован</span>
|
| 143 |
-
)}
|
| 144 |
</div>
|
| 145 |
</td>
|
| 146 |
-
<td className="px-6 py-4">
|
| 147 |
-
<
|
| 148 |
-
onClick={() =>
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
</td>
|
| 156 |
</tr>
|
| 157 |
))}
|
|
@@ -159,6 +260,76 @@ export default function UsersTab() {
|
|
| 159 |
</table>
|
| 160 |
</div>
|
| 161 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
</div>
|
| 163 |
)
|
| 164 |
}
|
|
|
|
| 1 |
|
| 2 |
import { useState, useEffect } from 'react'
|
| 3 |
+
import { Search, Shield, User as UserIcon, LogIn, Check, X, Ban, Edit, Trash, Handshake } from 'lucide-react'
|
| 4 |
import { useToast } from '@/contexts/ToastContext'
|
| 5 |
|
| 6 |
interface User {
|
|
|
|
| 23 |
const [searchQuery, setSearchQuery] = useState('')
|
| 24 |
const toast = useToast()
|
| 25 |
|
| 26 |
+
// Edit Modal State
|
| 27 |
+
const [selectedUser, setSelectedUser] = useState<User | null>(null)
|
| 28 |
+
const [showEditModal, setShowEditModal] = useState(false)
|
| 29 |
+
const [editRole, setEditRole] = useState('')
|
| 30 |
+
const [editActive, setEditActive] = useState(true)
|
| 31 |
+
const [editVerified, setEditVerified] = useState(false)
|
| 32 |
+
|
| 33 |
+
// Partner Promo State
|
| 34 |
+
const [showPartnerModal, setShowPartnerModal] = useState(false)
|
| 35 |
+
const [partnerCompanyName, setPartnerCompanyName] = useState('')
|
| 36 |
+
|
| 37 |
useEffect(() => {
|
| 38 |
loadUsers()
|
| 39 |
}, [])
|
|
|
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
| 56 |
+
const deleteUser = async (userId: string) => {
|
| 57 |
+
if (!confirm('ВНИМАНИЕ: Это удалит пользователя и ВСЕ его данные НАВСЕГДА. Продолжить?')) return
|
| 58 |
+
try {
|
| 59 |
+
const res = await fetch(`/api/v1/admin/users/${userId}`, {
|
| 60 |
+
method: 'DELETE',
|
| 61 |
+
headers: { 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` }
|
| 62 |
+
})
|
| 63 |
+
if (res.ok) {
|
| 64 |
+
toast.success('Удалено', 'Пользователь удален')
|
| 65 |
+
loadUsers()
|
| 66 |
+
} else {
|
| 67 |
+
toast.error('Ошибка', 'Не удалось удалить')
|
| 68 |
+
}
|
| 69 |
+
} catch (e) { toast.error('Error', 'Network error') }
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
const openEditModal = (user: User) => {
|
| 73 |
+
setSelectedUser(user)
|
| 74 |
+
setEditRole(user.role)
|
| 75 |
+
setEditActive(user.is_active)
|
| 76 |
+
setEditVerified(user.is_verified)
|
| 77 |
+
setShowEditModal(true)
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
const saveUserChanges = async () => {
|
| 81 |
+
if (!selectedUser) return
|
| 82 |
+
try {
|
| 83 |
+
const res = await fetch(`/api/v1/admin/users/${selectedUser.id}`, {
|
| 84 |
+
method: 'PATCH',
|
| 85 |
+
headers: {
|
| 86 |
+
'Content-Type': 'application/json',
|
| 87 |
+
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`
|
| 88 |
+
},
|
| 89 |
+
body: JSON.stringify({
|
| 90 |
+
role: editRole,
|
| 91 |
+
is_active: editActive,
|
| 92 |
+
is_verified: editVerified
|
| 93 |
+
})
|
| 94 |
+
})
|
| 95 |
+
if (res.ok) {
|
| 96 |
+
toast.success('Обновлено', 'Данные пользователя обновлены')
|
| 97 |
+
setShowEditModal(false)
|
| 98 |
+
loadUsers()
|
| 99 |
+
}
|
| 100 |
+
} catch (e) { toast.error('Error', 'Network error') }
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
const openPartnerModal = (user: User) => {
|
| 104 |
+
setSelectedUser(user)
|
| 105 |
+
setPartnerCompanyName(user.tenant_name || '') // Default to Tenant name
|
| 106 |
+
setShowPartnerModal(true)
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
const promoteToPartner = async () => {
|
| 110 |
+
if (!selectedUser) return
|
| 111 |
+
try {
|
| 112 |
+
const res = await fetch(`/api/v1/admin/users/${selectedUser.id}/partner`, {
|
| 113 |
+
method: 'POST',
|
| 114 |
+
headers: {
|
| 115 |
+
'Content-Type': 'application/json',
|
| 116 |
+
'Authorization': `Bearer ${localStorage.getItem('auth_token')}`
|
| 117 |
+
},
|
| 118 |
+
body: JSON.stringify({
|
| 119 |
+
company_name: partnerCompanyName
|
| 120 |
+
})
|
| 121 |
+
})
|
| 122 |
+
if (res.ok) {
|
| 123 |
+
toast.success('Готово', 'Пользователь теперь Партнер!')
|
| 124 |
+
setShowPartnerModal(false)
|
| 125 |
+
loadUsers()
|
| 126 |
+
} else {
|
| 127 |
+
const err = await res.json()
|
| 128 |
+
toast.error('Ошибка', err.detail || 'Не удалось создать партнера')
|
| 129 |
+
}
|
| 130 |
+
} catch (e) { toast.error('Error', 'Network error') }
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
const handleImpersonate = async (userId: string) => {
|
| 134 |
if (!confirm('Вы уверены, что хотите войти под этим пользователем?')) return
|
|
|
|
| 135 |
try {
|
| 136 |
const res = await fetch(`/api/v1/admin/users/${userId}/impersonate`, {
|
| 137 |
method: 'POST',
|
| 138 |
headers: { 'Authorization': `Bearer ${localStorage.getItem('auth_token')}` }
|
| 139 |
})
|
|
|
|
| 140 |
if (res.ok) {
|
| 141 |
const data = await res.json()
|
|
|
|
| 142 |
localStorage.setItem('auth_token', data.access_token)
|
| 143 |
toast.success('Успех', 'Вход выполнен! Перенаправление...')
|
| 144 |
+
setTimeout(() => window.location.href = '/dashboard', 1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
}
|
| 146 |
+
} catch (error) { toast.error('Ошибка', 'Ошибка сети') }
|
|
|
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
const filteredUsers = users.filter(u =>
|
|
|
|
| 155 |
|
| 156 |
return (
|
| 157 |
<div className="space-y-6">
|
| 158 |
+
{/* Info Card */}
|
| 159 |
+
<div className="bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-100 p-4 rounded-xl flex items-start gap-3">
|
| 160 |
+
<div className="p-2 bg-blue-100 rounded-lg text-blue-600">
|
| 161 |
+
<UserIcon className="w-5 h-5" />
|
| 162 |
+
</div>
|
| 163 |
+
<div>
|
| 164 |
+
<h3 className="font-bold text-blue-900 text-sm">Пользователи и Аккаунты</h3>
|
| 165 |
+
<p className="text-xs text-blue-700 mt-1 leading-relaxed">
|
| 166 |
+
Здесь список всех зарегистрированных пользователей. Каждый пользователь привязан к "Тенанту" (Рабочему пространству).
|
| 167 |
+
Вы можете менять их роли, блокировать доступ или повышать до Партнеров (реферальная программа).
|
| 168 |
+
<br />
|
| 169 |
+
<strong>Внимание:</strong> Удаление пользователя необратимо стирает его данные.
|
| 170 |
+
</p>
|
| 171 |
+
</div>
|
| 172 |
+
</div>
|
| 173 |
+
|
| 174 |
{/* Search */}
|
| 175 |
<div className="bg-white rounded-2xl p-4 shadow-sm border border-slate-200">
|
| 176 |
<div className="relative">
|
|
|
|
| 179 |
type="text"
|
| 180 |
value={searchQuery}
|
| 181 |
onChange={(e) => setSearchQuery(e.target.value)}
|
| 182 |
+
placeholder="Поиск пользователей (email, имя)..."
|
| 183 |
className="w-full pl-10 pr-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500 outline-none"
|
| 184 |
/>
|
| 185 |
</div>
|
|
|
|
| 191 |
<thead className="bg-slate-50">
|
| 192 |
<tr>
|
| 193 |
<th className="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase">Пользователь</th>
|
| 194 |
+
<th className="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase">Роль / Статус</th>
|
| 195 |
+
<th className="px-6 py-4 text-right text-xs font-bold text-slate-500 uppercase">Действия</th>
|
|
|
|
|
|
|
| 196 |
</tr>
|
| 197 |
</thead>
|
| 198 |
<tbody className="divide-y divide-slate-100">
|
|
|
|
| 204 |
{user.full_name?.[0] || user.email?.[0]?.toUpperCase() || '?'}
|
| 205 |
</div>
|
| 206 |
<div>
|
| 207 |
+
<div className="flex items-center gap-2">
|
| 208 |
+
<p className="font-semibold text-slate-900">{user.full_name || 'Без имени'}</p>
|
| 209 |
+
{user.partner_status && (
|
| 210 |
+
<span className="px-1.5 py-0.5 bg-amber-100 text-amber-700 rounded text-[10px] font-bold border border-amber-200">PARTNER</span>
|
| 211 |
+
)}
|
| 212 |
+
</div>
|
| 213 |
<p className="text-xs text-slate-500">{user.email}</p>
|
| 214 |
+
<p className="text-[10px] text-slate-400 mt-0.5">Tenant: {user.tenant_name}</p>
|
| 215 |
</div>
|
| 216 |
</div>
|
| 217 |
</td>
|
|
|
|
|
|
|
|
|
|
| 218 |
<td className="px-6 py-4">
|
| 219 |
+
<div className="flex flex-col gap-1 items-start">
|
| 220 |
+
<span className={`px-2 py-1 rounded text-xs font-bold ${user.is_active ? 'bg-emerald-100 text-emerald-700' : 'bg-red-100 text-red-700'}`}>
|
| 221 |
+
{user.is_active ? 'АКТИВЕН' : 'ЗАБЛОКИРОВАН'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
</span>
|
| 223 |
+
<span className="text-xs text-slate-500 font-mono">
|
| 224 |
+
Role: {user.is_superuser ? 'SUPER ADMIN' : user.role}
|
| 225 |
+
</span>
|
| 226 |
+
<div className="flex items-center gap-1 text-[10px]">
|
| 227 |
+
{user.is_verified ? <Check className="w-3 h-3 text-emerald-500" /> : <X className="w-3 h-3 text-orange-500" />}
|
| 228 |
+
<span className={user.is_verified ? "text-emerald-600" : "text-orange-500"}>
|
| 229 |
+
{user.is_verified ? 'Email подтвержден' : 'Email не подтвержден'}
|
| 230 |
</span>
|
| 231 |
+
</div>
|
|
|
|
|
|
|
| 232 |
</div>
|
| 233 |
</td>
|
| 234 |
+
<td className="px-6 py-4 text-right">
|
| 235 |
+
<div className="flex justify-end gap-2">
|
| 236 |
+
<button onClick={() => openEditModal(user)} className="p-2 text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 rounded-lg transition-colors" title="Редактировать">
|
| 237 |
+
<Edit className="w-4 h-4" />
|
| 238 |
+
</button>
|
| 239 |
+
|
| 240 |
+
{!user.partner_status && (
|
| 241 |
+
<button onClick={() => openPartnerModal(user)} className="p-2 text-slate-400 hover:text-amber-600 hover:bg-amber-50 rounded-lg transition-colors" title="Сделать Партнером">
|
| 242 |
+
<Handshake className="w-4 h-4" />
|
| 243 |
+
</button>
|
| 244 |
+
)}
|
| 245 |
+
|
| 246 |
+
<button onClick={() => handleImpersonate(user.id)} className="p-2 text-slate-400 hover:text-white hover:bg-slate-800 rounded-lg transition-colors" title="Во��ти как">
|
| 247 |
+
<LogIn className="w-4 h-4" />
|
| 248 |
+
</button>
|
| 249 |
+
|
| 250 |
+
{!user.is_superuser && (
|
| 251 |
+
<button onClick={() => deleteUser(user.id)} className="p-2 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors" title="Удалить навсегда">
|
| 252 |
+
<Trash className="w-4 h-4" />
|
| 253 |
+
</button>
|
| 254 |
+
)}
|
| 255 |
+
</div>
|
| 256 |
</td>
|
| 257 |
</tr>
|
| 258 |
))}
|
|
|
|
| 260 |
</table>
|
| 261 |
</div>
|
| 262 |
</div>
|
| 263 |
+
|
| 264 |
+
{/* Edit Modal */}
|
| 265 |
+
{showEditModal && selectedUser && (
|
| 266 |
+
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4">
|
| 267 |
+
<div className="bg-white rounded-2xl w-full max-w-md shadow-2xl overflow-hidden animate-in fade-in zoom-in duration-200">
|
| 268 |
+
<div className="p-4 border-b border-slate-100 flex justify-between items-center bg-slate-50/50">
|
| 269 |
+
<h3 className="font-bold text-lg">Редактирование</h3>
|
| 270 |
+
<button onClick={() => setShowEditModal(false)} className="p-1 hover:bg-slate-200 rounded-full"><X className="w-5 h-5" /></button>
|
| 271 |
+
</div>
|
| 272 |
+
<div className="p-6 space-y-4">
|
| 273 |
+
<div>
|
| 274 |
+
<label className="text-xs font-bold text-slate-500 uppercase block mb-1">Роль</label>
|
| 275 |
+
<select value={editRole} onChange={e => setEditRole(e.target.value)} className="w-full border rounded-lg p-2.5 bg-slate-50 focus:bg-white transition-colors">
|
| 276 |
+
<option value="OWNER">Owner</option>
|
| 277 |
+
<option value="MANAGER">Manager</option>
|
| 278 |
+
<option value="admin">Admin (Superuser)</option>
|
| 279 |
+
</select>
|
| 280 |
+
</div>
|
| 281 |
+
<div className="flex items-center gap-3 p-3 border rounded-lg hover:bg-slate-50 cursor-pointer" onClick={() => setEditActive(!editActive)}>
|
| 282 |
+
<div className={`w-10 h-6 rounded-full p-1 transition-colors ${editActive ? 'bg-emerald-500' : 'bg-slate-300'}`}>
|
| 283 |
+
<div className={`w-4 h-4 bg-white rounded-full shadow-sm transition-transform ${editActive ? 'translate-x-4' : ''}`} />
|
| 284 |
+
</div>
|
| 285 |
+
<span className="font-medium text-sm">Активный аккаунт</span>
|
| 286 |
+
</div>
|
| 287 |
+
<div className="flex items-center gap-3 p-3 border rounded-lg hover:bg-slate-50 cursor-pointer" onClick={() => setEditVerified(!editVerified)}>
|
| 288 |
+
<div className={`w-10 h-6 rounded-full p-1 transition-colors ${editVerified ? 'bg-indigo-500' : 'bg-slate-300'}`}>
|
| 289 |
+
<div className={`w-4 h-4 bg-white rounded-full shadow-sm transition-transform ${editVerified ? 'translate-x-4' : ''}`} />
|
| 290 |
+
</div>
|
| 291 |
+
<span className="font-medium text-sm">Email подтвержден</span>
|
| 292 |
+
</div>
|
| 293 |
+
</div>
|
| 294 |
+
<div className="p-4 border-t border-slate-100 flex justify-end gap-2 bg-slate-50/50">
|
| 295 |
+
<button onClick={() => setShowEditModal(false)} className="px-4 py-2 text-slate-600 hover:bg-slate-200 rounded-lg font-medium text-sm">Отмена</button>
|
| 296 |
+
<button onClick={saveUserChanges} className="px-4 py-2 bg-indigo-600 text-white hover:bg-indigo-700 rounded-lg font-bold text-sm shadow-lg shadow-indigo-600/20">Сохранить</button>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
</div>
|
| 300 |
+
)}
|
| 301 |
+
|
| 302 |
+
{/* Partner Modal */}
|
| 303 |
+
{showPartnerModal && selectedUser && (
|
| 304 |
+
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4">
|
| 305 |
+
<div className="bg-white rounded-2xl w-full max-w-md shadow-2xl overflow-hidden">
|
| 306 |
+
<div className="p-4 border-b border-slate-100 flex justify-between items-center bg-amber-50">
|
| 307 |
+
<h3 className="font-bold text-lg text-amber-900">Новый Партнер</h3>
|
| 308 |
+
<button onClick={() => setShowPartnerModal(false)} className="p-1 hover:bg-amber-100 rounded-full text-amber-900"><X className="w-5 h-5" /></button>
|
| 309 |
+
</div>
|
| 310 |
+
<div className="p-6 space-y-4">
|
| 311 |
+
<p className="text-sm text-slate-600">
|
| 312 |
+
Вы собираетесь сделать пользователя <strong>{selectedUser.email}</strong> партнером.
|
| 313 |
+
Им будет выдан доступ к партнерскому кабинету и реферальная ссылка.
|
| 314 |
+
</p>
|
| 315 |
+
<div>
|
| 316 |
+
<label className="text-xs font-bold text-slate-500 uppercase block mb-1">Название Компании / Имя</label>
|
| 317 |
+
<input
|
| 318 |
+
type="text"
|
| 319 |
+
value={partnerCompanyName}
|
| 320 |
+
onChange={e => setPartnerCompanyName(e.target.value)}
|
| 321 |
+
className="w-full border rounded-lg p-2.5 focus:ring-2 focus:ring-amber-500 outline-none"
|
| 322 |
+
placeholder="Например: Агентство Ромашка"
|
| 323 |
+
/>
|
| 324 |
+
</div>
|
| 325 |
+
</div>
|
| 326 |
+
<div className="p-4 border-t border-slate-100 flex justify-end gap-2 bg-slate-50">
|
| 327 |
+
<button onClick={() => setShowPartnerModal(false)} className="px-4 py-2 text-slate-600 hover:bg-slate-200 rounded-lg font-medium text-sm">Отмена</button>
|
| 328 |
+
<button onClick={promoteToPartner} className="px-4 py-2 bg-amber-500 text-white hover:bg-amber-600 rounded-lg font-bold text-sm shadow-lg shadow-amber-500/20">Создать Партнера</button>
|
| 329 |
+
</div>
|
| 330 |
+
</div>
|
| 331 |
+
</div>
|
| 332 |
+
)}
|
| 333 |
</div>
|
| 334 |
)
|
| 335 |
}
|