mirror of
https://github.com/EdiFarcas/Giveaway-app.git
synced 2026-06-28 13:00:42 +03:00
Initial commit - project setup
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
interface AdminClientProps {
|
||||
email: string;
|
||||
}
|
||||
|
||||
export default function AdminClient({ email }: AdminClientProps) {
|
||||
const [giveaway, setGiveaway] = useState({ title: "", description: "", value: 0, prize: "" });
|
||||
const [userCoins, setUserCoins] = useState({ userId: "", coins: 0 });
|
||||
|
||||
const handleCreateGiveaway = async () => {
|
||||
const response = await fetch("/api/admin/create-giveaway", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(giveaway),
|
||||
});
|
||||
if (response.ok) {
|
||||
alert("Giveaway created successfully!");
|
||||
setGiveaway({ title: "", description: "", value:0, prize: "" }); // Reset form
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(`Failed to create giveaway: ${error.error}`);
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpdateCoins = async () => {
|
||||
const response = await fetch("/api/admin/update-coins", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(userCoins),
|
||||
});
|
||||
if (response.ok) {
|
||||
alert("User coins updated successfully!");
|
||||
setUserCoins({ userId: "", coins: 0 }); // Reset form
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(`Failed to update user coins: ${error.error}`);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-white text-black py-12 px-4 sm:px-6 lg:px-8">
|
||||
<div className="max-w-3xl mx-auto space-y-8">
|
||||
<h1 className="text-3xl font-bold">Admin Page</h1>
|
||||
<p>Welcome, {email}!</p>
|
||||
|
||||
{/* Create Giveaway Form */}
|
||||
<div className="p-4 text-white bg-gray-800 shadow rounded">
|
||||
<h2 className="text-xl font-semibold">Create Giveaway</h2>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Title"
|
||||
value={giveaway.title}
|
||||
onChange={(e) => setGiveaway({ ...giveaway, title: e.target.value })}
|
||||
className="block w-full mt-2 p-2 border rounded bg-gray-700 text-gray-200"
|
||||
/>
|
||||
<textarea
|
||||
placeholder="Description"
|
||||
value={giveaway.description}
|
||||
onChange={(e) => setGiveaway({ ...giveaway, description: e.target.value })}
|
||||
className="block w-full mt-2 p-2 border rounded bg-gray-700 text-gray-200"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Prize"
|
||||
value={giveaway.prize}
|
||||
onChange={(e) => setGiveaway({ ...giveaway, prize: e.target.value })}
|
||||
className="block w-full mt-2 p-2 border rounded bg-gray-700 text-gray-200"
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
placeholder="Value"
|
||||
value={giveaway.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"
|
||||
/>
|
||||
<button
|
||||
onClick={handleCreateGiveaway}
|
||||
className="mt-4 bg-blue-600 text-white px-4 py-2 rounded"
|
||||
>
|
||||
Create Giveaway
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Update User Coins Form */}
|
||||
<div className="p-4 text-white bg-gray-800 shadow rounded">
|
||||
<h2 className="text-xl font-semibold">Update User Coins</h2>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="User ID"
|
||||
value={userCoins.userId}
|
||||
onChange={(e) => setUserCoins({ ...userCoins, userId: e.target.value })}
|
||||
className="block w-full mt-2 p-2 border rounded bg-gray-700 text-gray-200"
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
placeholder="Coins"
|
||||
value={userCoins.coins}
|
||||
onChange={(e) => setUserCoins({ ...userCoins, coins: Number(e.target.value) })}
|
||||
className="block w-full mt-2 p-2 border rounded bg-gray-700 text-gray-200"
|
||||
/>
|
||||
<button
|
||||
onClick={handleUpdateCoins}
|
||||
className="mt-4 bg-green-600 text-white px-4 py-2 rounded"
|
||||
>
|
||||
Update Coins
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user