feat: implement fund application process with admin review and user submission
This commit is contained in:
+16
-6
@@ -22,13 +22,14 @@ model User {
|
|||||||
isFund Boolean @default(false)
|
isFund Boolean @default(false)
|
||||||
isHidden Boolean @default(false) // hidden from leaderboards and public listings
|
isHidden Boolean @default(false) // hidden from leaderboards and public listings
|
||||||
|
|
||||||
positions Position[]
|
positions Position[]
|
||||||
trades Trade[]
|
trades Trade[]
|
||||||
passwordResets PasswordReset[]
|
passwordResets PasswordReset[]
|
||||||
managedFunds FundManager[]
|
managedFunds FundManager[]
|
||||||
fund HedgeFund?
|
fund HedgeFund?
|
||||||
fundInvestments FundInvestment[]
|
fundInvestments FundInvestment[]
|
||||||
portfolioHistory UserPortfolioHistory[]
|
portfolioHistory UserPortfolioHistory[]
|
||||||
|
fundApplication FundApplication?
|
||||||
}
|
}
|
||||||
|
|
||||||
model HedgeFund {
|
model HedgeFund {
|
||||||
@@ -213,3 +214,12 @@ enum TradeType {
|
|||||||
FUND_INVEST // invested cash into a hedge fund
|
FUND_INVEST // invested cash into a hedge fund
|
||||||
FUND_REDEEM // redeemed shares from a hedge fund
|
FUND_REDEEM // redeemed shares from a hedge fund
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model FundApplication {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
userId String @unique
|
||||||
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
fundName String
|
||||||
|
reason String
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
}
|
||||||
|
|||||||
@@ -149,6 +149,12 @@ export default function AboutPage() {
|
|||||||
Fund shares are stored to 6 decimal places. Fund accounts cannot sign in directly and do not earn
|
Fund shares are stored to 6 decimal places. Fund accounts cannot sign in directly and do not earn
|
||||||
research points or play the lottery.
|
research points or play the lottery.
|
||||||
</p>
|
</p>
|
||||||
|
<p className="text-xs">
|
||||||
|
Want to run your own fund?{' '}
|
||||||
|
<Link href="/fund/apply" className="text-indigo-400 hover:text-indigo-300 underline underline-offset-2">
|
||||||
|
Apply here →
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
import { FileText, Check, X, ChevronDown, ChevronUp } from 'lucide-react'
|
||||||
|
|
||||||
|
interface Applicant {
|
||||||
|
id: string
|
||||||
|
username: string
|
||||||
|
displayUsername: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Application {
|
||||||
|
id: string
|
||||||
|
fundName: string
|
||||||
|
reason: string
|
||||||
|
createdAt: string
|
||||||
|
user: Applicant
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AdminFundApplications({ applications: initial }: { applications: Application[] }) {
|
||||||
|
const router = useRouter()
|
||||||
|
const [applications, setApplications] = useState<Application[]>(initial)
|
||||||
|
const [expanded, setExpanded] = useState<string | null>(null)
|
||||||
|
const [approveId, setApproveId] = useState<string | null>(null)
|
||||||
|
const [startingBalance, setStartingBalance] = useState('0')
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
async function approve(app: Application) {
|
||||||
|
setLoading(true)
|
||||||
|
setError('')
|
||||||
|
const res = await fetch(`/api/admin/fund-applications/${app.id}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ action: 'approve', startingBalance: parseFloat(startingBalance) || 0 }),
|
||||||
|
})
|
||||||
|
const data = await res.json()
|
||||||
|
setLoading(false)
|
||||||
|
if (!res.ok) { setError(data.error ?? 'Failed'); return }
|
||||||
|
setApplications(applications.filter((a) => a.id !== app.id))
|
||||||
|
setApproveId(null)
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deny(id: string) {
|
||||||
|
if (!confirm('Deny this application? The applicant will not be notified.')) return
|
||||||
|
setLoading(true)
|
||||||
|
const res = await fetch(`/api/admin/fund-applications/${id}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ action: 'deny' }),
|
||||||
|
})
|
||||||
|
setLoading(false)
|
||||||
|
if (res.ok) {
|
||||||
|
setApplications(applications.filter((a) => a.id !== id))
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applications.length === 0) {
|
||||||
|
return (
|
||||||
|
<p className="text-slate-500 text-sm">No pending fund applications.</p>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
{error && (
|
||||||
|
<p className="text-red-400 text-sm bg-red-400/10 border border-red-400/20 rounded-lg px-3 py-2">{error}</p>
|
||||||
|
)}
|
||||||
|
{applications.map((app) => (
|
||||||
|
<div key={app.id} className="bg-surface-card border border-amber-500/20 rounded-xl overflow-hidden">
|
||||||
|
<div className="flex items-start justify-between px-4 py-3">
|
||||||
|
<div className="flex items-start gap-3 min-w-0">
|
||||||
|
<FileText className="h-4 w-4 text-amber-400 mt-0.5 shrink-0" />
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="font-medium text-sm">{app.fundName}</p>
|
||||||
|
<p className="text-xs text-slate-500">
|
||||||
|
by{' '}
|
||||||
|
<span className="text-slate-300">{app.user.displayUsername ?? app.user.username}</span>
|
||||||
|
{' '}· {new Date(app.createdAt).toLocaleDateString()}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 ml-4 shrink-0">
|
||||||
|
<button
|
||||||
|
onClick={() => setExpanded(expanded === app.id ? null : app.id)}
|
||||||
|
className="text-slate-400 hover:text-slate-200 transition-colors"
|
||||||
|
aria-label="Toggle reason"
|
||||||
|
>
|
||||||
|
{expanded === app.id ? <ChevronUp className="h-4 w-4" /> : <ChevronDown className="h-4 w-4" />}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => deny(app.id)}
|
||||||
|
disabled={loading}
|
||||||
|
className="p-1.5 text-red-400 hover:text-red-300 hover:bg-red-400/10 rounded-lg transition-colors disabled:opacity-50"
|
||||||
|
title="Deny application"
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setApproveId(approveId === app.id ? null : app.id)}
|
||||||
|
disabled={loading}
|
||||||
|
className="p-1.5 text-green-400 hover:text-green-300 hover:bg-green-400/10 rounded-lg transition-colors disabled:opacity-50"
|
||||||
|
title="Approve application"
|
||||||
|
>
|
||||||
|
<Check className="h-4 w-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{expanded === app.id && (
|
||||||
|
<div className="px-4 pb-3 text-sm text-slate-300 whitespace-pre-wrap border-t border-surface-border pt-3">
|
||||||
|
{app.reason}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{approveId === app.id && (
|
||||||
|
<div className="px-4 pb-4 border-t border-surface-border pt-3 space-y-3">
|
||||||
|
<p className="text-xs text-slate-400">
|
||||||
|
Approve <span className="text-white font-medium">{app.fundName}</span> for{' '}
|
||||||
|
<span className="text-slate-200">{app.user.displayUsername ?? app.user.username}</span>
|
||||||
|
</p>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div>
|
||||||
|
<label className="text-xs text-slate-500 block mb-1">Starting Balance ($)</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
value={startingBalance}
|
||||||
|
onChange={(e) => setStartingBalance(e.target.value)}
|
||||||
|
className="w-32 bg-surface border border-surface-border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-green-500"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2 mt-4">
|
||||||
|
<button
|
||||||
|
onClick={() => approve(app)}
|
||||||
|
disabled={loading}
|
||||||
|
className="px-3 py-1.5 bg-green-600 hover:bg-green-500 text-white text-xs rounded-lg disabled:opacity-50 transition-colors"
|
||||||
|
>
|
||||||
|
Confirm Approval
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setApproveId(null)}
|
||||||
|
className="px-3 py-1.5 text-xs text-slate-400 hover:text-slate-100"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,24 +1,50 @@
|
|||||||
import { prisma } from '@/lib/prisma'
|
import { prisma } from '@/lib/prisma'
|
||||||
import AdminFundActions from './AdminFundActions'
|
import AdminFundActions from './AdminFundActions'
|
||||||
|
import AdminFundApplications from './AdminFundApplications'
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic'
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
export default async function AdminFundsPage() {
|
export default async function AdminFundsPage() {
|
||||||
const funds = await prisma.hedgeFund.findMany({
|
const [funds, applications] = await Promise.all([
|
||||||
orderBy: { createdAt: 'asc' },
|
prisma.hedgeFund.findMany({
|
||||||
include: {
|
orderBy: { createdAt: 'asc' },
|
||||||
user: { select: { balance: true } },
|
include: {
|
||||||
managers: {
|
user: { select: { balance: true } },
|
||||||
include: { user: { select: { id: true, username: true, displayUsername: true } } },
|
managers: {
|
||||||
orderBy: { addedAt: 'asc' },
|
include: { user: { select: { id: true, username: true, displayUsername: true } } },
|
||||||
|
orderBy: { addedAt: 'asc' },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
}),
|
||||||
})
|
prisma.fundApplication.findMany({
|
||||||
|
orderBy: { createdAt: 'asc' },
|
||||||
|
include: { user: { select: { id: true, username: true, displayUsername: true } } },
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
const serialisedApplications = applications.map((a) => ({
|
||||||
|
...a,
|
||||||
|
createdAt: a.createdAt.toISOString(),
|
||||||
|
}))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-8">
|
||||||
<h2 className="text-lg font-semibold">Hedge Funds</h2>
|
<div className="space-y-4">
|
||||||
<AdminFundActions funds={funds} />
|
<h2 className="text-lg font-semibold flex items-center gap-2">
|
||||||
|
Fund Applications
|
||||||
|
{applications.length > 0 && (
|
||||||
|
<span className="text-xs bg-amber-500/20 text-amber-400 border border-amber-500/30 rounded-full px-2 py-0.5">
|
||||||
|
{applications.length}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</h2>
|
||||||
|
<AdminFundApplications applications={serialisedApplications} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<h2 className="text-lg font-semibold">Hedge Funds</h2>
|
||||||
|
<AdminFundActions funds={funds} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { authOptions } from '@/lib/auth'
|
||||||
|
import { prisma } from '@/lib/prisma'
|
||||||
|
import { z } from 'zod'
|
||||||
|
import bcrypt from 'bcryptjs'
|
||||||
|
|
||||||
|
function toSlug(name: string) {
|
||||||
|
return name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
const approveSchema = z.object({
|
||||||
|
action: z.literal('approve'),
|
||||||
|
startingBalance: z.number().min(0).default(0),
|
||||||
|
})
|
||||||
|
|
||||||
|
const denySchema = z.object({
|
||||||
|
action: z.literal('deny'),
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/admin/fund-applications/[applicationId]
|
||||||
|
* action: 'approve' — creates the fund, adds applicant as manager, deletes the application
|
||||||
|
* action: 'deny' — deletes the application
|
||||||
|
*/
|
||||||
|
export async function POST(
|
||||||
|
req: NextRequest,
|
||||||
|
{ params }: { params: { applicationId: string } }
|
||||||
|
) {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
if (!session?.user?.isAdmin) {
|
||||||
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const application = await prisma.fundApplication.findUnique({
|
||||||
|
where: { id: params.applicationId },
|
||||||
|
include: { user: { select: { id: true, username: true } } },
|
||||||
|
})
|
||||||
|
if (!application) {
|
||||||
|
return NextResponse.json({ error: 'Application not found' }, { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await req.json()
|
||||||
|
|
||||||
|
if (body.action === 'deny') {
|
||||||
|
await prisma.fundApplication.delete({ where: { id: params.applicationId } })
|
||||||
|
return NextResponse.json({ ok: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = approveSchema.safeParse(body)
|
||||||
|
if (!parsed.success) {
|
||||||
|
return NextResponse.json({ error: parsed.error.errors[0]?.message ?? 'Invalid input' }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const { startingBalance } = parsed.data
|
||||||
|
const name = application.fundName
|
||||||
|
const slug = toSlug(name)
|
||||||
|
const shadowUsername = `fund:${slug}`
|
||||||
|
|
||||||
|
// Check for conflicts
|
||||||
|
const [existingFund, existingSlug, existingUser] = await Promise.all([
|
||||||
|
prisma.hedgeFund.findFirst({ where: { name: { equals: name, mode: 'insensitive' } } }),
|
||||||
|
prisma.hedgeFund.findUnique({ where: { slug } }),
|
||||||
|
prisma.user.findUnique({ where: { username: shadowUsername } }),
|
||||||
|
])
|
||||||
|
|
||||||
|
if (existingFund) return NextResponse.json({ error: 'A fund with that name already exists.' }, { status: 409 })
|
||||||
|
if (existingSlug) return NextResponse.json({ error: 'A fund with that slug already exists.' }, { status: 409 })
|
||||||
|
if (existingUser) return NextResponse.json({ error: 'Shadow user conflict.' }, { status: 409 })
|
||||||
|
|
||||||
|
const fund = await prisma.$transaction(async (tx) => {
|
||||||
|
const shadowUser = await tx.user.create({
|
||||||
|
data: {
|
||||||
|
username: shadowUsername,
|
||||||
|
displayUsername: name,
|
||||||
|
passwordHash: await bcrypt.hash(crypto.randomUUID(), 10),
|
||||||
|
balance: startingBalance,
|
||||||
|
isFund: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const newFund = await tx.hedgeFund.create({
|
||||||
|
data: { name, slug, userId: shadowUser.id, sharesOutstanding: 0 },
|
||||||
|
include: {
|
||||||
|
user: { select: { balance: true } },
|
||||||
|
managers: { include: { user: { select: { id: true, username: true, displayUsername: true } } } },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await tx.fundManager.create({
|
||||||
|
data: { fundId: newFund.id, userId: application.userId },
|
||||||
|
})
|
||||||
|
|
||||||
|
await tx.fundApplication.delete({ where: { id: application.id } })
|
||||||
|
|
||||||
|
return { ...newFund, managers: [{ id: 'new', userId: application.userId, user: application.user }] }
|
||||||
|
})
|
||||||
|
|
||||||
|
return NextResponse.json(fund, { status: 201 })
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { authOptions } from '@/lib/auth'
|
||||||
|
import { prisma } from '@/lib/prisma'
|
||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
const submitSchema = z.object({
|
||||||
|
fundName: z.string().min(1).max(60),
|
||||||
|
reason: z.string().min(10).max(1000),
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/fund-applications
|
||||||
|
* Returns the current user's pending application, or null.
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
|
|
||||||
|
const application = await prisma.fundApplication.findUnique({
|
||||||
|
where: { userId: session.user.id },
|
||||||
|
})
|
||||||
|
|
||||||
|
return NextResponse.json(application)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/fund-applications
|
||||||
|
* Submit a fund application. One per user at a time.
|
||||||
|
*/
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
|
|
||||||
|
const body = await req.json()
|
||||||
|
const parsed = submitSchema.safeParse(body)
|
||||||
|
if (!parsed.success) {
|
||||||
|
return NextResponse.json({ error: parsed.error.errors[0]?.message ?? 'Invalid input' }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const { fundName, reason } = parsed.data
|
||||||
|
|
||||||
|
try {
|
||||||
|
const application = await prisma.fundApplication.create({
|
||||||
|
data: { userId: session.user.id, fundName: fundName.trim(), reason: reason.trim() },
|
||||||
|
})
|
||||||
|
return NextResponse.json(application, { status: 201 })
|
||||||
|
} catch {
|
||||||
|
// Unique constraint violation — already has a pending application
|
||||||
|
return NextResponse.json({ error: 'You already have a pending application.' }, { status: 409 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE /api/fund-applications
|
||||||
|
* Withdraw the current user's pending application.
|
||||||
|
*/
|
||||||
|
export async function DELETE() {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
|
|
||||||
|
await prisma.fundApplication.deleteMany({ where: { userId: session.user.id } })
|
||||||
|
return NextResponse.json({ ok: true })
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
|
import Link from 'next/link'
|
||||||
|
import { Building2, Clock, CheckCircle } from 'lucide-react'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
existing: { fundName: string; reason: string; createdAt: string } | null
|
||||||
|
managedFund: { name: string; slug: string } | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function FundApplicationClient({ existing, managedFund }: Props) {
|
||||||
|
const router = useRouter()
|
||||||
|
const [fundName, setFundName] = useState('')
|
||||||
|
const [reason, setReason] = useState('')
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [withdrawing, setWithdrawing] = useState(false)
|
||||||
|
|
||||||
|
// Already a fund manager
|
||||||
|
if (managedFund) {
|
||||||
|
return (
|
||||||
|
<div className="bg-surface-card border border-surface-border rounded-xl p-6 space-y-3">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<CheckCircle className="h-5 w-5 text-green-400" />
|
||||||
|
<p className="font-medium">You already manage a fund</p>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm text-slate-400">
|
||||||
|
You are a manager of{' '}
|
||||||
|
<Link href={`/fund/${managedFund.slug}`} className="text-indigo-400 hover:text-indigo-300 underline underline-offset-2">
|
||||||
|
{managedFund.name}
|
||||||
|
</Link>
|
||||||
|
.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pending application
|
||||||
|
if (existing) {
|
||||||
|
async function withdraw() {
|
||||||
|
setWithdrawing(true)
|
||||||
|
await fetch('/api/fund-applications', { method: 'DELETE' })
|
||||||
|
setWithdrawing(false)
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-surface-card border border-indigo-500/30 rounded-xl p-6 space-y-4">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Clock className="h-5 w-5 text-amber-400" />
|
||||||
|
<p className="font-medium">Application pending review</p>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2 text-sm">
|
||||||
|
<div>
|
||||||
|
<span className="text-slate-500 text-xs uppercase tracking-wide">Fund Name</span>
|
||||||
|
<p className="text-white mt-0.5">{existing.fundName}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span className="text-slate-500 text-xs uppercase tracking-wide">Reason</span>
|
||||||
|
<p className="text-slate-300 mt-0.5 whitespace-pre-wrap">{existing.reason}</p>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-slate-500">
|
||||||
|
Submitted {new Date(existing.createdAt).toLocaleDateString()}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={withdraw}
|
||||||
|
disabled={withdrawing}
|
||||||
|
className="text-xs text-red-400 hover:text-red-300 transition-colors disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{withdrawing ? 'Withdrawing…' : 'Withdraw application'}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Submit form
|
||||||
|
async function handleSubmit(e: React.FormEvent) {
|
||||||
|
e.preventDefault()
|
||||||
|
if (!fundName.trim() || !reason.trim()) return
|
||||||
|
setLoading(true)
|
||||||
|
setError('')
|
||||||
|
const res = await fetch('/api/fund-applications', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ fundName: fundName.trim(), reason: reason.trim() }),
|
||||||
|
})
|
||||||
|
const data = await res.json()
|
||||||
|
setLoading(false)
|
||||||
|
if (!res.ok) { setError(data.error ?? 'Failed to submit'); return }
|
||||||
|
router.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleSubmit} className="bg-surface-card border border-surface-border rounded-xl p-6 space-y-4">
|
||||||
|
<div className="flex items-center gap-2 text-slate-300">
|
||||||
|
<Building2 className="h-5 w-5 text-indigo-400" />
|
||||||
|
<span className="font-medium">New Fund Application</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p className="text-red-400 text-sm bg-red-400/10 border border-red-400/20 rounded-lg px-3 py-2">{error}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="text-xs text-slate-500 uppercase tracking-wide block mb-1">
|
||||||
|
Fund Name <span className="normal-case">(max 60 chars)</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
value={fundName}
|
||||||
|
onChange={(e) => setFundName(e.target.value)}
|
||||||
|
maxLength={60}
|
||||||
|
placeholder="TechAlpha Capital"
|
||||||
|
required
|
||||||
|
className="w-full bg-surface border border-surface-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label className="text-xs text-slate-500 uppercase tracking-wide block mb-1">
|
||||||
|
Why do you want to run this fund?
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
value={reason}
|
||||||
|
onChange={(e) => setReason(e.target.value)}
|
||||||
|
rows={5}
|
||||||
|
minLength={10}
|
||||||
|
maxLength={1000}
|
||||||
|
placeholder="Describe your strategy, what hashtags you plan to focus on, and why you'd be a good fund manager…"
|
||||||
|
required
|
||||||
|
className="w-full bg-surface border border-surface-border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500 resize-none"
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-slate-600 mt-0.5 text-right">{reason.length}/1000</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={loading || !fundName.trim() || reason.trim().length < 10}
|
||||||
|
className="w-full py-2 bg-indigo-600 hover:bg-indigo-500 text-white text-sm font-medium rounded-lg disabled:opacity-50 transition-colors"
|
||||||
|
>
|
||||||
|
{loading ? 'Submitting…' : 'Submit Application'}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { authOptions } from '@/lib/auth'
|
||||||
|
import { redirect } from 'next/navigation'
|
||||||
|
import { prisma } from '@/lib/prisma'
|
||||||
|
import FundApplicationClient from './FundApplicationClient'
|
||||||
|
|
||||||
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
|
export default async function FundApplyPage() {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
if (!session) redirect('/auth/signin?callbackUrl=/fund/apply')
|
||||||
|
|
||||||
|
const [application, managedFund] = await Promise.all([
|
||||||
|
prisma.fundApplication.findUnique({ where: { userId: session.user.id } }),
|
||||||
|
prisma.fundManager.findFirst({
|
||||||
|
where: { userId: session.user.id },
|
||||||
|
include: { fund: { select: { name: true, slug: true } } },
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-xl mx-auto space-y-6 py-8">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-2xl font-bold">Apply for a Hedge Fund</h1>
|
||||||
|
<p className="text-slate-400 text-sm mt-1">
|
||||||
|
Propose a new fund. Admins will review your application and approve or deny it.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<FundApplicationClient
|
||||||
|
existing={application ? { fundName: application.fundName, reason: application.reason, createdAt: application.createdAt.toISOString() } : null}
|
||||||
|
managedFund={managedFund ? { name: managedFund.fund.name, slug: managedFund.fund.slug } : null}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user