diff --git a/packages/nextjs/app/admin/_components/SubmissionCard.tsx b/packages/nextjs/app/admin/_components/SubmissionCard.tsx index f154923..2f8eecd 100644 --- a/packages/nextjs/app/admin/_components/SubmissionCard.tsx +++ b/packages/nextjs/app/admin/_components/SubmissionCard.tsx @@ -8,11 +8,13 @@ import { useMutation } from "@tanstack/react-query"; import clsx from "clsx"; import { useAccount } from "wagmi"; import { Address } from "~~/components/scaffold-eth"; +import scaffoldConfig from "~~/scaffold.config"; import { SubmissionWithAvg } from "~~/services/database/repositories/submissions"; import { postMutationFetcher } from "~~/utils/react-query"; import { notification } from "~~/utils/scaffold-eth"; export const SubmissionCard = ({ submission }: { submission: SubmissionWithAvg }) => { + const { votingEnabled } = scaffoldConfig; const { address: connectedAddress } = useAccount(); const { mutateAsync: postNewVote, isPending: isVotePending } = useMutation({ @@ -23,6 +25,11 @@ export const SubmissionCard = ({ submission }: { submission: SubmissionWithAvg } const vote = async (newScore: number) => { try { + if (!votingEnabled) { + notification.error("Voting is disabled"); + return; + } + if (newScore < 0 || newScore > 10) { notification.error("Wrong score"); return; diff --git a/packages/nextjs/app/admin/_components/Submissions.tsx b/packages/nextjs/app/admin/_components/Submissions.tsx index cd63e76..6e887df 100644 --- a/packages/nextjs/app/admin/_components/Submissions.tsx +++ b/packages/nextjs/app/admin/_components/Submissions.tsx @@ -1,7 +1,18 @@ import { SubmissionTabs } from "./SubmissionTabs"; +import scaffoldConfig from "~~/scaffold.config"; import { getAllSubmissions } from "~~/services/database/repositories/submissions"; export const Submissions = async () => { const submissions = await getAllSubmissions(); - return ; + const { votingEnabled } = scaffoldConfig; + return ( + <> + {!votingEnabled && ( +
+
Voting period ended
+
+ )} + + + ); }; diff --git a/packages/nextjs/app/api/submissions/[submissionId]/votes/route.ts b/packages/nextjs/app/api/submissions/[submissionId]/votes/route.ts index 2565ebd..e761dcd 100644 --- a/packages/nextjs/app/api/submissions/[submissionId]/votes/route.ts +++ b/packages/nextjs/app/api/submissions/[submissionId]/votes/route.ts @@ -1,15 +1,22 @@ import { NextRequest, NextResponse } from "next/server"; import { getServerSession } from "next-auth"; +import scaffoldConfig from "~~/scaffold.config"; import { createOrUpdateVote, deleteVote } from "~~/services/database/repositories/votes"; import { authOptions } from "~~/utils/auth"; export async function POST(req: NextRequest, { params }: { params: { submissionId: number } }) { + const { votingEnabled } = scaffoldConfig; try { const session = await getServerSession(authOptions); if (session?.user.role !== "admin") { return NextResponse.json({ error: "Only admins can vote" }, { status: 401 }); } + + if (!votingEnabled) { + return NextResponse.json({ error: "Voting is disabled" }, { status: 400 }); + } + const { submissionId } = params; const { score } = (await req.json()) as { score: string }; diff --git a/packages/nextjs/scaffold.config.ts b/packages/nextjs/scaffold.config.ts index b00a22e..ffe76bf 100644 --- a/packages/nextjs/scaffold.config.ts +++ b/packages/nextjs/scaffold.config.ts @@ -6,6 +6,7 @@ export type ScaffoldConfig = { alchemyApiKey: string; walletConnectProjectId: string; onlyLocalBurnerWallet: boolean; + votingEnabled: boolean; }; const scaffoldConfig = { @@ -30,6 +31,9 @@ const scaffoldConfig = { // Only show the Burner Wallet when running on hardhat network onlyLocalBurnerWallet: true, + + // Enable voting on submissions + votingEnabled: false, } as const satisfies ScaffoldConfig; export default scaffoldConfig;