106 lines
3.7 KiB
TypeScript
106 lines
3.7 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useEffect } from 'react'
|
|
import { Search, Edit, Trash2, Star, XCircle } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { Poll } from '@/types'
|
|
|
|
export default function AdminPollsPage() {
|
|
const [polls, setPolls] = useState<Poll[]>([])
|
|
const [search, setSearch] = useState('')
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
fetch('/api/admin/polls')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
setPolls(data.polls || [])
|
|
setLoading(false)
|
|
})
|
|
}, [])
|
|
|
|
const handleAction = async (pollId: string, action: 'feature' | 'close' | 'delete') => {
|
|
await fetch(`/api/admin/polls/${pollId}`, {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ action })
|
|
})
|
|
|
|
window.location.reload()
|
|
}
|
|
|
|
const filtered = polls.filter(p =>
|
|
p.question.toLowerCase().includes(search.toLowerCase())
|
|
)
|
|
|
|
return (
|
|
<div className="min-h-screen bg-gradient-to-b from-celo-dark to-black text-white p-4">
|
|
<div className="max-w-6xl mx-auto space-y-6">
|
|
<div className="flex items-center justify-between">
|
|
<h1 className="text-3xl font-bold">๐ Manage Polls</h1>
|
|
<Link href="/admin" className="text-gray-400 hover:text-white">
|
|
โ Back to Dashboard
|
|
</Link>
|
|
</div>
|
|
|
|
<div className="relative">
|
|
<Search className="absolute left-3 top-3 text-gray-400" size={20} />
|
|
<input
|
|
type="text"
|
|
value={search}
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
placeholder="Search polls..."
|
|
className="w-full pl-10 pr-4 py-3 bg-white/10 rounded-xl border border-white/20 focus:border-celo-green outline-none"
|
|
/>
|
|
</div>
|
|
|
|
{loading ? (
|
|
<div className="text-center py-12">Loading...</div>
|
|
) : (
|
|
<div className="space-y-3">
|
|
{filtered.map(poll => (
|
|
<div key={poll.id} className="bg-white/10 rounded-xl p-4">
|
|
<div className="flex items-start justify-between">
|
|
<div className="flex-1">
|
|
<h3 className="font-semibold">{poll.emoji} {poll.question}</h3>
|
|
<p className="text-sm text-gray-400 mt-1">{poll.description}</p>
|
|
<div className="flex gap-4 mt-2 text-sm text-gray-400">
|
|
<span>Status: {poll.status}</span>
|
|
<span>๐ฅ {poll.totalVotes} votes</span>
|
|
<span>๐ฐ {poll.totalAmount.toFixed(2)} cUSD</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex gap-2">
|
|
<button
|
|
onClick={() => handleAction(poll.id, 'feature')}
|
|
className="p-2 bg-celo-yellow/20 rounded-lg hover:bg-celo-yellow/30 transition"
|
|
title="Feature"
|
|
>
|
|
<Star size={16} />
|
|
</button>
|
|
<button
|
|
onClick={() => handleAction(poll.id, 'close')}
|
|
className="p-2 bg-white/10 rounded-lg hover:bg-white/20 transition"
|
|
title="Close"
|
|
>
|
|
<XCircle size={16} />
|
|
</button>
|
|
<button
|
|
onClick={() => handleAction(poll.id, 'delete')}
|
|
className="p-2 bg-red-500/20 rounded-lg hover:bg-red-500/30 transition"
|
|
title="Delete"
|
|
>
|
|
<Trash2 size={16} />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|