generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/nextjs/app/api/builders/[builderAddress]/grants/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NextResponse } from "next/server"; | ||
import { getAllGrantsForUser } from "~~/services/database/grants"; | ||
|
||
export async function GET(_request: Request, { params }: { params: { builderAddress: string } }) { | ||
try { | ||
const builderAddress = params.builderAddress; | ||
const grants = await getAllGrantsForUser(builderAddress); | ||
return NextResponse.json(grants); | ||
} catch (error) { | ||
return NextResponse.json( | ||
{ error: "Internal Server Error" }, | ||
{ | ||
status: 500, | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use client"; | ||
|
||
import { NextPage } from "next"; | ||
import useSWR from "swr"; | ||
import { useAccount } from "wagmi"; | ||
import { GrantData } from "~~/services/database/schema"; | ||
import { PROPOSAL_STATUS } from "~~/utils/grants"; | ||
|
||
const badgeBgColor = { | ||
[PROPOSAL_STATUS.PROPOSED]: "bg-warning", | ||
[PROPOSAL_STATUS.APPROVED]: "bg-success", | ||
[PROPOSAL_STATUS.SUBMITTED]: "bg-warning", | ||
[PROPOSAL_STATUS.COMPLETED]: "bg-success", | ||
[PROPOSAL_STATUS.REJECTED]: "bg-error", | ||
}; | ||
|
||
// ToDo. Action (v1.0 = submit grant after completion) | ||
const MyGrants: NextPage = () => { | ||
const { address } = useAccount(); | ||
const { data: builderGrants, isLoading } = useSWR<GrantData[]>(address ? `/api/builders/${address}/grants` : null); | ||
|
||
return ( | ||
<div className="container mx-auto max-w-screen-md mt-12"> | ||
<h1 className="text-4xl font-bold">My grants</h1> | ||
{isLoading && <span className="loading loading-spinner"></span>} | ||
{builderGrants?.length === 0 && <p>No grants found</p>} | ||
{builderGrants?.map(grant => ( | ||
<div key={grant.id} className="border p-4 my-4"> | ||
<h3 className="font-bold"> | ||
{grant.title} | ||
<span className="text-sm text-gray-500 ml-2">({grant.id})</span> | ||
</h3> | ||
<p>{grant.description}</p> | ||
<p className={`badge ${badgeBgColor[grant.status]}`}>{grant.status}</p> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MyGrants; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters