feat: add CoopCredits Solana media rewards ecosystem
Add complete token system with Plex/Tautulli/Overseer integration: - Anchor program for SPL token mint/burn/transfer - Express backend with OAuth, webhooks, Solana integration - Next.js frontend with dashboard, admin panel, wallet management - Docker deployment for 172.20.1.0/24 infrastructure - Production configs with SSL, Nginx, health monitoring Tautulli webhooks auto-mint on watch events. Overseer integration burns for content requests.
This commit is contained in:
@@ -0,0 +1,333 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useStore } from '@/lib/store';
|
||||
import { adminApi } from '@/lib/api';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import {
|
||||
Users,
|
||||
Settings,
|
||||
Pause,
|
||||
Play,
|
||||
TrendingUp,
|
||||
Search,
|
||||
Gift
|
||||
} from 'lucide-react';
|
||||
import { formatNumber } from '@/lib/utils';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
interface Analytics {
|
||||
users: {
|
||||
total: number;
|
||||
with_wallet: number;
|
||||
new_this_week: number;
|
||||
};
|
||||
transactions: {
|
||||
total_earned: number;
|
||||
total_spent: number;
|
||||
total_transactions: number;
|
||||
};
|
||||
watchStats: {
|
||||
total_seconds: number;
|
||||
total_credits: number;
|
||||
total_events: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface User {
|
||||
id: string;
|
||||
plexUsername: string;
|
||||
email: string | null;
|
||||
isAdmin: boolean;
|
||||
isActive: boolean;
|
||||
walletAddress: string | null;
|
||||
totalEarned: number;
|
||||
totalSpent: number;
|
||||
watchTimeMinutes: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export default function AdminPage() {
|
||||
const router = useRouter();
|
||||
const { user, isAuthenticated } = useStore();
|
||||
const [analytics, setAnalytics] = useState<Analytics | null>(null);
|
||||
const [users, setUsers] = useState<User[]>([]);
|
||||
const [settings, setSettings] = useState<any>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
router.push('/login');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user?.isAdmin) {
|
||||
router.push('/dashboard');
|
||||
return;
|
||||
}
|
||||
|
||||
loadData();
|
||||
}, [isAuthenticated, user, router]);
|
||||
|
||||
const loadData = async () => {
|
||||
try {
|
||||
const [analyticsRes, usersRes, settingsRes] = await Promise.all([
|
||||
adminApi.getAnalytics(),
|
||||
adminApi.getUsers(),
|
||||
adminApi.getSettings()
|
||||
]);
|
||||
|
||||
setAnalytics(analyticsRes.data);
|
||||
setUsers(usersRes.data.users);
|
||||
setSettings(settingsRes.data);
|
||||
} catch (error) {
|
||||
toast.error('Failed to load admin data');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handlePause = async () => {
|
||||
try {
|
||||
await adminApi.pause();
|
||||
toast.success('Minting paused');
|
||||
loadData();
|
||||
} catch (error) {
|
||||
toast.error('Failed to pause minting');
|
||||
}
|
||||
};
|
||||
|
||||
const handleResume = async () => {
|
||||
try {
|
||||
await adminApi.resume();
|
||||
toast.success('Minting resumed');
|
||||
loadData();
|
||||
} catch (error) {
|
||||
toast.error('Failed to resume minting');
|
||||
}
|
||||
};
|
||||
|
||||
const handleGrantBonus = async (userId: string) => {
|
||||
const amount = prompt('Enter bonus amount:');
|
||||
if (!amount) return;
|
||||
|
||||
try {
|
||||
await adminApi.grantBonus(userId, parseInt(amount), 'Admin bonus');
|
||||
toast.success('Bonus granted');
|
||||
loadData();
|
||||
} catch (error) {
|
||||
toast.error('Failed to grant bonus');
|
||||
}
|
||||
};
|
||||
|
||||
if (!isAuthenticated || !user?.isAdmin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center">
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background">
|
||||
<header className="border-b bg-card">
|
||||
<div className="max-w-7xl mx-auto px-4 py-4 flex items-center justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
<h1 className="text-2xl font-bold">Admin Dashboard</h1>
|
||||
<Badge variant="secondary">{user.plexUsername}</Badge>
|
||||
</div>
|
||||
<Button variant="ghost" onClick={() => router.push('/dashboard')}>
|
||||
Back to Dashboard
|
||||
</Button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main className="max-w-7xl mx-auto px-4 py-8">
|
||||
{/* Stats Overview */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4 mb-8">
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-sm font-medium">Total Users</CardTitle>
|
||||
<Users className="h-4 w-4 text-muted-foreground" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">{analytics?.users.total || 0}</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{analytics?.users.with_wallet || 0} with wallets
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-sm font-medium">Total Minted</CardTitle>
|
||||
<TrendingUp className="h-4 w-4 text-green-500" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">
|
||||
{formatNumber(analytics?.transactions.total_earned || 0)} $COOP
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{analytics?.transactions.total_transactions || 0} transactions
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-sm font-medium">Watch Time</CardTitle>
|
||||
<TrendingUp className="h-4 w-4 text-blue-500" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="text-2xl font-bold">
|
||||
{Math.floor((analytics?.watchStats.total_seconds || 0) / 3600)}h
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{analytics?.watchStats.total_events || 0} watch events
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-sm font-medium">System Status</CardTitle>
|
||||
<Settings className="h-4 w-4 text-muted-foreground" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className={`w-2 h-2 rounded-full ${settings?.mintingPaused ? 'bg-red-500' : 'bg-green-500'}`} />
|
||||
<span className="font-bold">
|
||||
{settings?.mintingPaused ? 'Paused' : 'Active'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex gap-2 mt-2">
|
||||
<Button size="sm" variant="outline" onClick={handlePause} disabled={settings?.mintingPaused}>
|
||||
<Pause className="h-3 w-3 mr-1" />
|
||||
Pause
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" onClick={handleResume} disabled={!settings?.mintingPaused}>
|
||||
<Play className="h-3 w-3 mr-1" />
|
||||
Resume
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<Tabs defaultValue="users">
|
||||
<TabsList>
|
||||
<TabsTrigger value="users">Users</TabsTrigger>
|
||||
<TabsTrigger value="settings">Settings</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="users" className="space-y-4">
|
||||
<div className="flex gap-4">
|
||||
<div className="relative flex-1 max-w-sm">
|
||||
<Search className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Search users..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardContent className="p-0">
|
||||
<div className="divide-y">
|
||||
{users.map((u) => (
|
||||
<div key={u.id} className="flex items-center justify-between p-4">
|
||||
<div>
|
||||
<p className="font-medium">{u.plexUsername}</p>
|
||||
<p className="text-sm text-muted-foreground">{u.email}</p>
|
||||
<div className="flex gap-2 mt-1">
|
||||
{u.isAdmin && <Badge variant="default">Admin</Badge>}
|
||||
{!u.isActive && <Badge variant="destructive">Inactive</Badge>}
|
||||
{u.walletAddress && <Badge variant="secondary">Wallet</Badge>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<p className="font-mono text-sm">
|
||||
{formatNumber(u.totalEarned - u.totalSpent)} $COOP
|
||||
</p>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => handleGrantBonus(u.id)}
|
||||
>
|
||||
<Gift className="h-4 w-4 mr-1" />
|
||||
Bonus
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="settings">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Minting Settings</CardTitle>
|
||||
<CardDescription>Configure how users earn $COOP</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Credits Per Minute</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={settings?.creditsPerMinute || 10}
|
||||
onChange={(e) => setSettings({ ...settings, creditsPerMinute: parseInt(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Min Watch Percent</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={settings?.minWatchPercent || 80}
|
||||
onChange={(e) => setSettings({ ...settings, minWatchPercent: parseInt(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Movie Request Cost</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={settings?.movieRequestCost || 100}
|
||||
onChange={(e) => setSettings({ ...settings, movieRequestCost: parseInt(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>TV Request Cost</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={settings?.tvRequestCost || 200}
|
||||
onChange={(e) => setSettings({ ...settings, tvRequestCost: parseInt(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Button onClick={() => adminApi.updateSettings(settings).then(() => toast.success('Settings saved'))}>
|
||||
Save Settings
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user