-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: pabl0cks <[email protected]>
- Loading branch information
1 parent
693d592
commit b6517b3
Showing
4 changed files
with
140 additions
and
21 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/nextjs/app/api/users/[address]/submissions/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,18 @@ | ||
import { NextResponse } from "next/server"; | ||
import { getSubmissionsByBuilder } from "~~/services/database/repositories/submissions"; | ||
|
||
export async function GET(request: Request, { params }: { params: { address: string } }) { | ||
try { | ||
const { address } = params; | ||
|
||
if (!address) { | ||
return NextResponse.json({ error: "Address not provided" }, { status: 400 }); | ||
} | ||
|
||
const submissions = await getSubmissionsByBuilder(address); | ||
return NextResponse.json(submissions); | ||
} catch (error) { | ||
console.error(error); | ||
return NextResponse.json({ error: "Error fetching submissions" }, { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
import { SubmissionCard } from "../submissions/_components/SubmissionCard"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useAccount } from "wagmi"; | ||
import { RainbowKitCustomConnectButton } from "~~/components/scaffold-eth"; | ||
import scaffoldConfig from "~~/scaffold.config"; | ||
import { SubmissionWithWinnerTag } from "~~/services/database/repositories/submissions"; | ||
|
||
const MySubmissions = () => { | ||
const { address: connectedAddress, isConnecting } = useAccount(); | ||
const router = useRouter(); | ||
const { submissionsEnabled } = scaffoldConfig; | ||
|
||
const { | ||
isPending, | ||
error, | ||
data: submissions, | ||
} = useQuery({ | ||
queryKey: ["my-submissions", connectedAddress], | ||
queryFn: () => fetch(`/api/users/${connectedAddress}/submissions`).then(res => res.json()), | ||
}); | ||
|
||
if (isConnecting || isPending) { | ||
return <div className="max-w-7xl container mx-auto px-6 mt-10">Loading...</div>; | ||
} | ||
|
||
if (error) { | ||
return <div className="max-w-7xl container mx-auto px-6 mt-10">Error loading submissions.</div>; | ||
} | ||
|
||
return ( | ||
<div className="max-w-7xl container mx-auto px-6 mt-10"> | ||
{!connectedAddress ? ( | ||
<div className="max-w-7xl container mx-auto px-6 mt-10"> | ||
<span className="mr-4">Connect Wallet to see your submissions</span> | ||
<RainbowKitCustomConnectButton /> | ||
</div> | ||
) : ( | ||
<div> | ||
<h1 className="text-4xl font-bold mb-6">My Submissions</h1> | ||
{submissions.length === 0 ? ( | ||
<div className="flex flex-col items-center"> | ||
{submissionsEnabled ? ( | ||
<> | ||
<p className="mb-4">You haven't made any submissions yet.</p> | ||
<button onClick={() => router.push("/submit")} className="btn btn-primary"> | ||
Submit an Extension | ||
</button> | ||
</> | ||
) : ( | ||
<> | ||
<p className="mb-4">You haven't made any submissions.</p> | ||
<button className="btn btn-disabled" disabled> | ||
Submissions Closed | ||
</button> | ||
</> | ||
)} | ||
</div> | ||
) : ( | ||
<div className="grid gap-6 md:grid-cols-2 xl:grid-cols-3"> | ||
{submissions.map((submission: SubmissionWithWinnerTag) => ( | ||
<SubmissionCard key={submission.id} submission={submission} /> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MySubmissions; |
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