-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add structured submission form with draft saving and success state #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
od-hunter
wants to merge
1
commit into
boundlessfi:main
Choose a base branch
from
od-hunter:feat/submission-flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+965
−1,047
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,55 +1,89 @@ | ||
| import { NextResponse } from 'next/server'; | ||
| import { BountyStore } from '@/lib/store'; | ||
| import { Submission } from '@/types/participation'; | ||
| import { NextResponse } from "next/server"; | ||
| import { BountyStore } from "@/lib/store"; | ||
| import { Submission } from "@/types/participation"; | ||
| import { submissionFormSchema } from "@/components/bounty/forms/schemas"; | ||
|
|
||
| const generateId = () => crypto.randomUUID(); | ||
|
|
||
| export async function POST( | ||
| request: Request, | ||
| { params }: { params: Promise<{ id: string }> } | ||
| request: Request, | ||
| { params }: { params: Promise<{ id: string }> }, | ||
| ) { | ||
| const { id: bountyId } = await params; | ||
| const { id: bountyId } = await params; | ||
|
|
||
| try { | ||
| const body = await request.json(); | ||
| const { contributorId, content } = body; | ||
| try { | ||
| const body = await request.json(); | ||
| const { contributorId, ...formData } = body; | ||
|
|
||
| if (!contributorId || !content) { | ||
| return NextResponse.json({ error: 'Missing required fields' }, { status: 400 }); | ||
| } | ||
| if (!contributorId) { | ||
| return NextResponse.json( | ||
| { error: "Missing contributor ID" }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
|
|
||
| const bounty = BountyStore.getBountyById(bountyId); | ||
| if (!bounty) { | ||
| return NextResponse.json({ error: 'Bounty not found' }, { status: 404 }); | ||
| } | ||
| const parsed = submissionFormSchema.safeParse(formData); | ||
| if (!parsed.success) { | ||
| const fieldErrors = parsed.error.flatten().fieldErrors; | ||
| return NextResponse.json( | ||
| { error: "Validation failed", fieldErrors }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
|
|
||
| const allowedModels = ['single-claim', 'competition', 'multi-winner', 'application']; | ||
| if (!allowedModels.includes(bounty.claimingModel)) { | ||
| return NextResponse.json({ error: 'Submission not allowed for this bounty type' }, { status: 400 }); | ||
| } | ||
| const bounty = BountyStore.getBountyById(bountyId); | ||
| if (!bounty) { | ||
| return NextResponse.json({ error: "Bounty not found" }, { status: 404 }); | ||
| } | ||
|
|
||
| const existingSubmission = BountyStore.getSubmissionsByBounty(bountyId).find( | ||
| s => s.contributorId === contributorId | ||
| ); | ||
| const allowedModels = [ | ||
| "single-claim", | ||
| "competition", | ||
| "multi-winner", | ||
| "application", | ||
| ]; | ||
| if (!allowedModels.includes(bounty.claimingModel)) { | ||
| return NextResponse.json( | ||
| { error: "Submission not allowed for this bounty type" }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
|
|
||
| if (existingSubmission) { | ||
| return NextResponse.json({ error: 'Duplicate submission' }, { status: 409 }); | ||
| } | ||
| const existingSubmission = BountyStore.getSubmissionsByBounty( | ||
| bountyId, | ||
| ).find((s) => s.contributorId === contributorId); | ||
|
|
||
| const submission: Submission = { | ||
| id: generateId(), | ||
| bountyId, | ||
| contributorId, | ||
| content, | ||
| status: 'pending', | ||
| submittedAt: new Date().toISOString(), | ||
| }; | ||
| if (existingSubmission) { | ||
| return NextResponse.json( | ||
| { error: "Duplicate submission" }, | ||
| { status: 409 }, | ||
| ); | ||
| } | ||
|
|
||
| BountyStore.addSubmission(submission); | ||
| const { explanation, walletAddress, githubUrl, demoUrl, attachments } = | ||
| parsed.data; | ||
|
|
||
| return NextResponse.json({ success: true, data: submission }); | ||
| const submission: Submission = { | ||
| id: generateId(), | ||
| bountyId, | ||
| contributorId, | ||
| content: explanation, | ||
| explanation, | ||
| walletAddress, | ||
| githubUrl: githubUrl || undefined, | ||
| demoUrl: demoUrl || undefined, | ||
| attachments: attachments?.length ? attachments : undefined, | ||
| status: "pending", | ||
| submittedAt: new Date().toISOString(), | ||
| }; | ||
|
|
||
| } catch { | ||
| return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 }); | ||
| } | ||
| BountyStore.addSubmission(submission); | ||
|
|
||
| return NextResponse.json({ success: true, data: submission }); | ||
| } catch { | ||
| return NextResponse.json( | ||
| { error: "Internal Server Error" }, | ||
| { status: 500 }, | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing bounty status check — submissions can be made to closed/claimed bounties.
The route verifies the bounty exists and checks the claiming model, but never validates
bounty.status === "open". The frontend disables the button for non-open bounties, but a direct API call can bypass this, allowing submissions to closed or already-claimed bounties.🐛 Proposed fix
const bounty = BountyStore.getBountyById(bountyId); if (!bounty) { return NextResponse.json({ error: "Bounty not found" }, { status: 404 }); } + if (bounty.status !== "open") { + return NextResponse.json( + { error: "This bounty is no longer accepting submissions" }, + { status: 400 }, + ); + } + const allowedModels = [🤖 Prompt for AI Agents