From 0ab8407a220a418ed2fa173c7ffcfd99863f48d6 Mon Sep 17 00:00:00 2001 From: Styles Date: Mon, 23 Sep 2024 16:25:32 +0530 Subject: [PATCH] added a check for builder page - added a useEffect to check if builder page exists --- packages/nextjs/app/page.tsx | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index 2f31e78..e3fb1a0 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -1,5 +1,6 @@ "use client"; +import { useEffect, useState } from "react"; import Image from "next/image"; import Link from "next/link"; import type { NextPage } from "next"; @@ -10,6 +11,7 @@ import { useScaffoldReadContract } from "~~/hooks/scaffold-eth"; const Home: NextPage = () => { const { address: connectedAddress } = useAccount(); const zeroAddress = "0x0000000000000000000000000000000000000000"; + const [builderPageExists, setBuilderPageExists] = useState(false); const { data: isAllowed } = useScaffoldReadContract({ contractName: "BatchRegistry", @@ -32,6 +34,23 @@ const Home: NextPage = () => { console.log("Error fetching checkedInCounter", error); } + useEffect(() => { + const verifyBuilderPage = async (address: string) => { + try { + const response = await fetch(`/builders/${address}`); + setBuilderPageExists(response.status === 200); + } catch (error) { + setBuilderPageExists(false); + } + }; + + if (connectedAddress) { + verifyBuilderPage(connectedAddress); + } else { + setBuilderPageExists(false); + } + }, [connectedAddress]); + return (
@@ -78,31 +97,34 @@ const Home: NextPage = () => { {checkedInCounter === undefined && !error ? (
) : checkedInCounter ? ( -

- Checked-in Count: +

+ Checked-in count: {checkedInCounter.toString()}

) : null}
{/* Member Status */} - {isAllowed && IsCheckIn !== zeroAddress ? ( + {builderPageExists ? ( - Batch Member ✅ + Batch Member {isAllowed ? "✅" : "❌"} ) : ( -
+
Batch Member {isAllowed ? "✅" : "❌"}
)} {isAllowed && IsCheckIn !== zeroAddress ? ( -
+

Cheers 🍻.. You are checked in!

) : (