|
@@ -77,18 +77,10 @@ export default function AdminUsersPage() {
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
{(() => {
|
|
{(() => {
|
|
|
- const superadminCount = users.filter((u) => u.role === 'superadmin').length
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="space-y-2">
|
|
<div className="space-y-2">
|
|
|
{users.map((user) => {
|
|
{users.map((user) => {
|
|
|
const isSelf = user.id === currentUser?.id
|
|
const isSelf = user.id === currentUser?.id
|
|
|
- const isLastSuperadmin = user.role === 'superadmin' && superadminCount <= 1
|
|
|
|
|
- const roleDisabled = isSelf && (currentUser?.role !== 'superadmin' || isLastSuperadmin)
|
|
|
|
|
- const roleTitle = isSelf
|
|
|
|
|
- ? currentUser?.role !== 'superadmin'
|
|
|
|
|
- ? 'Вы не можете сменить свою роль'
|
|
|
|
|
- : 'Нельзя сменить роль единственного суперадмина'
|
|
|
|
|
- : undefined
|
|
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div key={user.id} className="flex items-center justify-between rounded-lg border border-white/10 bg-white/5 p-4">
|
|
<div key={user.id} className="flex items-center justify-between rounded-lg border border-white/10 bg-white/5 p-4">
|
|
@@ -106,31 +98,28 @@ export default function AdminUsersPage() {
|
|
|
</div>
|
|
</div>
|
|
|
<p className="text-sm text-white/40">{user.email}</p>
|
|
<p className="text-sm text-white/40">{user.email}</p>
|
|
|
</div>
|
|
</div>
|
|
|
- <div className="flex items-center gap-2">
|
|
|
|
|
- <div className="relative" title={roleTitle}>
|
|
|
|
|
|
|
+ {!isSelf && (
|
|
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
<select value={user.role}
|
|
<select value={user.role}
|
|
|
- disabled={roleDisabled}
|
|
|
|
|
onChange={(e) => updateUser(user.id, { role: e.target.value })}
|
|
onChange={(e) => updateUser(user.id, { role: e.target.value })}
|
|
|
- className={`rounded-lg border border-white/10 px-2 py-1.5 text-sm text-white outline-none transition ${
|
|
|
|
|
- roleDisabled ? 'cursor-not-allowed opacity-50' : 'bg-white/5'
|
|
|
|
|
- }`}
|
|
|
|
|
|
|
+ className="rounded-lg border border-white/10 bg-white/5 px-2 py-1.5 text-sm text-white outline-none"
|
|
|
>
|
|
>
|
|
|
{Object.entries(roleLabels).map(([k, v]) => (
|
|
{Object.entries(roleLabels).map(([k, v]) => (
|
|
|
<option key={k} value={k} className="bg-[#1e293b]">{v}</option>
|
|
<option key={k} value={k} className="bg-[#1e293b]">{v}</option>
|
|
|
))}
|
|
))}
|
|
|
</select>
|
|
</select>
|
|
|
|
|
+ <button onClick={() => updateUser(user.id, {
|
|
|
|
|
+ status: user.status === 'banned' ? 'active' : 'banned'
|
|
|
|
|
+ })}
|
|
|
|
|
+ className={`rounded-lg px-3 py-1.5 text-sm transition ${
|
|
|
|
|
+ user.status === 'banned' ? 'bg-green-600/80 text-white hover:bg-green-500' :
|
|
|
|
|
+ 'bg-red-600/80 text-white hover:bg-red-500'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ {user.status === 'banned' ? 'Разблокировать' : 'Заблокировать'}
|
|
|
|
|
+ </button>
|
|
|
</div>
|
|
</div>
|
|
|
- <button onClick={() => updateUser(user.id, {
|
|
|
|
|
- status: user.status === 'banned' ? 'active' : 'banned'
|
|
|
|
|
- })}
|
|
|
|
|
- className={`rounded-lg px-3 py-1.5 text-sm transition ${
|
|
|
|
|
- user.status === 'banned' ? 'bg-green-600/80 text-white hover:bg-green-500' :
|
|
|
|
|
- 'bg-red-600/80 text-white hover:bg-red-500'
|
|
|
|
|
- }`}
|
|
|
|
|
- >
|
|
|
|
|
- {user.status === 'banned' ? 'Разблокировать' : 'Заблокировать'}
|
|
|
|
|
- </button>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ )}
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
|
})}
|
|
})}
|