From c87f4ade946a65a865be2a1bcfd98135e36a266d Mon Sep 17 00:00:00 2001 From: pabl0cks Date: Tue, 3 Sep 2024 11:12:41 +0200 Subject: [PATCH 1/6] Control apply button visibility based on env var --- packages/nextjs/.env.example | 1 + .../StickySubmissionInfo.tsx | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/nextjs/.env.example b/packages/nextjs/.env.example index c8d03d7..b05b228 100644 --- a/packages/nextjs/.env.example +++ b/packages/nextjs/.env.example @@ -11,3 +11,4 @@ # More info: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables NEXT_PUBLIC_ALCHEMY_API_KEY= NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID= +NEXT_PUBLIC_SUBMISSION_DEADLINE= diff --git a/packages/nextjs/components/extensions-hackathon/StickySubmissionInfo.tsx b/packages/nextjs/components/extensions-hackathon/StickySubmissionInfo.tsx index 4df4f70..cfddc1b 100644 --- a/packages/nextjs/components/extensions-hackathon/StickySubmissionInfo.tsx +++ b/packages/nextjs/components/extensions-hackathon/StickySubmissionInfo.tsx @@ -3,6 +3,8 @@ import Link from "next/link"; export const StickySubmissionInfo = () => { const [isVisible, setIsVisible] = useState(true); + const submissionDeadline = new Date(process.env.NEXT_PUBLIC_SUBMISSION_DEADLINE || ""); + const isSubmissionClosed = isNaN(submissionDeadline.getTime()) || new Date() > submissionDeadline; if (!isVisible) { return ( @@ -26,16 +28,18 @@ export const StickySubmissionInfo = () => { ✕

- Submissions
open + {isSubmissionClosed ? "Submissions closed" : "Submissions open"}

AUG 20 - SEP 2

- - Apply - + {!isSubmissionClosed && ( + + Apply + + )} Date: Tue, 3 Sep 2024 11:15:17 +0200 Subject: [PATCH 2/6] Restrict POST requests depending on env var --- packages/nextjs/app/api/submissions/route.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/nextjs/app/api/submissions/route.ts b/packages/nextjs/app/api/submissions/route.ts index b36b410..602e142 100644 --- a/packages/nextjs/app/api/submissions/route.ts +++ b/packages/nextjs/app/api/submissions/route.ts @@ -26,6 +26,11 @@ export type CreateNewSubmissionBody = SubmissionInsert & { signature: `0x${strin export async function POST(req: Request) { try { + const submissionDeadline = new Date(process.env.NEXT_PUBLIC_SUBMISSION_DEADLINE || ""); + if (isNaN(submissionDeadline.getTime()) || new Date() > submissionDeadline) { + return NextResponse.json({ error: "Submissions are closed" }, { status: 403 }); + } + const { title, description, telegram, linkToRepository, linkToVideo, feedback, signature, builder } = (await req.json()) as CreateNewSubmissionBody; From 2185b28bbf9cb1da4ef90afd436ebd22d0d490d9 Mon Sep 17 00:00:00 2001 From: pabl0cks Date: Tue, 3 Sep 2024 11:16:27 +0200 Subject: [PATCH 3/6] Manage submit button depending on env var --- .../nextjs/app/submit/_component/SubmitButton.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/nextjs/app/submit/_component/SubmitButton.tsx b/packages/nextjs/app/submit/_component/SubmitButton.tsx index dc5adf2..4230129 100644 --- a/packages/nextjs/app/submit/_component/SubmitButton.tsx +++ b/packages/nextjs/app/submit/_component/SubmitButton.tsx @@ -4,17 +4,23 @@ import { useFormStatus } from "react-dom"; import { useAccount } from "wagmi"; import { RainbowKitCustomConnectButton } from "~~/components/scaffold-eth"; -// To use useFormStatus we need to make sure button is child of form const SubmitButton = () => { const { pending } = useFormStatus(); const { isConnected } = useAccount(); + const submissionDeadline = new Date(process.env.NEXT_PUBLIC_SUBMISSION_DEADLINE || ""); + const isSubmissionClosed = isNaN(submissionDeadline.getTime()) || Date.now() > submissionDeadline.getTime(); + return (
- {isConnected ? ( + {isSubmissionClosed ? ( + + ) : isConnected ? (