|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useState } from 'react'; |
| 4 | +import Link from 'next/link'; |
| 5 | +import { ExternalLink, Loader2 } from 'lucide-react'; |
| 6 | + |
| 7 | +import { Badge } from '@/components/ui/badge'; |
| 8 | +import EmptyState from '@/components/EmptyState'; |
| 9 | +import { computeBountyModeLabel } from '@/components/organization/bounties/new/tabs/schemas/modeSchema'; |
| 10 | +import { |
| 11 | + useMyBountyApplications, |
| 12 | + useMyBountySubmissions, |
| 13 | + type BountyActivitySummary, |
| 14 | + type MyBountyApplicationRow, |
| 15 | + type MyBountySubmissionRow, |
| 16 | +} from '@/features/bounties'; |
| 17 | + |
| 18 | +type Tab = 'applications' | 'submissions'; |
| 19 | + |
| 20 | +const APP_STATUS: Record<string, { label: string; className: string }> = { |
| 21 | + SUBMITTED: { label: 'Submitted', className: 'bg-blue-500/10 text-blue-400' }, |
| 22 | + SHORTLISTED: { |
| 23 | + label: 'Shortlisted', |
| 24 | + className: 'bg-amber-500/10 text-amber-400', |
| 25 | + }, |
| 26 | + SELECTED: { |
| 27 | + label: 'Selected', |
| 28 | + className: 'bg-emerald-500/10 text-emerald-400', |
| 29 | + }, |
| 30 | + DECLINED: { label: 'Not selected', className: 'bg-red-500/10 text-red-400' }, |
| 31 | + WITHDRAWN: { label: 'Withdrawn', className: 'bg-zinc-700/60 text-zinc-300' }, |
| 32 | +}; |
| 33 | + |
| 34 | +/** Map a submission's review status to a builder-facing progress label. */ |
| 35 | +function submissionProgress(s: MyBountySubmissionRow): { |
| 36 | + label: string; |
| 37 | + className: string; |
| 38 | +} { |
| 39 | + if (s.tierPosition != null) |
| 40 | + return { label: 'Won', className: 'bg-emerald-500/10 text-emerald-400' }; |
| 41 | + switch (s.status) { |
| 42 | + case 'in_review': |
| 43 | + case 'under_review': |
| 44 | + return { label: 'In review', className: 'bg-blue-500/10 text-blue-400' }; |
| 45 | + case 'accepted': |
| 46 | + case 'approved': |
| 47 | + return { |
| 48 | + label: 'Accepted', |
| 49 | + className: 'bg-emerald-500/10 text-emerald-400', |
| 50 | + }; |
| 51 | + case 'rejected': |
| 52 | + case 'closed': |
| 53 | + return { label: 'Closed', className: 'bg-zinc-700/60 text-zinc-300' }; |
| 54 | + default: |
| 55 | + return { label: 'Submitted', className: 'bg-blue-500/10 text-blue-400' }; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +function mode(b: BountyActivitySummary): string { |
| 60 | + return b.entryType && b.claimType |
| 61 | + ? computeBountyModeLabel(b.entryType, b.claimType) |
| 62 | + : 'Bounty'; |
| 63 | +} |
| 64 | + |
| 65 | +const fmtDate = (iso: string | null): string => |
| 66 | + iso |
| 67 | + ? new Date(iso).toLocaleDateString(undefined, { |
| 68 | + month: 'short', |
| 69 | + day: 'numeric', |
| 70 | + year: 'numeric', |
| 71 | + }) |
| 72 | + : '—'; |
| 73 | + |
| 74 | +export default function MyBountiesPage() { |
| 75 | + const [tab, setTab] = useState<Tab>('applications'); |
| 76 | + const applications = useMyBountyApplications(); |
| 77 | + const submissions = useMyBountySubmissions(); |
| 78 | + |
| 79 | + const active = tab === 'applications' ? applications : submissions; |
| 80 | + const rows = |
| 81 | + tab === 'applications' |
| 82 | + ? (applications.data?.items ?? []) |
| 83 | + : (submissions.data?.items ?? []); |
| 84 | + |
| 85 | + return ( |
| 86 | + <div className='mx-auto max-w-5xl px-4 py-8'> |
| 87 | + <h1 className='text-2xl font-bold tracking-tight text-white'> |
| 88 | + My bounties |
| 89 | + </h1> |
| 90 | + <p className='mt-1 text-sm text-zinc-400'> |
| 91 | + Track your applications, submissions, and results. |
| 92 | + </p> |
| 93 | + |
| 94 | + {/* Tabs */} |
| 95 | + <div className='mt-6 mb-4 flex gap-2'> |
| 96 | + {(['applications', 'submissions'] as Tab[]).map(t => ( |
| 97 | + <button |
| 98 | + key={t} |
| 99 | + onClick={() => setTab(t)} |
| 100 | + className={`rounded-full px-4 py-2 text-sm font-medium capitalize transition-all ${ |
| 101 | + tab === t |
| 102 | + ? 'bg-primary text-black' |
| 103 | + : 'bg-zinc-900 text-white hover:bg-zinc-800' |
| 104 | + }`} |
| 105 | + > |
| 106 | + {t} |
| 107 | + </button> |
| 108 | + ))} |
| 109 | + </div> |
| 110 | + |
| 111 | + {active.isLoading ? ( |
| 112 | + <div className='flex items-center justify-center py-20'> |
| 113 | + <Loader2 className='h-6 w-6 animate-spin text-zinc-500' /> |
| 114 | + </div> |
| 115 | + ) : rows.length === 0 ? ( |
| 116 | + <div className='py-16'> |
| 117 | + <EmptyState |
| 118 | + title={`No ${tab} yet`} |
| 119 | + description={ |
| 120 | + tab === 'applications' |
| 121 | + ? 'Apply to a bounty and it will show up here.' |
| 122 | + : 'Submit your work on a bounty and it will show up here.' |
| 123 | + } |
| 124 | + type='compact' |
| 125 | + /> |
| 126 | + </div> |
| 127 | + ) : ( |
| 128 | + <div className='overflow-hidden rounded-xl border border-zinc-800'> |
| 129 | + {tab === 'applications' |
| 130 | + ? (rows as MyBountyApplicationRow[]).map(row => ( |
| 131 | + <ApplicationRow key={row.id} row={row} /> |
| 132 | + )) |
| 133 | + : (rows as MyBountySubmissionRow[]).map(row => ( |
| 134 | + <SubmissionRow key={row.id} row={row} /> |
| 135 | + ))} |
| 136 | + </div> |
| 137 | + )} |
| 138 | + </div> |
| 139 | + ); |
| 140 | +} |
| 141 | + |
| 142 | +function ApplicationRow({ row }: { row: MyBountyApplicationRow }) { |
| 143 | + const status = row.applicationStatus |
| 144 | + ? (APP_STATUS[row.applicationStatus] ?? { |
| 145 | + label: row.applicationStatus, |
| 146 | + className: 'bg-zinc-700/60 text-zinc-300', |
| 147 | + }) |
| 148 | + : { label: 'Claimed', className: 'bg-emerald-500/10 text-emerald-400' }; |
| 149 | + |
| 150 | + return ( |
| 151 | + <Link |
| 152 | + href={`/bounties/${row.bounty.id}`} |
| 153 | + className='flex items-center justify-between gap-4 border-b border-zinc-800 px-4 py-3 transition-colors last:border-0 hover:bg-zinc-900/50' |
| 154 | + > |
| 155 | + <div className='min-w-0'> |
| 156 | + <p className='truncate text-sm font-medium text-white'> |
| 157 | + {row.bounty.title} |
| 158 | + </p> |
| 159 | + <p className='text-xs text-zinc-500'> |
| 160 | + {mode(row.bounty)} · applied {fmtDate(row.createdAt)} |
| 161 | + </p> |
| 162 | + </div> |
| 163 | + <Badge |
| 164 | + variant='outline' |
| 165 | + className={`shrink-0 rounded-full border-transparent px-3 py-1 text-xs font-medium ${status.className}`} |
| 166 | + > |
| 167 | + {status.label} |
| 168 | + </Badge> |
| 169 | + </Link> |
| 170 | + ); |
| 171 | +} |
| 172 | + |
| 173 | +function SubmissionRow({ row }: { row: MyBountySubmissionRow }) { |
| 174 | + const progress = submissionProgress(row); |
| 175 | + const won = row.tierPosition != null && row.tierAmount; |
| 176 | + |
| 177 | + return ( |
| 178 | + <div className='flex items-center justify-between gap-4 border-b border-zinc-800 px-4 py-3 last:border-0'> |
| 179 | + <Link href={`/bounties/${row.bounty.id}`} className='min-w-0 flex-1'> |
| 180 | + <p className='truncate text-sm font-medium text-white hover:underline'> |
| 181 | + {row.bounty.title} |
| 182 | + </p> |
| 183 | + <p className='text-xs text-zinc-500'> |
| 184 | + {mode(row.bounty)} · submitted {fmtDate(row.createdAt)} |
| 185 | + </p> |
| 186 | + </Link> |
| 187 | + |
| 188 | + <div className='flex shrink-0 items-center gap-3'> |
| 189 | + {won && ( |
| 190 | + <span className='text-primary text-sm font-semibold'> |
| 191 | + {Number(row.tierAmount).toLocaleString()}{' '} |
| 192 | + {row.bounty.rewardCurrency} |
| 193 | + </span> |
| 194 | + )} |
| 195 | + {row.rewardTransactionHash && ( |
| 196 | + <a |
| 197 | + href={`https://stellar.expert/explorer/testnet/tx/${row.rewardTransactionHash}`} |
| 198 | + target='_blank' |
| 199 | + rel='noreferrer' |
| 200 | + className='text-primary inline-flex items-center gap-1 text-xs hover:underline' |
| 201 | + title='View payout transaction' |
| 202 | + > |
| 203 | + tx |
| 204 | + <ExternalLink className='h-3 w-3' /> |
| 205 | + </a> |
| 206 | + )} |
| 207 | + <Badge |
| 208 | + variant='outline' |
| 209 | + className={`rounded-full border-transparent px-3 py-1 text-xs font-medium ${progress.className}`} |
| 210 | + > |
| 211 | + {progress.label} |
| 212 | + </Badge> |
| 213 | + </div> |
| 214 | + </div> |
| 215 | + ); |
| 216 | +} |
0 commit comments