Skip to content

Commit

Permalink
Add configuration to enable or disable submissions (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pabl0cks authored Sep 10, 2024
1 parent e5b1864 commit 80a8262
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions packages/nextjs/app/api/submissions/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { recoverTypedDataAddress } from "viem";
import scaffoldConfig from "~~/scaffold.config";
import { createBuilder, getBuilderById } from "~~/services/database/repositories/builders";
import { createSubmission, getAllSubmissions } from "~~/services/database/repositories/submissions";
import { SubmissionInsert } from "~~/services/database/repositories/submissions";
Expand All @@ -26,8 +27,8 @@ export type CreateNewSubmissionBody = SubmissionInsert & { signature: `0x${strin

export async function POST(req: Request) {
try {
const isSubmissionClosed = true;
if (isSubmissionClosed) {
const { submissionsEnabled } = scaffoldConfig;
if (!submissionsEnabled) {
return NextResponse.json({ error: "Submissions are closed" }, { status: 403 });
}

Expand Down
9 changes: 5 additions & 4 deletions packages/nextjs/app/submit/_component/SubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import { useFormStatus } from "react-dom";
import { useAccount } from "wagmi";
import { RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
import scaffoldConfig from "~~/scaffold.config";

const SubmitButton = () => {
const { pending } = useFormStatus();
const { isConnected } = useAccount();
const isSubmissionClosed = true;
const { submissionsEnabled } = scaffoldConfig;

return (
<div
className={`items-center flex flex-col ${!isConnected && !isSubmissionClosed && "tooltip tooltip-bottom"}`}
data-tip={`${!isConnected && !isSubmissionClosed ? "Please connect your wallet" : ""}`}
className={`items-center flex flex-col ${!isConnected && submissionsEnabled && "tooltip tooltip-bottom"}`}
data-tip={`${!isConnected && submissionsEnabled ? "Please connect your wallet" : ""}`}
>
{isSubmissionClosed ? (
{!submissionsEnabled ? (
<button className="btn border border-black px-6 text-lg h-10 min-h-10 font-medium" disabled>
Submissions Closed
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useState } from "react";
import Link from "next/link";
import scaffoldConfig from "~~/scaffold.config";

export const StickySubmissionInfo = () => {
const [isVisible, setIsVisible] = useState(true);
const isSubmissionClosed = true;
const { submissionsEnabled } = scaffoldConfig;

if (!isVisible) {
return (
Expand All @@ -27,11 +28,11 @@ export const StickySubmissionInfo = () => {
</button>
<h2 className="text-2xl underline mb-0 md:mb-4 2xl:text-3xl 2xl:mb-6">
{isSubmissionClosed ? "Submissions closed" : "Submissions open"}
{submissionsEnabled ? "Submissions open" : "Submissions closed"}
</h2>
<p className="md:mb-10 mt-2 2xl:text-xl 2xl:mb-12 2xl:mt-4">AUG 20 - SEP 2</p>
<div className="flex md:block space-x-2 2xl:space-x-4">
{!isSubmissionClosed && (
{submissionsEnabled && (
<Link
href="/submit"
className="bg-[#B7EBEC] py-2 px-2 sm:px-4 border border-1 border-black text-center flex-1 2xl:py-3 2xl:px-6 text-sm sm:text-base 2xl:text-xl"
Expand Down
4 changes: 4 additions & 0 deletions packages/nextjs/scaffold.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type ScaffoldConfig = {
votingEnabled: boolean;
winnersThreshold: number;
runnersUpThreshold: number;
submissionsEnabled: boolean;
};

const scaffoldConfig = {
Expand All @@ -34,6 +35,9 @@ const scaffoldConfig = {
// Only show the Burner Wallet when running on hardhat network
onlyLocalBurnerWallet: true,

// Enable submissions
submissionsEnabled: false,

// Enable voting on submissions
votingEnabled: false,

Expand Down

0 comments on commit 80a8262

Please sign in to comment.