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

136 lines
4.9 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client'
import { useEffect, useState } from 'react'
import { ReferralStats } from '@/types/referral'
export default function InviteDashboard() {
const [stats, setStats] = useState<ReferralStats | null>(null)
const [code, setCode] = useState('')
const [url, setUrl] = useState('')
const [copied, setCopied] = useState(false)
useEffect(() => {
loadData()
}, [])
const loadData = async () => {
try {
const [codeRes, statsRes] = await Promise.all([
fetch('/api/referral/generate', { method: 'POST' }),
fetch('/api/referral/stats'),
])
const codeData = await codeRes.json()
const statsData = await statsRes.json()
setCode(codeData.code)
setUrl(codeData.url)
setStats(statsData)
} catch (error) {
console.error('Failed to load referral data:', error)
}
}
const copyToClipboard = () => {
navigator.clipboard.writeText(url)
setCopied(true)
setTimeout(() => setCopied(false), 2000)
}
const shareText = `Join me on PollCelo! Vote with cUSD and win daily rewards 🎯\n\n${url}`
return (
<div className="min-h-screen bg-gradient-to-br from-gray-900 to-gray-800 p-4">
<div className="max-w-2xl mx-auto pt-20">
<h1 className="text-3xl font-bold text-white mb-2">Invite Friends</h1>
<p className="text-gray-400 mb-8">Earn 0.01 cUSD for each friend who votes</p>
{/* Stats */}
{stats && (
<div className="grid grid-cols-3 gap-4 mb-8">
<div className="bg-gray-800 rounded-xl p-4 text-center">
<div className="text-3xl font-bold text-celo-green">{stats.totalReferrals}</div>
<div className="text-sm text-gray-400">Total Invites</div>
</div>
<div className="bg-gray-800 rounded-xl p-4 text-center">
<div className="text-3xl font-bold text-celo-yellow">{stats.completedReferrals}</div>
<div className="text-sm text-gray-400">Completed</div>
</div>
<div className="bg-gray-800 rounded-xl p-4 text-center">
<div className="text-3xl font-bold text-white">{stats.totalEarnings}</div>
<div className="text-sm text-gray-400">cUSD Earned</div>
</div>
</div>
)}
{/* Share Card */}
<div className="bg-gray-800 rounded-xl p-6 mb-4">
<label className="text-sm text-gray-400 mb-2 block">Your Referral Link</label>
<div className="flex gap-2">
<input
type="text"
value={url}
readOnly
className="flex-1 bg-gray-900 text-white px-4 py-3 rounded-lg"
/>
<button
onClick={copyToClipboard}
className="bg-celo-green text-white px-6 py-3 rounded-lg font-semibold hover:bg-celo-green/90"
>
{copied ? '✓ Copied' : 'Copy'}
</button>
</div>
</div>
{/* Share Buttons */}
<div className="grid grid-cols-2 gap-4">
<a
href={`https://warpcast.com/~/compose?text=${encodeURIComponent(shareText)}`}
target="_blank"
rel="noopener noreferrer"
className="bg-purple-600 text-white py-4 rounded-xl font-semibold text-center hover:bg-purple-700"
>
Share on Warpcast
</a>
<a
href={`https://twitter.com/intent/tweet?text=${encodeURIComponent(shareText)}`}
target="_blank"
rel="noopener noreferrer"
className="bg-blue-500 text-white py-4 rounded-xl font-semibold text-center hover:bg-blue-600"
>
Share on Twitter
</a>
</div>
{/* How it Works */}
<div className="mt-8 bg-gray-800 rounded-xl p-6">
<h2 className="text-xl font-bold text-white mb-4">How it Works</h2>
<div className="space-y-3 text-gray-300">
<div className="flex gap-3">
<span className="text-2xl">1️⃣</span>
<div>
<div className="font-semibold">Share your link</div>
<div className="text-sm text-gray-400">Send to friends on Warpcast or Twitter</div>
</div>
</div>
<div className="flex gap-3">
<span className="text-2xl">2️⃣</span>
<div>
<div className="font-semibold">They vote on a poll</div>
<div className="text-sm text-gray-400">Friend must cast at least one vote</div>
</div>
</div>
<div className="flex gap-3">
<span className="text-2xl">3️⃣</span>
<div>
<div className="font-semibold">You earn 0.01 cUSD</div>
<div className="text-sm text-gray-400">Automatic reward for each referral</div>
</div>
</div>
</div>
</div>
</div>
</div>
)
}