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 prize String
active Boolean @default(true) active Boolean @default(true)
createdAt DateTime @default(now()) createdAt DateTime @default(now())
duration Int?
endsAt DateTime?
entryCost Int @default(7000000) entryCost Int @default(7000000)
entries Entry[] entries Entry[]
} }
+32 -25
View File
@@ -7,7 +7,7 @@ interface AdminClientProps {
} }
export default function AdminClient({ email }: 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 [userCoins, setUserCoins] = useState({ userId: "", coins: 0 });
const handleCreateGiveaway = async () => { const handleCreateGiveaway = async () => {
@@ -18,7 +18,7 @@ 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: "" }); // Reset form setGiveaway({ title: "", description: "", value: 0, prize: "", duration: 0, endsAt: 0 }); // 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}`);
@@ -50,37 +50,44 @@ export default function AdminClient({ email }: AdminClientProps) {
<div className="p-4 text-white bg-gray-800 shadow rounded"> <div className="p-4 text-white bg-gray-800 shadow rounded">
<h2 className="text-xl font-semibold">Create Giveaway</h2> <h2 className="text-xl font-semibold">Create Giveaway</h2>
<input <input
type="text" type="text"
placeholder="Title" placeholder="Title"
value={giveaway.title} value={giveaway.title}
onChange={(e) => setGiveaway({ ...giveaway, title: e.target.value })} onChange={(e) => setGiveaway({ ...giveaway, title: 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"
/> />
<textarea <textarea
placeholder="Description" placeholder="Description"
value={giveaway.description} value={giveaway.description}
onChange={(e) => setGiveaway({ ...giveaway, description: e.target.value })} onChange={(e) => setGiveaway({ ...giveaway, description: 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"
/> />
<input <input
type="text" type="text"
placeholder="Prize" placeholder="Prize"
value={giveaway.prize} value={giveaway.prize}
onChange={(e) => setGiveaway({ ...giveaway, prize: e.target.value })} onChange={(e) => setGiveaway({ ...giveaway, prize: 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"
/> />
<input <input
type="number" type="number"
placeholder="Value" placeholder="Value"
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"
/>
<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 <button
onClick={handleCreateGiveaway} onClick={handleCreateGiveaway}
className="mt-4 bg-blue-600 text-white px-4 py-2 rounded" className="mt-4 bg-blue-600 text-white px-4 py-2 rounded"
> >
Create Giveaway Create Giveaway
</button> </button>
</div> </div>
+3 -1
View File
@@ -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 } = 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,8 @@ export async function POST(req: Request) {
description, description,
prize, prize,
value, value,
duration,
endsAt: new Date(endsAt),
}, },
}); });
return NextResponse.json(giveaway); 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 GoogleProvider from "next-auth/providers/google";
import { PrismaAdapter } from "@next-auth/prisma-adapter"; import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { db } from "@/lib/db"; // Ensure this is the correct path to your Prisma client import { db } from "@/lib/db"; // Ensure this is the correct path to your Prisma client
import axios from "axios";
if (!db) { if (!db) {
throw new Error("Prisma client is not initialized. Check your database configuration."); throw new Error("Prisma client is not initialized. Check your database configuration.");
@@ -13,6 +14,11 @@ export const authOptions = {
GoogleProvider({ GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!, clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
authorization: {
params: {
scope: "openid email profile https://www.googleapis.com/auth/youtube.readonly",
},
},
}), }),
], ],
secret: process.env.NEXTAUTH_SECRET, secret: process.env.NEXTAUTH_SECRET,
+5
View File
@@ -12,6 +12,11 @@ export default async function ProfilePage() {
const user = await db.user.findUnique({ const user = await db.user.findUnique({
where: { email: session.user?.email! }, where: { email: session.user?.email! },
select: {
name: true,
email: true,
coins: true,
},
}); });
if (!user) { if (!user) {