mirror of
https://github.com/EdiFarcas/Giveaway-app.git
synced 2026-06-29 11:01:02 +03:00
Update homepage, giveaway creation and view update.
This commit is contained in:
@@ -8,7 +8,15 @@ interface AdminClientProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AdminClient({ email }: AdminClientProps) {
|
export default function AdminClient({ email }: AdminClientProps) {
|
||||||
const [giveaway, setGiveaway] = useState({ title: "", description: "", value: 0, prize: "", duration: 0, endsAt: 0 });
|
const [giveaway, setGiveaway] = useState({
|
||||||
|
title: "",
|
||||||
|
description: "",
|
||||||
|
value: 0,
|
||||||
|
prize: "",
|
||||||
|
entryCost: 70000000,
|
||||||
|
duration: 0,
|
||||||
|
endsAt: new Date(Date.now() + 24 * 60 * 60 * 1000).getTime() // Set to tomorrow
|
||||||
|
});
|
||||||
const [youtube_url, setYoutubeUrl] = useState("");
|
const [youtube_url, setYoutubeUrl] = useState("");
|
||||||
const [coin_value, setCoinValue] = useState(0);
|
const [coin_value, setCoinValue] = useState(0);
|
||||||
|
|
||||||
@@ -20,7 +28,8 @@ export default function AdminClient({ email }: AdminClientProps) {
|
|||||||
});
|
});
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
alert("Giveaway created successfully!");
|
alert("Giveaway created successfully!");
|
||||||
setGiveaway({ title: "", description: "", value: 0, prize: "", duration: 0, endsAt: 0 }); // Reset form
|
|
||||||
|
setGiveaway({ title: "", description: "", value: 0, prize: "", entryCost: 70000000, duration: 0, endsAt: new Date(Date.now() + 24 * 60 * 60 * 1000).getTime() }); // Reset form
|
||||||
} else {
|
} else {
|
||||||
const error = await response.json();
|
const error = await response.json();
|
||||||
alert(`Failed to create giveaway: ${error.error}`);
|
alert(`Failed to create giveaway: ${error.error}`);
|
||||||
@@ -58,7 +67,7 @@ export default function AdminClient({ email }: AdminClientProps) {
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
placeholder="Value in Dollars"
|
placeholder="Value in Coins"
|
||||||
value={giveaway.value || ""}
|
value={giveaway.value || ""}
|
||||||
onChange={(e) => setGiveaway({ ...giveaway, value: Number(e.target.value) })}
|
onChange={(e) => setGiveaway({ ...giveaway, value: Number(e.target.value) })}
|
||||||
className="block w-full mt-2 p-2 border rounded bg-gray-700 text-gray-200"
|
className="block w-full mt-2 p-2 border rounded bg-gray-700 text-gray-200"
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ const handleUpdateCoins = async (youtubeUrl: string, coinValue: number) => {
|
|||||||
// Continue with the next author
|
// Continue with the next author
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},{timeout: 60000}); // Set a timeout of 60 seconds for the transaction
|
},{timeout: 60000}); // Set a timeout of 60 seconds for the transaction (Modify as needed)
|
||||||
|
|
||||||
console.log("Coins updated successfully for all authors.");
|
console.log("Coins updated successfully for all authors.");
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { db } from "@/lib/db";
|
|||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
const { title, description, value, prize, duration, endsAt } = body;
|
const { title, description, value, prize, duration, endsAt } = body;
|
||||||
|
|
||||||
if (!title || !description || !prize || !value) {
|
if (!title || !description || !prize || !value) {
|
||||||
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
|
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
|
||||||
@@ -16,6 +16,7 @@ export async function POST(req: Request) {
|
|||||||
description,
|
description,
|
||||||
prize,
|
prize,
|
||||||
value,
|
value,
|
||||||
|
entryCost: value * 0.1,
|
||||||
duration,
|
duration,
|
||||||
endsAt: new Date(endsAt),
|
endsAt: new Date(endsAt),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import { NextResponse } from "next/server";
|
|
||||||
import { db } from "@/lib/db";
|
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
|
||||||
const body = await req.json();
|
|
||||||
const { userId, coins } = body;
|
|
||||||
|
|
||||||
if (!userId || coins === undefined) {
|
|
||||||
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const user = await db.user.update({
|
|
||||||
where: { id: userId },
|
|
||||||
data: { coins },
|
|
||||||
});
|
|
||||||
return NextResponse.json(user);
|
|
||||||
} catch {
|
|
||||||
return NextResponse.json({ error: "Failed to update user coins" }, { status: 500 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,23 +18,41 @@ export default async function GiveawaysPage() {
|
|||||||
title: true,
|
title: true,
|
||||||
description: true,
|
description: true,
|
||||||
prize: true,
|
prize: true,
|
||||||
|
endsAt: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
|
<div className="min-h-screen bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
|
||||||
<div className="max-w-7xl mx-auto">
|
<div className="max-w-7xl mx-auto">
|
||||||
<h1 className="text-3xl font-bold text-gray-800 mb-8">Active Giveaways</h1>
|
<h1 className="text-3xl font-bold text-gray-800 mb-8">Active Giveaways</h1>
|
||||||
<div className="text-black grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
<div className="text-black grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
{giveaways.map((giveaway) => (
|
{giveaways.map((giveaway) => {
|
||||||
|
const remainingTime = Math.max(
|
||||||
|
0,
|
||||||
|
new Date(giveaway.endsAt ?? 0).getTime() - Date.now()
|
||||||
|
);
|
||||||
|
|
||||||
|
const days = Math.floor(remainingTime / (1000 * 60 * 60 * 24));
|
||||||
|
|
||||||
|
const hours = Math.floor(
|
||||||
|
(remainingTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
|
||||||
|
);
|
||||||
|
|
||||||
|
const minutes = Math.floor(
|
||||||
|
(remainingTime % (1000 * 60 * 60)) / (1000 * 60)
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
<GiveawayCard
|
<GiveawayCard
|
||||||
key={giveaway.id}
|
key={giveaway.id}
|
||||||
title={giveaway.title}
|
title={giveaway.title}
|
||||||
description={giveaway.description}
|
description={`${giveaway.description} - Ends in: ${days}d ${hours}h ${minutes}m`}
|
||||||
imageUrl={giveaway.prize} // Assuming prize is a URL to an image
|
imageUrl={giveaway.prize} // Assuming prize is a URL to an image
|
||||||
/>
|
/>
|
||||||
))}
|
);
|
||||||
</div>
|
})}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
+66
-65
@@ -2,118 +2,119 @@ import Image from "next/image";
|
|||||||
|
|
||||||
export default function GiveawaySystem() {
|
export default function GiveawaySystem() {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-50 py-12 px-4 sm:px-6 lg:px-8 font-[family-name:var(--font-geist-sans)]">
|
<div className="min-h-screen bg-gradient-to-br from-yellow-100 to-pink-200 py-12 px-4 sm:px-6 lg:px-8 font-sans">
|
||||||
<div className="max-w-4xl mx-auto">
|
<div className="max-w-4xl mx-auto">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="text-center mb-16">
|
<div className="text-center mb-16">
|
||||||
<h1 className="text-4xl sm:text-5xl font-bold mb-4 bg-gradient-to-r from-purple-600 to-blue-600 bg-clip-text text-transparent">
|
<Image
|
||||||
🎁 Community Giveaway System
|
src="/logo-tcg-love.png"
|
||||||
|
alt="TCG Love Openings Logo"
|
||||||
|
width={120}
|
||||||
|
height={120}
|
||||||
|
className="mx-auto mb-4 rounded-full border-4 border-pink-400 shadow-lg"
|
||||||
|
/>
|
||||||
|
<h1 className="text-4xl sm:text-5xl font-bold mb-2 bg-gradient-to-r from-pink-600 to-yellow-500 bg-clip-text text-transparent drop-shadow">
|
||||||
|
🎁 TCG Love Giveaway System
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-lg text-gray-600">Revamped engagement-powered rewards system</p>
|
<p className="text-lg text-gray-700">Join the fun — earn coins, win cool cards!</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Coin System Section */}
|
{/* Coin System Section */}
|
||||||
<div className="bg-white rounded-xl shadow-lg p-6 mb-8">
|
<div className="bg-white rounded-2xl shadow-lg p-6 mb-10 border-2 border-yellow-300">
|
||||||
<div className="flex items-center mb-4">
|
<div className="flex items-center mb-4">
|
||||||
<span className="text-3xl mr-3">🪙</span>
|
<span className="text-3xl mr-3">🪙</span>
|
||||||
<h2 className="text-2xl font-bold">Coin System Overview</h2>
|
<h2 className="text-2xl font-bold text-pink-700">How Coins Work</h2>
|
||||||
</div>
|
</div>
|
||||||
<ul className="list-disc pl-6 space-y-3 text-gray-700">
|
<ul className="list-disc pl-6 space-y-3 text-gray-800">
|
||||||
<li>Earn coins by commenting on videos and other engagement</li>
|
<li>Earn coins by:
|
||||||
<li>Coins serve dual purpose:
|
<ul className="list-circle pl-4 mt-1 space-y-1 text-sm text-gray-600">
|
||||||
<ul className="list-circle pl-4 mt-2 space-y-2">
|
<li>Commenting on TCG Love Openings videos</li>
|
||||||
<li>Eligibility requirement for giveaways</li>
|
<li>Liking and subscribing</li>
|
||||||
<li>Weighted entries (1 coin = 1 ticket, with diminishing returns)</li>
|
<li>Engaging with the community</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<li>Coins = your gateway to exclusive giveaways!</li>
|
||||||
|
<li>More coins mean more chances to win — but with balance!</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Weighted Lottery Section */}
|
{/* Lottery Multiplier */}
|
||||||
<div className="bg-white rounded-xl shadow-lg p-6 mb-8">
|
<div className="bg-white rounded-2xl shadow-xl p-6 mb-10 border-2 border-pink-300">
|
||||||
<div className="flex items-center mb-4">
|
<div className="flex items-center mb-4">
|
||||||
<span className="text-3xl mr-3">🧮</span>
|
<span className="text-3xl mr-3">🎲</span>
|
||||||
<h2 className="text-2xl font-bold">Weighted Lottery System</h2>
|
<h2 className="text-2xl font-bold text-purple-700">Weighted Lottery</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid md:grid-cols-2 gap-6">
|
<div className="grid md:grid-cols-2 gap-6">
|
||||||
<div className="space-y-4">
|
<div className="space-y-3">
|
||||||
<div className="flex justify-between items-center p-3 bg-gray-50 rounded-lg">
|
{[{ range: "1–100", mult: "1x", color: "text-yellow-600" },
|
||||||
<span>1–100 coins</span>
|
{ range: "101–200", mult: "0.5x", color: "text-green-600" },
|
||||||
<span className="font-bold text-purple-600">1x multiplier</span>
|
{ range: "201–300", mult: "0.25x", color: "text-blue-600" },
|
||||||
</div>
|
{ range: "301+", mult: "0.1x", color: "text-red-500" }]
|
||||||
<div className="flex justify-between items-center p-3 bg-gray-50 rounded-lg">
|
.map((tier) => (
|
||||||
<span>101–200 coins</span>
|
<div key={tier.range} className="flex justify-between items-center p-3 bg-gradient-to-r from-gray-100 to-white rounded-lg shadow">
|
||||||
<span className="font-bold text-blue-600">0.5x multiplier</span>
|
<span>{tier.range} coins</span>
|
||||||
</div>
|
<span className={`font-bold ${tier.color}`}>{tier.mult}</span>
|
||||||
<div className="flex justify-between items-center p-3 bg-gray-50 rounded-lg">
|
</div>
|
||||||
<span>201–300 coins</span>
|
))}
|
||||||
<span className="font-bold text-green-600">0.25x multiplier</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex justify-between items-center p-3 bg-gray-50 rounded-lg">
|
|
||||||
<span>301+ coins</span>
|
|
||||||
<span className="font-bold text-red-600">0.1x multiplier</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div className="bg-purple-50 p-4 rounded-lg border border-purple-200 shadow-sm">
|
||||||
<div className="bg-purple-50 p-4 rounded-lg">
|
<h3 className="font-semibold mb-2">🎯 Example</h3>
|
||||||
<h3 className="font-semibold mb-2">Example Calculation</h3>
|
<p className="text-sm text-gray-700">
|
||||||
<p className="text-sm text-gray-600">
|
450 coins = <br />
|
||||||
User with 450 coins:<br />
|
100×1 + 100×0.5 + 100×0.25 + 50×0.1 = <br />
|
||||||
100 × 1 + 100 × 0.5 + 100 × 0.25 + 50 × 0.1 =<br />
|
<span className="font-bold">180 tickets!</span>
|
||||||
<span className="font-bold">100 + 50 + 25 + 5 = 180 tickets</span>
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Entry Requirements */}
|
{/* Entry Requirements */}
|
||||||
<div className="bg-white rounded-xl shadow-lg p-6">
|
<div className="bg-white rounded-2xl shadow-lg p-6 mb-10 border-2 border-blue-200">
|
||||||
<div className="flex items-center mb-4">
|
<div className="flex items-center mb-4">
|
||||||
<span className="text-3xl mr-3">🔐</span>
|
<span className="text-3xl mr-3">🎟️</span>
|
||||||
<h2 className="text-2xl font-bold">Entry Requirements</h2>
|
<h2 className="text-2xl font-bold text-blue-700">Giveaway Entry Requirements</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table className="w-full">
|
<table className="w-full text-sm text-left text-gray-600">
|
||||||
<thead className="bg-gray-50">
|
<thead className="bg-blue-50 text-blue-900">
|
||||||
<tr>
|
<tr>
|
||||||
<th className="text-left py-3 px-4">Giveaway Value</th>
|
<th className="py-2 px-4">Prize Tier</th>
|
||||||
<th className="text-left py-3 px-4">Minimum Coins</th>
|
<th className="py-2 px-4">Min. Coins</th>
|
||||||
<th className="text-left py-3 px-4">Coins Burned</th>
|
<th className="py-2 px-4">Burn (Optional)</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody className="divide-y">
|
||||||
<tr className="border-b">
|
<tr>
|
||||||
<td className="py-3 px-4">$1–5</td>
|
<td className="py-3 px-4">$1–5 card</td>
|
||||||
<td className="py-3 px-4 font-medium">500</td>
|
<td className="py-3 px-4 font-medium">500</td>
|
||||||
<td className="py-3 px-4 text-gray-500">None</td>
|
<td className="py-3 px-4">None</td>
|
||||||
</tr>
|
|
||||||
<tr className="border-b">
|
|
||||||
<td className="py-3 px-4">$10–25</td>
|
|
||||||
<td className="py-3 px-4 font-medium">1,000</td>
|
|
||||||
<td className="py-3 px-4 text-gray-500">None</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="py-3 px-4">$50+</td>
|
<td className="py-3 px-4">$10–25 card</td>
|
||||||
|
<td className="py-3 px-4 font-medium">1,000</td>
|
||||||
|
<td className="py-3 px-4">None</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td className="py-3 px-4">$50+ special set</td>
|
||||||
<td className="py-3 px-4 font-medium">2,000+</td>
|
<td className="py-3 px-4 font-medium">2,000+</td>
|
||||||
<td className="py-3 px-4 text-gray-500">Optional (e.g., 50 coins)</td>
|
<td className="py-3 px-4 text-red-500">+50 for extra entries</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-6 p-4 bg-blue-50 rounded-lg">
|
<div className="mt-6 p-4 bg-blue-100 rounded-lg">
|
||||||
<p className="text-sm text-blue-800">
|
<p className="text-sm text-blue-800">
|
||||||
💡 Note: Coins are not spent to enter - minimum balance acts as eligibility requirement.
|
📌 You keep your coins — they arent spent to enter! But optional burns can boost your odds.
|
||||||
Optional burns for higher tiers provide bonus entry weight.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Disclaimer */}
|
{/* Footer */}
|
||||||
<div className="mt-8 text-center text-sm text-gray-500">
|
<div className="mt-10 text-center text-sm text-gray-500">
|
||||||
<p>System subject to change. See full rules for complete details.</p>
|
<p>⚠️ Subject to change. See full rules in description or Discord.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ interface GiveawayCardProps {
|
|||||||
const GiveawayCard: React.FC<GiveawayCardProps> = ({ title, description, imageUrl }) => {
|
const GiveawayCard: React.FC<GiveawayCardProps> = ({ title, description, imageUrl }) => {
|
||||||
return (
|
return (
|
||||||
<div className="bg-white shadow-md rounded-lg overflow-hidden">
|
<div className="bg-white shadow-md rounded-lg overflow-hidden">
|
||||||
<img src={imageUrl} alt={title} className="w-full h-48 object-cover" />
|
{/* <img src={imageUrl} alt={title} className="w-full h-48 object-cover" /> */}
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<h3 className="text-lg font-bold mb-2">{title}</h3>
|
<h3 className="text-lg font-bold mb-2">{title}</h3>
|
||||||
<p className="text-gray-600 text-sm">{description}</p>
|
<p className="text-gray-600 text-sm">{description}</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user