mirror of
https://github.com/EdiFarcas/Giveaway-app.git
synced 2026-06-22 07:00:57 +03:00
Update Giveaway, app-functional
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Giveaway" ADD COLUMN "duration" INTEGER,
|
||||
ADD COLUMN "endsAt" TIMESTAMP(3);
|
||||
@@ -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[]
|
||||
}
|
||||
|
||||
@@ -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,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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user