Update Giveaway, app-functional

This commit is contained in:
EdiFarcas
2025-04-28 14:46:10 +03:00
parent 4f6455ffbe
commit 7f744e1e9f
6 changed files with 51 additions and 26 deletions
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "Giveaway" ADD COLUMN "duration" INTEGER,
ADD COLUMN "endsAt" TIMESTAMP(3);
+2
View File
@@ -64,6 +64,8 @@ model Giveaway {
prize String
active Boolean @default(true)
createdAt DateTime @default(now())
duration Int?
endsAt DateTime?
entryCost Int @default(7000000)
entries Entry[]
}
+32 -25
View File
@@ -7,7 +7,7 @@ interface AdminClientProps {
}
export default function AdminClient({ email }: AdminClientProps) {
const [giveaway, setGiveaway] = useState({ title: "", description: "", value: 0, prize: "" });
const [giveaway, setGiveaway] = useState({ title: "", description: "", value: 0, prize: "", duration: 0, endsAt: 0 });
const [userCoins, setUserCoins] = useState({ userId: "", coins: 0 });
const handleCreateGiveaway = async () => {
@@ -18,7 +18,7 @@ export default function AdminClient({ email }: AdminClientProps) {
});
if (response.ok) {
alert("Giveaway created successfully!");
setGiveaway({ title: "", description: "", value:0, prize: "" }); // Reset form
setGiveaway({ title: "", description: "", value: 0, prize: "", duration: 0, endsAt: 0 }); // Reset form
} else {
const error = await response.json();
alert(`Failed to create giveaway: ${error.error}`);
@@ -50,37 +50,44 @@ export default function AdminClient({ email }: AdminClientProps) {
<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"
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"
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"
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"
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"
/>
<input
type="datetime-local"
placeholder="Ends At"
value={giveaway.endsAt ? new Date(giveaway.endsAt).toISOString().slice(0, 16) : ""}
onChange={(e) => setGiveaway({ ...giveaway, endsAt: Date.parse(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
onClick={handleCreateGiveaway}
className="mt-4 bg-blue-600 text-white px-4 py-2 rounded"
>
Create Giveaway
</button>
</div>
+3 -1
View File
@@ -3,7 +3,7 @@ import { db } from "@/lib/db";
export async function POST(req: Request) {
const body = await req.json();
const { title, description, value, prize } = body;
const { title, description, value, prize, duration, endsAt } = body;
if (!title || !description || !prize || !value) {
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
@@ -16,6 +16,8 @@ export async function POST(req: Request) {
description,
prize,
value,
duration,
endsAt: new Date(endsAt),
},
});
return NextResponse.json(giveaway);
+6
View File
@@ -2,6 +2,7 @@ import NextAuth, { SessionStrategy } from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { db } from "@/lib/db"; // Ensure this is the correct path to your Prisma client
import axios from "axios";
if (!db) {
throw new Error("Prisma client is not initialized. Check your database configuration.");
@@ -13,6 +14,11 @@ export const authOptions = {
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
authorization: {
params: {
scope: "openid email profile https://www.googleapis.com/auth/youtube.readonly",
},
},
}),
],
secret: process.env.NEXTAUTH_SECRET,
+5
View File
@@ -12,6 +12,11 @@ export default async function ProfilePage() {
const user = await db.user.findUnique({
where: { email: session.user?.email! },
select: {
name: true,
email: true,
coins: true,
},
});
if (!user) {