diff --git a/prisma/migrations/20250505181248_entry_update_2/migration.sql b/prisma/migrations/20250505181248_entry_update_2/migration.sql new file mode 100644 index 0000000..9d866db --- /dev/null +++ b/prisma/migrations/20250505181248_entry_update_2/migration.sql @@ -0,0 +1,10 @@ +/* + Warnings: + + - You are about to drop the column `weight` on the `Entry` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "Entry" DROP COLUMN "weight", +ADD COLUMN "acive" BOOLEAN NOT NULL DEFAULT true, +ADD COLUMN "pastValue" INTEGER NOT NULL DEFAULT 0; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b7fb3dc..dc05b3b 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -78,5 +78,6 @@ model Entry { userId String giveaway Giveaway @relation(fields: [giveawayId], references: [id]) giveawayId String - weight Float + acive Boolean @default(true) + pastValue Int @default(0) } diff --git a/src/app/giveaways/page.tsx b/src/app/giveaways/page.tsx index 914334a..e6d38c6 100644 --- a/src/app/giveaways/page.tsx +++ b/src/app/giveaways/page.tsx @@ -77,7 +77,7 @@ export default async function GiveawaysPage() { className="bg-white rounded-2xl shadow-lg border-2 border-pink-200 hover:shadow-xl transition-shadow duration-300" > = ({ id, title, description, imageUrl, value, userId}) => { +const GiveawayCard: React.FC = ({ giveawayId, title, description, imageUrl, value, userId}) => { const [isModalOpen, setIsModalOpen] = useState(false); + const [entrynumber, setEntrynumber] = useState(0); + const [activeUserCoins, setActiveUserCoins] = useState(0); - const entrienumber = entrycount(userId, id); - const handleEnterClick = () => { - const activeUserCoins = 300; // Replace with actual logic to fetch active user's coins (TO DO LATER) + const fetchEntryCount = async () => { + try { + const count = await entrycount(userId, giveawayId); + setEntrynumber(count); + } catch (error) { + console.error("Error fetching entry count:", error); + } + }; + + useEffect(() => { + fetchEntryCount(); + }, [userId, giveawayId]); + + const fetchActiveUserCoins = async () => { + try { + const coins = await usercoins(userId, giveawayId); + setActiveUserCoins(coins); + } catch (error) { + console.error("Error fetching active user coins:", error); + } + }; + + useEffect(() => { + fetchActiveUserCoins(); + }, [userId, giveawayId]); + + const handleEnterClick = async () => { + + await fetchActiveUserCoins(); + if (activeUserCoins >= value) { setIsModalOpen(true); } else { @@ -37,7 +67,7 @@ const GiveawayCard: React.FC = ({ id, title, description, ima

{title}

{description}

Value: {value} coins

- {/*

Your entries: {entrycount(userId, id)}

*/} +

Your entries: {entrynumber}