2025-12-08 16:31:30 +03:00

117 lines
4.6 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/navigation'
export default function CreatorDashboard() {
const [stats, setStats] = useState<any>(null)
const router = useRouter()
useEffect(() => {
loadStats()
}, [])
const loadStats = async () => {
try {
const res = await fetch('/api/creator/stats')
const data = await res.json()
setStats(data)
} catch (error) {
console.error('Failed to load creator stats:', error)
}
}
if (!stats) {
return <div className="min-h-screen bg-gray-900 flex items-center justify-center">
<div className="text-white">Loading...</div>
</div>
}
return (
<div className="min-h-screen bg-gradient-to-br from-gray-900 to-gray-800 p-4">
<div className="max-w-4xl mx-auto pt-20">
<div className="flex items-center justify-between mb-8">
<h1 className="text-3xl font-bold text-white">🎨 Creator Dashboard</h1>
<button
onClick={() => router.push('/create')}
className="bg-celo-green text-white px-6 py-3 rounded-xl font-semibold hover:bg-celo-green/90"
>
+ Create Poll
</button>
</div>
{/* Stats */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-8">
<div className="bg-gray-800 rounded-xl p-6 text-center">
<div className="text-3xl font-bold text-white">{stats.totalPolls}</div>
<div className="text-sm text-gray-400 mt-1">Polls Created</div>
</div>
<div className="bg-gray-800 rounded-xl p-6 text-center">
<div className="text-3xl font-bold text-celo-green">{stats.totalVotes}</div>
<div className="text-sm text-gray-400 mt-1">Total Votes</div>
</div>
<div className="bg-gray-800 rounded-xl p-6 text-center">
<div className="text-3xl font-bold text-celo-yellow">{stats.totalVolume}</div>
<div className="text-sm text-gray-400 mt-1">cUSD Volume</div>
</div>
<div className="bg-gray-800 rounded-xl p-6 text-center">
<div className="text-3xl font-bold text-green-500">{stats.earnings}</div>
<div className="text-sm text-gray-400 mt-1">Earnings (1%)</div>
</div>
</div>
{/* Enable Monetization */}
{!stats.monetizationEnabled && (
<div className="bg-gradient-to-r from-celo-green/20 to-celo-yellow/20 border-2 border-celo-green rounded-xl p-6 mb-8">
<h2 className="text-xl font-bold text-white mb-2">💰 Enable Creator Earnings</h2>
<p className="text-gray-300 mb-4">
Earn 1% of the pot from your polls. The more engaging your polls, the more you earn!
</p>
<button
onClick={async () => {
await fetch('/api/creator/enable', { method: 'POST' })
loadStats()
}}
className="bg-celo-green text-white px-6 py-3 rounded-xl font-semibold hover:bg-celo-green/90"
>
Enable Now
</button>
</div>
)}
{/* Your Polls */}
<div className="bg-gray-800 rounded-xl p-6">
<h2 className="text-xl font-bold text-white mb-4">Your Polls</h2>
<div className="space-y-4">
{stats.polls?.map((poll: any) => (
<div key={poll.id} className="flex items-center justify-between p-4 bg-gray-700 rounded-xl">
<div className="flex-1">
<div className="flex items-center gap-2 mb-1">
<span className="text-2xl">{poll.emoji}</span>
<h3 className="font-bold text-white">{poll.question}</h3>
</div>
<div className="flex gap-4 text-sm text-gray-400">
<span>👥 {poll.votes} votes</span>
<span>💰 {poll.totalPot} cUSD</span>
<span className={`${poll.status === 'active' ? 'text-green-500' : 'text-gray-500'}`}>
{poll.status}
</span>
</div>
</div>
{stats.monetizationEnabled && (
<div className="text-right">
<div className="text-lg font-bold text-celo-green">
+{(parseFloat(poll.totalPot) * 0.01).toFixed(3)} cUSD
</div>
<div className="text-xs text-gray-400">Your earnings</div>
</div>
)}
</div>
))}
</div>
</div>
</div>
</div>
)
}