Skip to content

Commit 31abfc0

Browse files
committed
tweaks: minor web app fixes
1 parent 711b669 commit 31abfc0

File tree

5 files changed

+111
-77
lines changed

5 files changed

+111
-77
lines changed

web/src/app/publishers/[id]/agents/[agentId]/[version]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const AgentDetailPage = async ({ params }: AgentDetailPageProps) => {
134134
{' '}
135135
{/* Navigation */}
136136
<div className="mb-6">
137-
<BackButton />
137+
<BackButton fallbackUrl="/store" />
138138
</div>
139139
{/* Agent Header */}
140140
<Card className="mb-6">

web/src/app/referrals/[code]/page.tsx

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import type { ReferralCodeResponse } from '../../api/referrals/[code]/route'
99
import { authOptions } from '../../api/auth/[...nextauth]/auth-options'
1010
import CardWithBeams from '@/components/card-with-beams'
1111
import { Button } from '@/components/ui/button'
12-
import { ReferralClientWrapper } from '@/components/referral/referral-client-wrapper'
13-
import { GitHubSignInButton } from '@/components/referral/github-signin-button'
12+
import ReferralClient from './referral-client'
1413

1514
export const generateMetadata = async ({
1615
params,
@@ -79,7 +78,7 @@ export default async function ReferralPage({
7978
)
8079
}
8180

82-
// If referrer has maxed out referrals
81+
// Handle referrer with maxed out referrals
8382
if (referralData.status.reason) {
8483
return (
8584
<CardWithBeams
@@ -104,55 +103,17 @@ export default async function ReferralPage({
104103
)
105104
}
106105

107-
// Valid referral - show success page and automatically redeem
108106
const referrerDisplayName =
109107
referralData.referrerName || referrerName || 'Someone'
110108

109+
// Pass data to the client component for rendering
111110
return (
112-
<ReferralClientWrapper referralCode={code}>
113-
<CardWithBeams
114-
title={`${referrerDisplayName} invited you to Codebuff!`}
115-
description="You're eligible for bonus credits when you complete the referral."
116-
content={
117-
<>
118-
<div className="text-center space-y-4">
119-
<p className="text-muted-foreground">
120-
Welcome! Complete your referral to get bonus credits.
121-
</p>
122-
123-
<div className="flex justify-center">
124-
{!session && (
125-
<GitHubSignInButton
126-
referralCode={code}
127-
referrerName={referrerName}
128-
/>
129-
)}
130-
</div>
131-
132-
{/* Complete Referral button positioned at bottom right for logged-in users */}
133-
{session && !referralData.isSameUser && (
134-
<div className="flex justify-end mt-6">
135-
<Button asChild>
136-
<Link href={`/onboard?referral_code=${code}`}>
137-
Complete Referral
138-
</Link>
139-
</Button>
140-
</div>
141-
)}
142-
143-
{/* Show warning if user is viewing their own referral link */}
144-
{session && referralData.isSameUser && (
145-
<div className="mt-6 p-3 bg-red-800 border border-red-900 rounded-md">
146-
<p className="text-white text-sm font-medium">
147-
⚠️ This is your own referral link. You will not be able to
148-
redeem your own code.
149-
</p>
150-
</div>
151-
)}
152-
</div>
153-
</>
154-
}
155-
/>
156-
</ReferralClientWrapper>
111+
<ReferralClient
112+
code={code}
113+
session={session}
114+
referralData={referralData}
115+
referrerDisplayName={referrerDisplayName}
116+
referrerName={referrerName}
117+
/>
157118
)
158119
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'use client'
2+
3+
import { useEffect } from 'react'
4+
import Link from 'next/link'
5+
6+
import CardWithBeams from '@/components/card-with-beams'
7+
import { Button } from '@/components/ui/button'
8+
import { GitHubSignInButton } from '@/components/referral/github-signin-button'
9+
10+
import type { ReferralCodeResponse } from '../../api/referrals/[code]/route'
11+
12+
interface ReferralClientProps {
13+
code: string
14+
session: any
15+
referralData: ReferralCodeResponse
16+
referrerDisplayName: string
17+
referrerName?: string
18+
}
19+
20+
export default function ReferralClient({
21+
code,
22+
session,
23+
referralData,
24+
referrerDisplayName,
25+
referrerName,
26+
}: ReferralClientProps) {
27+
// Always store referral code in localStorage when landing on referral page
28+
// This overwrites any previously stored referral code
29+
useEffect(() => {
30+
if (typeof window !== 'undefined' && code) {
31+
localStorage.setItem('referral_code', code)
32+
}
33+
}, [code])
34+
35+
return (
36+
<CardWithBeams
37+
title={`${referrerDisplayName} invited you to Codebuff!`}
38+
description="You're eligible for bonus credits when you complete the referral."
39+
content={
40+
<>
41+
<div className="text-center space-y-4">
42+
<p className="text-muted-foreground">
43+
Welcome! Complete your referral to get bonus credits.
44+
</p>
45+
46+
<div className="flex justify-center">
47+
{!session && (
48+
<GitHubSignInButton
49+
referralCode={code}
50+
referrerName={referrerName}
51+
/>
52+
)}
53+
</div>
54+
55+
{/* Complete Referral button for logged-in users */}
56+
{session && !referralData.isSameUser && (
57+
<div className="flex justify-end mt-6">
58+
<Button asChild>
59+
<Link href={`/onboard?referral_code=${code}`}>
60+
Complete Referral
61+
</Link>
62+
</Button>
63+
</div>
64+
)}
65+
66+
{/* Warning for user's own referral link */}
67+
{session && referralData.isSameUser && (
68+
<div className="mt-6 p-3 bg-red-800 border border-red-900 rounded-md">
69+
<p className="text-white text-sm font-medium">
70+
⚠️ This is your own referral link. You will not be able to
71+
redeem your own code.
72+
</p>
73+
</div>
74+
)}
75+
</div>
76+
</>
77+
}
78+
/>
79+
)
80+
}

web/src/components/referral/referral-client-wrapper.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
'use client'
22

3+
import { ArrowLeft } from 'lucide-react'
34
import { useRouter } from 'next/navigation'
5+
46
import { Button } from '@/components/ui/button'
5-
import { ArrowLeft } from 'lucide-react'
67

7-
export const BackButton = () => {
8+
interface BackButtonProps {
9+
fallbackUrl?: string
10+
}
11+
12+
export const BackButton = ({ fallbackUrl }: BackButtonProps = {}) => {
813
const router = useRouter()
914

15+
const handleBack = () => {
16+
// If a fallback URL is provided, use it
17+
if (fallbackUrl) {
18+
router.push(fallbackUrl)
19+
return
20+
}
21+
22+
// Otherwise use browser history
23+
router.back()
24+
}
25+
1026
return (
11-
<Button
12-
variant="ghost"
13-
className="mb-4"
14-
onClick={() => router.back()}
15-
>
27+
<Button variant="ghost" className="mb-4" onClick={handleBack}>
1628
<ArrowLeft className="h-4 w-4 mr-2" />
1729
Back
1830
</Button>
1931
)
20-
}
32+
}

0 commit comments

Comments
 (0)