final 0.9
This commit is contained in:
@@ -9,6 +9,7 @@ interface User {
|
||||
id: number
|
||||
username: string
|
||||
email: string
|
||||
referral_points?: number
|
||||
}
|
||||
|
||||
export default function Nav() {
|
||||
@@ -29,7 +30,24 @@ export default function Nav() {
|
||||
})
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
setUser(data.user)
|
||||
const userData = data.user
|
||||
|
||||
// If user is logged in, fetch referral points
|
||||
if (userData) {
|
||||
try {
|
||||
const pointsResponse = await fetch('/api/referral-points', {
|
||||
credentials: 'include',
|
||||
})
|
||||
if (pointsResponse.ok) {
|
||||
const pointsData = await pointsResponse.json()
|
||||
userData.referral_points = pointsData.referral_points
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching referral points:', error)
|
||||
}
|
||||
}
|
||||
|
||||
setUser(userData)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking auth:', error)
|
||||
@@ -85,6 +103,16 @@ export default function Nav() {
|
||||
<span style={{ color: 'var(--muted)', fontSize: '14px', marginLeft: '48px' }}>
|
||||
{user.username}
|
||||
</span>
|
||||
{user.referral_points !== undefined && user.referral_points > 0 && (
|
||||
<span style={{
|
||||
color: '#0a7931',
|
||||
fontSize: '14px',
|
||||
marginLeft: '12px',
|
||||
fontWeight: 500,
|
||||
}}>
|
||||
⭐ {user.referral_points.toFixed(0)} pts
|
||||
</span>
|
||||
)}
|
||||
<a
|
||||
href="/orders"
|
||||
onClick={() => setMobileMenuOpen(false)}
|
||||
|
||||
Reference in New Issue
Block a user