mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 18:31:12 -05:00
Refactor: Redesign admin panel
This commit is contained in:
@@ -4,38 +4,26 @@ import { ProfileManager } from '@/components/moderation/ProfileManager';
|
|||||||
import { UserRoleManager } from '@/components/moderation/UserRoleManager';
|
import { UserRoleManager } from '@/components/moderation/UserRoleManager';
|
||||||
import { Users, Shield, UserCheck, UserX } from 'lucide-react';
|
import { Users, Shield, UserCheck, UserX } from 'lucide-react';
|
||||||
export function UserManagement() {
|
export function UserManagement() {
|
||||||
return <div className="space-y-6">
|
return (
|
||||||
|
<Tabs defaultValue="profiles" className="space-y-4">
|
||||||
|
<TabsList className="grid w-full grid-cols-2">
|
||||||
|
<TabsTrigger value="profiles" className="flex items-center gap-2">
|
||||||
|
<UserCheck className="w-4 h-4" />
|
||||||
|
Users
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="roles" className="flex items-center gap-2">
|
||||||
|
<Shield className="w-4 h-4" />
|
||||||
|
Roles
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
<TabsContent value="profiles" className="mt-4">
|
||||||
|
<ProfileManager />
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
<Tabs defaultValue="profiles" className="space-y-4">
|
<TabsContent value="roles" className="mt-4">
|
||||||
<TabsList className="grid w-full grid-cols-2">
|
<UserRoleManager />
|
||||||
<TabsTrigger value="profiles" className="flex items-center gap-2">
|
</TabsContent>
|
||||||
<UserCheck className="w-4 h-4" />
|
</Tabs>
|
||||||
Users
|
);
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger value="roles" className="flex items-center gap-2">
|
|
||||||
<Shield className="w-4 h-4" />
|
|
||||||
Roles
|
|
||||||
</TabsTrigger>
|
|
||||||
</TabsList>
|
|
||||||
|
|
||||||
<TabsContent value="profiles">
|
|
||||||
<Card>
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<ProfileManager />
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</TabsContent>
|
|
||||||
|
|
||||||
<TabsContent value="roles">
|
|
||||||
<Card>
|
|
||||||
|
|
||||||
<CardContent>
|
|
||||||
<UserRoleManager />
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</TabsContent>
|
|
||||||
</Tabs>
|
|
||||||
</div>;
|
|
||||||
}
|
}
|
||||||
@@ -27,26 +27,23 @@ export function AdminHeader({ onRefresh }: { onRefresh?: () => void }) {
|
|||||||
const pageTitle = isSettingsPage ? 'Admin Settings' : 'Admin Dashboard';
|
const pageTitle = isSettingsPage ? 'Admin Settings' : 'Admin Dashboard';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="sticky top-0 z-50 w-full border-b border-border bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
|
<header className="sticky top-0 z-50 w-full border-b border-border/50 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
|
||||||
<div className="container flex h-16 items-center justify-between px-4">
|
<div className="container flex h-14 items-center justify-between px-4 max-w-7xl">
|
||||||
{/* Left Section - Navigation */}
|
{/* Left Section - Navigation */}
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-3">
|
||||||
<Button variant="ghost" size="sm" asChild>
|
<Button variant="ghost" size="sm" asChild>
|
||||||
<Link to={backLink} className="flex items-center gap-2">
|
<Link to={backLink} className="flex items-center gap-2">
|
||||||
<ArrowLeft className="w-4 h-4" />
|
<ArrowLeft className="w-4 h-4" />
|
||||||
<span className="hidden sm:inline">{backText}</span>
|
<span className="hidden sm:inline text-sm">{backText}</span>
|
||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<div className="h-6 w-px bg-border hidden sm:block" />
|
<div className="h-4 w-px bg-border/50 hidden sm:block" />
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
<h1 className="text-base font-semibold">
|
||||||
<Shield className="w-6 h-6 text-primary" />
|
<span className="sm:hidden">Admin</span>
|
||||||
<h1 className="text-lg font-semibold">
|
<span className="hidden sm:inline">{pageTitle}</span>
|
||||||
<span className="sm:hidden">Admin</span>
|
</h1>
|
||||||
<span className="hidden sm:inline">{pageTitle}</span>
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right Section - Admin actions */}
|
{/* Right Section - Admin actions */}
|
||||||
@@ -94,16 +91,16 @@ export function AdminHeader({ onRefresh }: { onRefresh?: () => void }) {
|
|||||||
size="sm"
|
size="sm"
|
||||||
onClick={onRefresh}
|
onClick={onRefresh}
|
||||||
title="Refresh admin data"
|
title="Refresh admin data"
|
||||||
className="hidden md:flex"
|
className="hidden md:flex gap-2"
|
||||||
>
|
>
|
||||||
<RefreshCw className="w-4 h-4" />
|
<RefreshCw className="w-4 h-4" />
|
||||||
<span className="hidden sm:ml-2 sm:inline">Refresh</span>
|
<span className="text-sm">Refresh</span>
|
||||||
</Button>
|
</Button>
|
||||||
{permissions?.role_level === 'superuser' && !isSettingsPage && (
|
{permissions?.role_level === 'superuser' && !isSettingsPage && (
|
||||||
<Button variant="ghost" size="sm" asChild className="hidden md:flex">
|
<Button variant="ghost" size="sm" asChild className="hidden md:flex gap-2">
|
||||||
<Link to="/admin/settings">
|
<Link to="/admin/settings">
|
||||||
<Settings className="w-4 h-4" />
|
<Settings className="w-4 h-4" />
|
||||||
<span className="hidden sm:ml-2 sm:inline">Settings</span>
|
<span className="text-sm">Settings</span>
|
||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -264,32 +264,32 @@ export function ProfileManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-4">
|
||||||
{/* Filters */}
|
{/* Filters - compact single row */}
|
||||||
<div className="flex flex-col sm:flex-row gap-4">
|
<div className="flex flex-col sm:flex-row gap-3">
|
||||||
<div className="relative flex-1">
|
<div className="relative flex-1">
|
||||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground w-4 h-4" />
|
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground w-4 h-4" />
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search users..."
|
placeholder="Search users..."
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onChange={(e) => setSearchTerm(e.target.value)}
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
className="pl-10"
|
className="pl-10 h-9"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Select value={statusFilter} onValueChange={(value: 'all' | 'active' | 'banned') => setStatusFilter(value)}>
|
<Select value={statusFilter} onValueChange={(value: 'all' | 'active' | 'banned') => setStatusFilter(value)}>
|
||||||
<SelectTrigger className="w-full sm:w-[180px]">
|
<SelectTrigger className="w-full sm:w-[140px] h-9">
|
||||||
<SelectValue />
|
<SelectValue />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="all">All Users</SelectItem>
|
<SelectItem value="all">All Status</SelectItem>
|
||||||
<SelectItem value="active">Active</SelectItem>
|
<SelectItem value="active">Active</SelectItem>
|
||||||
<SelectItem value="banned">Banned</SelectItem>
|
<SelectItem value="banned">Banned</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
<Select value={roleFilter} onValueChange={(value: 'all' | UserRole) => setRoleFilter(value)}>
|
<Select value={roleFilter} onValueChange={(value: 'all' | UserRole) => setRoleFilter(value)}>
|
||||||
<SelectTrigger className="w-full sm:w-[180px]">
|
<SelectTrigger className="w-full sm:w-[140px] h-9">
|
||||||
<SelectValue />
|
<SelectValue />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@@ -305,49 +305,51 @@ export function ProfileManager() {
|
|||||||
{/* Users List */}
|
{/* Users List */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="flex items-center justify-center py-8">
|
<div className="flex items-center justify-center py-8">
|
||||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
<div className="animate-spin rounded-full h-6 w-6 border-b-2 border-primary"></div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid gap-4">
|
<div className="space-y-2">
|
||||||
{filteredProfiles.map((profile) => (
|
{filteredProfiles.map((profile) => (
|
||||||
<Card key={profile.id}>
|
<Card key={profile.id} className="border-border/50 hover:border-border transition-colors">
|
||||||
<CardContent className="p-6">
|
<CardContent className="p-4">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between gap-4">
|
||||||
<div className="flex items-center space-x-4">
|
<div className="flex items-center gap-3 min-w-0 flex-1">
|
||||||
<Avatar className="w-12 h-12">
|
<Avatar className="w-10 h-10 flex-shrink-0">
|
||||||
<AvatarImage src={profile.avatar_url} alt={profile.username} />
|
<AvatarImage src={profile.avatar_url} alt={profile.username} />
|
||||||
<AvatarFallback>
|
<AvatarFallback className="text-xs">
|
||||||
{profile.display_name?.[0] || profile.username[0]}
|
{profile.display_name?.[0] || profile.username[0]}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
|
|
||||||
<div>
|
<div className="min-w-0 flex-1">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
<h3 className="font-medium">{profile.display_name || profile.username}</h3>
|
<h3 className="font-medium text-sm truncate">{profile.display_name || profile.username}</h3>
|
||||||
{profile.banned && (
|
{profile.banned && (
|
||||||
<Badge variant="destructive" className="text-xs">
|
<Badge variant="destructive" className="text-xs h-5">
|
||||||
<Ban className="w-3 h-3 mr-1" />
|
<Ban className="w-3 h-3 mr-1" />
|
||||||
Banned
|
Banned
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-muted-foreground">@{profile.username}</p>
|
<div className="flex items-center gap-2 mt-0.5 flex-wrap">
|
||||||
<div className="flex gap-2 mt-1">
|
<p className="text-xs text-muted-foreground">@{profile.username}</p>
|
||||||
{profile.roles.length > 0 ? (
|
<div className="flex gap-1.5">
|
||||||
profile.roles.map((role) => (
|
{profile.roles.length > 0 ? (
|
||||||
<Badge key={role} variant="secondary" className="text-xs">
|
profile.roles.map((role) => (
|
||||||
{role}
|
<Badge key={role} variant="secondary" className="text-xs h-5">
|
||||||
</Badge>
|
{role}
|
||||||
))
|
</Badge>
|
||||||
) : (
|
))
|
||||||
<Badge variant="outline" className="text-xs">User</Badge>
|
) : (
|
||||||
)}
|
<Badge variant="outline" className="text-xs h-5">User</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{canManageUser(profile) && (
|
{canManageUser(profile) && (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2 flex-shrink-0">
|
||||||
{/* Ban/Unban Button */}
|
{/* Ban/Unban Button */}
|
||||||
{permissions.can_ban_any_user && (
|
{permissions.can_ban_any_user && (
|
||||||
<AlertDialog>
|
<AlertDialog>
|
||||||
@@ -355,17 +357,18 @@ export function ProfileManager() {
|
|||||||
<Button
|
<Button
|
||||||
variant={profile.banned ? "outline" : "destructive"}
|
variant={profile.banned ? "outline" : "destructive"}
|
||||||
size="sm"
|
size="sm"
|
||||||
|
className="h-8"
|
||||||
disabled={actionLoading === profile.user_id}
|
disabled={actionLoading === profile.user_id}
|
||||||
>
|
>
|
||||||
{profile.banned ? (
|
{profile.banned ? (
|
||||||
<>
|
<>
|
||||||
<UserCheck className="w-4 h-4 mr-2" />
|
<UserCheck className="w-3 h-3 sm:mr-2" />
|
||||||
Unban
|
<span className="hidden sm:inline">Unban</span>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<UserX className="w-4 h-4 mr-2" />
|
<UserX className="w-3 h-3 sm:mr-2" />
|
||||||
Ban
|
<span className="hidden sm:inline">Ban</span>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -399,18 +402,18 @@ export function ProfileManager() {
|
|||||||
onValueChange={(value) => handleRoleChange(profile.user_id, value as UserRole | 'remove', profile.roles)}
|
onValueChange={(value) => handleRoleChange(profile.user_id, value as UserRole | 'remove', profile.roles)}
|
||||||
disabled={actionLoading === profile.user_id}
|
disabled={actionLoading === profile.user_id}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="w-[140px]">
|
<SelectTrigger className="w-[100px] sm:w-[130px] h-8">
|
||||||
<SelectValue placeholder="Change Role" />
|
<SelectValue placeholder="Role" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="user">Make User</SelectItem>
|
<SelectItem value="user">User</SelectItem>
|
||||||
{permissions.can_manage_moderator_roles && (
|
{permissions.can_manage_moderator_roles && (
|
||||||
<SelectItem value="moderator">Make Moderator</SelectItem>
|
<SelectItem value="moderator">Moderator</SelectItem>
|
||||||
)}
|
)}
|
||||||
{permissions.can_manage_admin_roles && (
|
{permissions.can_manage_admin_roles && (
|
||||||
<SelectItem value="admin">Make Admin</SelectItem>
|
<SelectItem value="admin">Admin</SelectItem>
|
||||||
)}
|
)}
|
||||||
<SelectItem value="remove">Remove Roles</SelectItem>
|
<SelectItem value="remove">Remove</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
)}
|
)}
|
||||||
@@ -422,10 +425,10 @@ export function ProfileManager() {
|
|||||||
))}
|
))}
|
||||||
|
|
||||||
{filteredProfiles.length === 0 && (
|
{filteredProfiles.length === 0 && (
|
||||||
<div className="text-center py-8">
|
<div className="text-center py-12">
|
||||||
<AlertTriangle className="w-16 h-16 text-muted-foreground mx-auto mb-4" />
|
<AlertTriangle className="w-12 h-12 text-muted-foreground mx-auto mb-3" />
|
||||||
<h3 className="text-lg font-semibold mb-2">No Users Found</h3>
|
<h3 className="text-base font-semibold mb-1">No Users Found</h3>
|
||||||
<p className="text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
No users match your current filters.
|
No users match your current filters.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -212,47 +212,44 @@ export const ReportsQueue = forwardRef<ReportsQueueRef>((props, ref) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-4">
|
||||||
{reports.map((report) => (
|
{reports.map((report) => (
|
||||||
<Card key={report.id} className="border-l-4 border-l-red-500">
|
<Card key={report.id} className="border-border/50 relative before:absolute before:left-0 before:top-0 before:bottom-0 before:w-1 before:bg-red-500/50 before:rounded-l">
|
||||||
<CardHeader className="pb-4">
|
<CardHeader className="pb-3 pt-4">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-start justify-between gap-4">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
<Badge variant="destructive">
|
<Badge variant="destructive" className="text-xs">
|
||||||
<Flag className="w-3 h-3 mr-1" />
|
<Flag className="w-3 h-3 mr-1" />
|
||||||
{REPORT_TYPE_LABELS[report.report_type as keyof typeof REPORT_TYPE_LABELS]}
|
{REPORT_TYPE_LABELS[report.report_type as keyof typeof REPORT_TYPE_LABELS]}
|
||||||
</Badge>
|
</Badge>
|
||||||
<Badge variant="outline">
|
<Badge variant="outline" className="text-xs">
|
||||||
{report.reported_entity_type}
|
{report.reported_entity_type}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
<div className="flex items-center gap-1.5 text-xs text-muted-foreground whitespace-nowrap">
|
||||||
<Calendar className="w-4 h-4" />
|
<Calendar className="w-3 h-3" />
|
||||||
{format(new Date(report.created_at), 'MMM d, yyyy HH:mm')}
|
{format(new Date(report.created_at), 'MMM d, HH:mm')}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{report.reporter_profile && (
|
{report.reporter_profile && (
|
||||||
<div className="flex items-center gap-2 text-sm">
|
<div className="flex items-center gap-2 text-xs text-muted-foreground mt-2">
|
||||||
<User className="w-4 h-4 text-muted-foreground" />
|
<User className="w-3 h-3" />
|
||||||
<span>Reported by:</span>
|
<span className="font-medium text-foreground">
|
||||||
<span className="font-medium">
|
|
||||||
{report.reporter_profile.display_name || report.reporter_profile.username}
|
{report.reporter_profile.display_name || report.reporter_profile.username}
|
||||||
</span>
|
</span>
|
||||||
{report.reporter_profile.display_name && (
|
{report.reporter_profile.display_name && (
|
||||||
<span className="text-muted-foreground">
|
<span>@{report.reporter_profile.username}</span>
|
||||||
@{report.reporter_profile.username}
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="space-y-4">
|
<CardContent className="space-y-3 pt-0">
|
||||||
{report.reason && (
|
{report.reason && (
|
||||||
<div>
|
<div>
|
||||||
<Label>Report Reason:</Label>
|
<Label className="text-xs text-muted-foreground">Reason</Label>
|
||||||
<p className="text-sm bg-muted/50 p-3 rounded-lg mt-1">
|
<p className="text-sm bg-muted/30 p-2.5 rounded-lg mt-1">
|
||||||
{report.reason}
|
{report.reason}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -260,17 +257,17 @@ export const ReportsQueue = forwardRef<ReportsQueueRef>((props, ref) => {
|
|||||||
|
|
||||||
{report.reported_content && (
|
{report.reported_content && (
|
||||||
<div>
|
<div>
|
||||||
<Label>Reported Content:</Label>
|
<Label className="text-xs text-muted-foreground">Reported Content</Label>
|
||||||
<div className="bg-destructive/5 border border-destructive/20 p-4 rounded-lg mt-1">
|
<div className="bg-muted/30 border border-border/50 p-3 rounded-lg mt-1">
|
||||||
{report.reported_entity_type === 'review' && (
|
{report.reported_entity_type === 'review' && (
|
||||||
<div>
|
<div>
|
||||||
{report.reported_content.title && (
|
{report.reported_content.title && (
|
||||||
<h4 className="font-semibold mb-2">{report.reported_content.title}</h4>
|
<h4 className="font-medium text-sm mb-1.5">{report.reported_content.title}</h4>
|
||||||
)}
|
)}
|
||||||
{report.reported_content.content && (
|
{report.reported_content.content && (
|
||||||
<p className="text-sm mb-2">{report.reported_content.content}</p>
|
<p className="text-sm text-muted-foreground mb-2">{report.reported_content.content}</p>
|
||||||
)}
|
)}
|
||||||
<div className="text-sm text-muted-foreground">
|
<div className="text-xs text-muted-foreground">
|
||||||
Rating: {report.reported_content.rating}/5
|
Rating: {report.reported_content.rating}/5
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -279,10 +276,11 @@ export const ReportsQueue = forwardRef<ReportsQueueRef>((props, ref) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex gap-2 pt-2">
|
<div className="flex gap-2 pt-1">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleReportAction(report.id, 'reviewed')}
|
onClick={() => handleReportAction(report.id, 'reviewed')}
|
||||||
disabled={actionLoading === report.id}
|
disabled={actionLoading === report.id}
|
||||||
|
size="sm"
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
>
|
>
|
||||||
<CheckCircle className="w-4 h-4 mr-2" />
|
<CheckCircle className="w-4 h-4 mr-2" />
|
||||||
@@ -290,6 +288,7 @@ export const ReportsQueue = forwardRef<ReportsQueueRef>((props, ref) => {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
onClick={() => handleReportAction(report.id, 'dismissed')}
|
onClick={() => handleReportAction(report.id, 'dismissed')}
|
||||||
disabled={actionLoading === report.id}
|
disabled={actionLoading === report.id}
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
|
|||||||
@@ -179,28 +179,30 @@ export function UserRoleManager() {
|
|||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
const filteredRoles = userRoles.filter(role => role.profiles?.username?.toLowerCase().includes(searchTerm.toLowerCase()) || role.profiles?.display_name?.toLowerCase().includes(searchTerm.toLowerCase()) || role.role.toLowerCase().includes(searchTerm.toLowerCase()));
|
const filteredRoles = userRoles.filter(role => role.profiles?.username?.toLowerCase().includes(searchTerm.toLowerCase()) || role.profiles?.display_name?.toLowerCase().includes(searchTerm.toLowerCase()) || role.role.toLowerCase().includes(searchTerm.toLowerCase()));
|
||||||
return <div className="space-y-6">
|
return <div className="space-y-4">
|
||||||
{/* Add new role */}
|
{/* Add new role */}
|
||||||
<Card>
|
<Card className="border-border/50">
|
||||||
|
<CardHeader className="pb-3">
|
||||||
<CardContent className="space-y-4">
|
<CardTitle className="text-base">Grant Role</CardTitle>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-3">
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="user-search">Search Users</Label>
|
<Label htmlFor="user-search" className="text-sm">Search Users</Label>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Search className="absolute left-3 top-3 w-4 h-4 text-muted-foreground" />
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
||||||
<Input id="user-search" placeholder="Search by username or display name..." value={newUserSearch} onChange={e => setNewUserSearch(e.target.value)} className="pl-10" />
|
<Input id="user-search" placeholder="Search by username..." value={newUserSearch} onChange={e => setNewUserSearch(e.target.value)} className="pl-10 h-9 mt-1" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{searchResults.length > 0 && <div className="mt-2 border rounded-lg bg-background">
|
{searchResults.length > 0 && <div className="mt-2 border border-border/50 rounded-lg bg-background max-h-[200px] overflow-y-auto">
|
||||||
{searchResults.map(profile => <div key={profile.user_id} className="p-3 hover:bg-muted/50 cursor-pointer border-b last:border-b-0" onClick={() => {
|
{searchResults.map(profile => <div key={profile.user_id} className="p-2.5 hover:bg-muted/50 cursor-pointer border-b border-border/50 last:border-b-0 text-sm" onClick={() => {
|
||||||
setNewUserSearch(profile.display_name || profile.username);
|
setNewUserSearch(profile.display_name || profile.username);
|
||||||
setSearchResults([profile]);
|
setSearchResults([profile]);
|
||||||
}}>
|
}}>
|
||||||
<div className="font-medium">
|
<div className="font-medium">
|
||||||
{profile.display_name || profile.username}
|
{profile.display_name || profile.username}
|
||||||
</div>
|
</div>
|
||||||
{profile.display_name && <div className="text-sm text-muted-foreground">
|
{profile.display_name && <div className="text-xs text-muted-foreground">
|
||||||
@{profile.username}
|
@{profile.username}
|
||||||
</div>}
|
</div>}
|
||||||
</div>)}
|
</div>)}
|
||||||
@@ -208,10 +210,10 @@ export function UserRoleManager() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="role-select">Role</Label>
|
<Label htmlFor="role-select" className="text-sm">Role</Label>
|
||||||
<Select value={newRole} onValueChange={setNewRole}>
|
<Select value={newRole} onValueChange={setNewRole}>
|
||||||
<SelectTrigger>
|
<SelectTrigger className="h-9 mt-1">
|
||||||
<SelectValue placeholder="Select a role" />
|
<SelectValue placeholder="Select role" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="moderator">Moderator</SelectItem>
|
<SelectItem value="moderator">Moderator</SelectItem>
|
||||||
@@ -226,7 +228,7 @@ export function UserRoleManager() {
|
|||||||
if (selectedUser && newRole) {
|
if (selectedUser && newRole) {
|
||||||
grantRole(selectedUser.user_id, newRole as 'admin' | 'moderator' | 'user');
|
grantRole(selectedUser.user_id, newRole as 'admin' | 'moderator' | 'user');
|
||||||
}
|
}
|
||||||
}} disabled={!newRole || !searchResults.find(p => (p.display_name || p.username) === newUserSearch) || actionLoading === 'grant'} className="w-full md:w-auto">
|
}} disabled={!newRole || !searchResults.find(p => (p.display_name || p.username) === newUserSearch) || actionLoading === 'grant'} size="sm" className="w-full md:w-auto">
|
||||||
{actionLoading === 'grant' ? 'Granting...' : 'Grant Role'}
|
{actionLoading === 'grant' ? 'Granting...' : 'Grant Role'}
|
||||||
</Button>
|
</Button>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -234,39 +236,39 @@ export function UserRoleManager() {
|
|||||||
|
|
||||||
{/* Search existing roles */}
|
{/* Search existing roles */}
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="role-search">Search Existing Roles</Label>
|
<Label htmlFor="role-search" className="text-sm">Search Existing Roles</Label>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Search className="absolute left-3 top-3 w-4 h-4 text-muted-foreground" />
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
||||||
<Input id="role-search" placeholder="Search users with roles..." value={searchTerm} onChange={e => setSearchTerm(e.target.value)} className="pl-10" />
|
<Input id="role-search" placeholder="Search users with roles..." value={searchTerm} onChange={e => setSearchTerm(e.target.value)} className="pl-10 h-9 mt-1" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* User roles list */}
|
{/* User roles list */}
|
||||||
<div className="space-y-3">
|
<div className="space-y-2">
|
||||||
{filteredRoles.length === 0 ? <div className="text-center py-8">
|
{filteredRoles.length === 0 ? <div className="text-center py-12">
|
||||||
<Shield className="w-12 h-12 text-muted-foreground mx-auto mb-4" />
|
<Shield className="w-12 h-12 text-muted-foreground mx-auto mb-3" />
|
||||||
<h3 className="text-lg font-semibold mb-2">No roles found</h3>
|
<h3 className="text-base font-semibold mb-1">No roles found</h3>
|
||||||
<p className="text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
{searchTerm ? 'No users match your search criteria.' : 'No user roles have been granted yet.'}
|
{searchTerm ? 'No users match your search.' : 'No user roles granted yet.'}
|
||||||
</p>
|
</p>
|
||||||
</div> : filteredRoles.map(userRole => <Card key={userRole.id}>
|
</div> : filteredRoles.map(userRole => <Card key={userRole.id} className="border-border/50">
|
||||||
<CardContent className="flex items-center justify-between p-4">
|
<CardContent className="flex items-center justify-between p-3">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3 min-w-0 flex-1">
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<div className="font-medium">
|
<div className="font-medium text-sm truncate">
|
||||||
{userRole.profiles?.display_name || userRole.profiles?.username}
|
{userRole.profiles?.display_name || userRole.profiles?.username}
|
||||||
</div>
|
</div>
|
||||||
{userRole.profiles?.display_name && <div className="text-sm text-muted-foreground">
|
{userRole.profiles?.display_name && <div className="text-xs text-muted-foreground">
|
||||||
@{userRole.profiles.username}
|
@{userRole.profiles.username}
|
||||||
</div>}
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
<Badge variant={userRole.role === 'admin' ? 'default' : 'secondary'}>
|
<Badge variant={userRole.role === 'admin' ? 'default' : 'secondary'} className="text-xs h-5">
|
||||||
{userRole.role}
|
{userRole.role}
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Only show revoke button if current user can manage this role */}
|
{/* Only show revoke button if current user can manage this role */}
|
||||||
{(isSuperuser() || isAdmin() && !['admin', 'superuser'].includes(userRole.role)) && <Button variant="outline" size="sm" onClick={() => revokeRole(userRole.id)} disabled={actionLoading === userRole.id}>
|
{(isSuperuser() || isAdmin() && !['admin', 'superuser'].includes(userRole.role)) && <Button variant="outline" size="sm" onClick={() => revokeRole(userRole.id)} disabled={actionLoading === userRole.id} className="h-8 w-8 p-0 flex-shrink-0">
|
||||||
<X className="w-4 h-4" />
|
<X className="w-4 h-4" />
|
||||||
</Button>}
|
</Button>}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
@@ -79,109 +79,118 @@ export default function Admin() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AdminHeader onRefresh={handleRefresh} />
|
<AdminHeader onRefresh={handleRefresh} />
|
||||||
<div className="container mx-auto px-4 py-8">
|
<div className="container mx-auto px-4 py-8 max-w-7xl">
|
||||||
<div className="space-y-4 mb-8">
|
{/* Refresh status indicator - subtle */}
|
||||||
{/* Refresh status indicator */}
|
<div className="flex items-center gap-2 text-xs text-muted-foreground mb-6">
|
||||||
<div className="flex items-center justify-between">
|
<RefreshCw className="w-3 h-3" />
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
{refreshMode === 'auto' ? (
|
||||||
<RefreshCw className="w-4 h-4" />
|
<span>Auto-refresh: every {pollInterval / 1000}s</span>
|
||||||
{refreshMode === 'auto' ? (
|
) : (
|
||||||
<span>Auto-refresh: every {pollInterval / 1000}s</span>
|
<span>Manual refresh</span>
|
||||||
) : (
|
)}
|
||||||
<span>Manual refresh only</span>
|
{lastUpdated && (
|
||||||
)}
|
<span>• {lastUpdated.toLocaleTimeString()}</span>
|
||||||
{lastUpdated && (
|
)}
|
||||||
<span className="text-xs">
|
</div>
|
||||||
• Last updated: {lastUpdated.toLocaleTimeString()}
|
|
||||||
</span>
|
{/* Stats cards - horizontal layout */}
|
||||||
)}
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-12">
|
||||||
|
<Card className="border-border/50 hover:border-border/80 transition-colors">
|
||||||
|
<CardContent className="p-4">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="p-2 rounded-lg bg-amber-500/10">
|
||||||
|
<FileText className="h-5 w-5 text-amber-700 dark:text-amber-300" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium text-muted-foreground">Pending</p>
|
||||||
|
<p className="text-xs text-muted-foreground/80">Submissions</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-4xl font-bold text-amber-700 dark:text-amber-300">
|
||||||
|
{stats.pendingSubmissions}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card className="border-border/50 hover:border-border/80 transition-colors">
|
||||||
|
<CardContent className="p-4">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="p-2 rounded-lg bg-red-500/10">
|
||||||
|
<Flag className="h-5 w-5 text-red-700 dark:text-red-300" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium text-muted-foreground">Open</p>
|
||||||
|
<p className="text-xs text-muted-foreground/80">Reports</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-4xl font-bold text-red-700 dark:text-red-300">
|
||||||
|
{stats.openReports}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card className="border-border/50 hover:border-border/80 transition-colors">
|
||||||
|
<CardContent className="p-4">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="p-2 rounded-lg bg-orange-500/10">
|
||||||
|
<AlertCircle className="h-5 w-5 text-orange-700 dark:text-orange-300" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-sm font-medium text-muted-foreground">Flagged</p>
|
||||||
|
<p className="text-xs text-muted-foreground/80">Content</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-4xl font-bold text-orange-700 dark:text-orange-300">
|
||||||
|
{stats.flaggedContent}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Content Moderation Section - flatter design */}
|
||||||
|
<div className="space-y-8">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-lg font-semibold mb-4 flex items-center gap-2">
|
||||||
|
<Shield className="w-5 h-5" />
|
||||||
|
Moderation Queue
|
||||||
|
</h2>
|
||||||
|
<Tabs defaultValue="queue" className="space-y-4">
|
||||||
|
<TabsList className="grid w-full grid-cols-2">
|
||||||
|
<TabsTrigger value="queue" className="flex items-center gap-2">
|
||||||
|
<FileText className="w-4 h-4" />
|
||||||
|
{isMobile ? 'Queue' : 'Moderation Queue'}
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="reports" className="flex items-center gap-2">
|
||||||
|
<Flag className="w-4 h-4" />
|
||||||
|
Reports
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
<TabsContent value="queue" className="mt-4">
|
||||||
|
<ModerationQueue ref={moderationQueueRef} />
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
<TabsContent value="reports" className="mt-4">
|
||||||
|
<ReportsQueue ref={reportsQueueRef} />
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* User Management Section - flatter design */}
|
||||||
|
<div>
|
||||||
|
<h2 className="text-lg font-semibold mb-4 flex items-center gap-2">
|
||||||
|
<Users className="w-5 h-5" />
|
||||||
|
User Management
|
||||||
|
</h2>
|
||||||
|
<UserManagement />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Stats cards */}
|
|
||||||
<div className="grid grid-cols-3 gap-3 md:gap-6">
|
|
||||||
<Card>
|
|
||||||
<CardHeader className="flex flex-col items-center justify-center space-y-0 pb-2 text-center">
|
|
||||||
<FileText className="h-4 w-4 text-muted-foreground mb-2" />
|
|
||||||
<CardTitle className="text-sm font-medium">Pending Submissions</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="text-center">
|
|
||||||
<div className="text-2xl font-bold">
|
|
||||||
{stats.pendingSubmissions}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader className="flex flex-col items-center justify-center space-y-0 pb-2 text-center">
|
|
||||||
<Flag className="h-4 w-4 text-muted-foreground mb-2" />
|
|
||||||
<CardTitle className="text-sm font-medium">Open Reports</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="text-center">
|
|
||||||
<div className="text-2xl font-bold">
|
|
||||||
{stats.openReports}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader className="flex flex-col items-center justify-center space-y-0 pb-2 text-center">
|
|
||||||
<AlertCircle className="h-4 w-4 text-muted-foreground mb-2" />
|
|
||||||
<CardTitle className="text-sm font-medium">Flagged Content</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="text-center">
|
|
||||||
<div className="text-2xl font-bold">
|
|
||||||
{stats.flaggedContent}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Content Moderation Section */}
|
|
||||||
<Card className="mb-8">
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle className="flex items-center gap-2">
|
|
||||||
<Shield className="w-5 h-5" />
|
|
||||||
Moderation Queue
|
|
||||||
</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<Tabs defaultValue="queue" className="space-y-6">
|
|
||||||
<TabsList className="grid w-full grid-cols-2">
|
|
||||||
<TabsTrigger value="queue" className="flex items-center gap-2">
|
|
||||||
<FileText className="w-4 h-4" />
|
|
||||||
{isMobile ? 'Queue' : 'Moderation Queue'}
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger value="reports" className="flex items-center gap-2">
|
|
||||||
<Flag className="w-4 h-4" />
|
|
||||||
Reports
|
|
||||||
</TabsTrigger>
|
|
||||||
</TabsList>
|
|
||||||
|
|
||||||
<TabsContent value="queue">
|
|
||||||
<ModerationQueue ref={moderationQueueRef} />
|
|
||||||
</TabsContent>
|
|
||||||
|
|
||||||
<TabsContent value="reports">
|
|
||||||
<ReportsQueue ref={reportsQueueRef} />
|
|
||||||
</TabsContent>
|
|
||||||
</Tabs>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* User Management Section */}
|
|
||||||
<Card className="mb-8">
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle className="flex items-center gap-2">
|
|
||||||
<Users className="w-5 h-5" />
|
|
||||||
User Management
|
|
||||||
</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent>
|
|
||||||
<UserManagement />
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user