-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Implement Model-Specific Claim/Apply/Join Actions #60
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
Merged
0xdevcollins
merged 7 commits into
boundlessfi:main
from
Michaelkingsdev:claim-apply-join
Jan 30, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1930e25
feat: Implement Model-Specific Claim/Apply/Join Actions
Michaelkingsdev 13fac63
fix: fix lint errors
Michaelkingsdev 4888538
fix: implement coderabbit correction
Michaelkingsdev 07e1e84
fix: implement coderabbit correction
Michaelkingsdev 2235ace
fix: implement coderabbit correction
Michaelkingsdev 1442e64
fix merge conflict
Michaelkingsdev 64d4ad8
fix lint error
Michaelkingsdev 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
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
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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { NextResponse } from 'next/server'; | ||
| import { BountyStore } from '@/lib/store'; | ||
| import { addDays } from 'date-fns'; | ||
| import { getCurrentUser } from '@/lib/server-auth'; | ||
|
|
||
| export async function POST( | ||
| request: Request, | ||
| { params }: { params: Promise<{ id: string }> } | ||
| ) { | ||
| const { id: bountyId } = await params; | ||
|
|
||
| try { | ||
| const user = await getCurrentUser(); | ||
| if (!user) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | ||
| } | ||
|
|
||
| const body = await request.json(); | ||
| const { contributorId } = body; | ||
|
|
||
| // If client sends contributorId, ensure it matches the authenticated user | ||
| if (contributorId && contributorId !== user.id) { | ||
| return NextResponse.json({ error: 'Contributor ID mismatch' }, { status: 403 }); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const bounty = BountyStore.getBountyById(bountyId); | ||
| if (!bounty) { | ||
| return NextResponse.json({ error: 'Bounty not found' }, { status: 404 }); | ||
| } | ||
|
|
||
| if (bounty.claimingModel !== 'single-claim') { | ||
| return NextResponse.json({ error: 'Invalid claiming model for this action' }, { status: 400 }); | ||
| } | ||
|
|
||
| if (bounty.status !== 'open') { | ||
| return NextResponse.json({ error: 'Bounty is not available' }, { status: 409 }); | ||
| } | ||
|
|
||
| const now = new Date(); | ||
| const updates = { | ||
| status: 'claimed' as const, | ||
| claimedBy: user.id, // Use authenticated user ID | ||
| claimedAt: now.toISOString(), | ||
| claimExpiresAt: addDays(now, 7).toISOString(), | ||
| updatedAt: now.toISOString() | ||
| }; | ||
|
|
||
| const updatedBounty = BountyStore.updateBounty(bountyId, updates); | ||
|
|
||
| if (!updatedBounty) { | ||
| return NextResponse.json({ success: false, error: 'Failed to update bounty' }, { status: 500 }); | ||
| } | ||
|
|
||
| return NextResponse.json({ success: true, data: updatedBounty }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Michaelkingsdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| } catch (error) { | ||
| console.error('Error claiming bounty:', error); | ||
| return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 }); | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { NextResponse } from 'next/server'; | ||
| import { BountyStore } from '@/lib/store'; | ||
| import { CompetitionParticipation } from '@/types/participation'; | ||
| import { getCurrentUser } from '@/lib/server-auth'; | ||
|
|
||
| const generateId = () => crypto.randomUUID(); | ||
|
|
||
| export async function POST( | ||
| request: Request, | ||
| { params }: { params: Promise<{ id: string }> } | ||
| ) { | ||
| const { id: bountyId } = await params; | ||
|
|
||
| try { | ||
| const user = await getCurrentUser(); | ||
| if (!user) { | ||
| return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | ||
| } | ||
|
|
||
| const bounty = BountyStore.getBountyById(bountyId); | ||
| if (!bounty) { | ||
| return NextResponse.json({ error: 'Bounty not found' }, { status: 404 }); | ||
| } | ||
|
|
||
| if (bounty.claimingModel !== 'competition') { | ||
| return NextResponse.json({ error: 'Invalid claiming model for this action' }, { status: 400 }); | ||
| } | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Validate status is open | ||
| if (bounty.status !== 'open') { | ||
| return NextResponse.json({ error: 'Bounty is not open for registration' }, { status: 409 }); | ||
| } | ||
|
|
||
| const existing = BountyStore.getCompetitionParticipationsByBounty(bountyId) | ||
| .find(p => p.contributorId === user.id); | ||
|
|
||
| if (existing) { | ||
| return NextResponse.json({ error: 'Already joined this competition' }, { status: 409 }); | ||
| } | ||
|
|
||
| const participation: CompetitionParticipation = { | ||
| id: generateId(), | ||
| bountyId, | ||
| contributorId: user.id, // Use authenticated user ID | ||
| status: 'registered', | ||
| registeredAt: new Date().toISOString() | ||
| }; | ||
|
|
||
| BountyStore.addCompetitionParticipation(participation); | ||
Michaelkingsdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return NextResponse.json({ success: true, data: participation }); | ||
|
|
||
| } catch (error) { | ||
| console.error('Error joining competition:', error); | ||
| return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 }); | ||
| } | ||
| } | ||
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| "use client" | ||
|
|
||
| import { useState } from "react" | ||
| import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog" | ||
| import { Button } from "@/components/ui/button" | ||
| import { Label } from "@/components/ui/label" | ||
| import { Textarea } from "@/components/ui/textarea" | ||
| import { Input } from "@/components/ui/input" | ||
|
|
||
| interface ApplicationDialogProps { | ||
| bountyTitle: string | ||
| onApply: (data: { coverLetter: string, portfolioUrl?: string }) => Promise<boolean> | ||
| trigger: React.ReactNode | ||
| } | ||
|
|
||
| export function ApplicationDialog({ bountyTitle, onApply, trigger }: ApplicationDialogProps) { | ||
| const [open, setOpen] = useState(false) | ||
| const [loading, setLoading] = useState(false) | ||
| const [coverLetter, setCoverLetter] = useState("") | ||
| const [portfolioUrl, setPortfolioUrl] = useState("") | ||
|
|
||
| const handleSubmit = async (e: React.FormEvent) => { | ||
| e.preventDefault() | ||
| setLoading(true) | ||
| try { | ||
| const success = await onApply({ coverLetter, portfolioUrl }) | ||
| if (success) { | ||
| setOpen(false) | ||
| } | ||
| } catch (error) { | ||
| console.error("Failed to submit application", error) | ||
| } finally { | ||
| setLoading(false) | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <Dialog open={open} onOpenChange={setOpen}> | ||
| <DialogTrigger asChild> | ||
| {trigger} | ||
| </DialogTrigger> | ||
| <DialogContent className="sm:max-w-[525px] bg-background text-foreground border-border"> | ||
| <DialogHeader> | ||
| <DialogTitle>Apply for Bounty</DialogTitle> | ||
| <DialogDescription> | ||
| Submit your application for "{bountyTitle}". | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <form onSubmit={handleSubmit}> | ||
| <div className="grid gap-4 py-4"> | ||
| <div className="grid gap-2"> | ||
| <Label htmlFor="coverLetter">Cover Letter</Label> | ||
| <Textarea | ||
| id="coverLetter" | ||
| placeholder="Explain why you are a good fit..." | ||
| className="min-h-[150px]" | ||
| value={coverLetter} | ||
| onChange={(e) => setCoverLetter(e.target.value)} | ||
| required | ||
| /> | ||
| </div> | ||
| <div className="grid gap-2"> | ||
| <Label htmlFor="portfolio">Portfolio URL (Optional)</Label> | ||
| <Input | ||
| id="portfolio" | ||
| placeholder="https://..." | ||
| value={portfolioUrl} | ||
| onChange={(e) => setPortfolioUrl(e.target.value)} | ||
| /> | ||
| </div> | ||
| </div> | ||
| <DialogFooter> | ||
| <Button type="button" variant="ghost" onClick={() => setOpen(false)}>Cancel</Button> | ||
| <Button type="submit" disabled={loading}> | ||
| {loading ? "Submitting..." : "Submit Application"} | ||
| </Button> | ||
| </DialogFooter> | ||
| </form> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ) | ||
| } | ||
Michaelkingsdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.