fix: dashboard flickering + clickable logo change for applicants
All checks were successful
Build and Push Docker Image / build (push) Successful in 10m7s

- Fix session auto-refresh causing re-render cascade by using useRef
  instead of useState and delaying the refresh by 3s
- Make project logo clickable on dashboard and team page for team leads
  with hover pencil overlay and ProjectLogoUpload dialog

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 14:23:27 +01:00
parent 12e4864d36
commit 8d6f3ca11f
3 changed files with 73 additions and 20 deletions

View File

@@ -18,6 +18,7 @@ import { CompetitionTimelineSidebar } from '@/components/applicant/competition-t
import { WithdrawButton } from '@/components/applicant/withdraw-button' import { WithdrawButton } from '@/components/applicant/withdraw-button'
import { MentoringRequestCard } from '@/components/applicant/mentoring-request-card' import { MentoringRequestCard } from '@/components/applicant/mentoring-request-card'
import { AnimatedCard } from '@/components/shared/animated-container' import { AnimatedCard } from '@/components/shared/animated-container'
import { ProjectLogoUpload } from '@/components/shared/project-logo-upload'
import { import {
FileText, FileText,
Calendar, Calendar,
@@ -29,6 +30,7 @@ import {
ArrowRight, ArrowRight,
Star, Star,
AlertCircle, AlertCircle,
Pencil,
} from 'lucide-react' } from 'lucide-react'
const statusColors: Record<string, 'default' | 'success' | 'secondary' | 'destructive' | 'warning'> = { const statusColors: Record<string, 'default' | 'success' | 'secondary' | 'destructive' | 'warning'> = {
@@ -45,6 +47,7 @@ const statusColors: Record<string, 'default' | 'success' | 'secondary' | 'destru
export default function ApplicantDashboardPage() { export default function ApplicantDashboardPage() {
const { data: session, status: sessionStatus } = useSession() const { data: session, status: sessionStatus } = useSession()
const isAuthenticated = sessionStatus === 'authenticated' const isAuthenticated = sessionStatus === 'authenticated'
const utils = trpc.useUtils()
const { data, isLoading } = trpc.applicant.getMyDashboard.useQuery(undefined, { const { data, isLoading } = trpc.applicant.getMyDashboard.useQuery(undefined, {
enabled: isAuthenticated, enabled: isAuthenticated,
@@ -121,14 +124,36 @@ export default function ApplicantDashboardPage() {
{/* Header */} {/* Header */}
<div className="flex items-start justify-between flex-wrap gap-4"> <div className="flex items-start justify-between flex-wrap gap-4">
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
{/* Project logo */} {/* Project logo — clickable for team leads to change */}
<div className="shrink-0 h-14 w-14 rounded-xl border bg-muted/50 flex items-center justify-center overflow-hidden"> {project.isTeamLead ? (
{data.logoUrl ? ( <ProjectLogoUpload
<img src={data.logoUrl} alt={project.title} className="h-full w-full object-cover" /> projectId={project.id}
) : ( currentLogoUrl={data.logoUrl}
<FileText className="h-7 w-7 text-muted-foreground/60" /> onUploadComplete={() => utils.applicant.getMyDashboard.invalidate()}
)} >
</div> <button
type="button"
className="group relative shrink-0 h-14 w-14 rounded-xl border bg-muted/50 flex items-center justify-center overflow-hidden cursor-pointer hover:ring-2 hover:ring-primary/30 transition-all"
>
{data.logoUrl ? (
<img src={data.logoUrl} alt={project.title} className="h-full w-full object-cover" />
) : (
<FileText className="h-7 w-7 text-muted-foreground/60" />
)}
<div className="absolute inset-0 bg-black/0 group-hover:bg-black/40 transition-colors flex items-center justify-center">
<Pencil className="h-4 w-4 text-white opacity-0 group-hover:opacity-100 transition-opacity" />
</div>
</button>
</ProjectLogoUpload>
) : (
<div className="shrink-0 h-14 w-14 rounded-xl border bg-muted/50 flex items-center justify-center overflow-hidden">
{data.logoUrl ? (
<img src={data.logoUrl} alt={project.title} className="h-full w-full object-cover" />
) : (
<FileText className="h-7 w-7 text-muted-foreground/60" />
)}
</div>
)}
<div> <div>
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<h1 className="text-2xl font-semibold tracking-tight">{project.title}</h1> <h1 className="text-2xl font-semibold tracking-tight">{project.title}</h1>

View File

@@ -68,6 +68,7 @@ import {
GraduationCap, GraduationCap,
Heart, Heart,
Calendar, Calendar,
Pencil,
} from 'lucide-react' } from 'lucide-react'
import { formatDateOnly } from '@/lib/utils' import { formatDateOnly } from '@/lib/utils'
@@ -243,14 +244,36 @@ export default function ApplicantProjectPage() {
<div className="space-y-6"> <div className="space-y-6">
{/* Header */} {/* Header */}
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
{/* Project logo */} {/* Project logo — clickable for team leads */}
<div className="shrink-0 h-14 w-14 rounded-xl border bg-muted/50 flex items-center justify-center overflow-hidden"> {isTeamLead ? (
{logoUrl ? ( <ProjectLogoUpload
<img src={logoUrl} alt={project.title} className="h-full w-full object-cover" /> projectId={projectId}
) : ( currentLogoUrl={logoUrl}
<FolderOpen className="h-7 w-7 text-muted-foreground/60" /> onUploadComplete={() => refetchLogo()}
)} >
</div> <button
type="button"
className="group relative shrink-0 h-14 w-14 rounded-xl border bg-muted/50 flex items-center justify-center overflow-hidden cursor-pointer hover:ring-2 hover:ring-primary/30 transition-all"
>
{logoUrl ? (
<img src={logoUrl} alt={project.title} className="h-full w-full object-cover" />
) : (
<FolderOpen className="h-7 w-7 text-muted-foreground/60" />
)}
<div className="absolute inset-0 bg-black/0 group-hover:bg-black/40 transition-colors flex items-center justify-center">
<Pencil className="h-4 w-4 text-white opacity-0 group-hover:opacity-100 transition-opacity" />
</div>
</button>
</ProjectLogoUpload>
) : (
<div className="shrink-0 h-14 w-14 rounded-xl border bg-muted/50 flex items-center justify-center overflow-hidden">
{logoUrl ? (
<img src={logoUrl} alt={project.title} className="h-full w-full object-cover" />
) : (
<FolderOpen className="h-7 w-7 text-muted-foreground/60" />
)}
</div>
)}
<div> <div>
<h1 className="text-2xl font-semibold tracking-tight"> <h1 className="text-2xl font-semibold tracking-tight">
{project.title} {project.title}

View File

@@ -1,6 +1,6 @@
'use client' 'use client'
import { useState, useEffect } from 'react' import { useState, useEffect, useRef } from 'react'
import Link from 'next/link' import Link from 'next/link'
import { usePathname } from 'next/navigation' import { usePathname } from 'next/navigation'
import { signOut, useSession } from 'next-auth/react' import { signOut, useSession } from 'next-auth/react'
@@ -96,10 +96,15 @@ export function RoleNav({ navigation, roleName, user, basePath, statusBadge, edi
signOut({ callbackUrl: '/login' }) signOut({ callbackUrl: '/login' })
} }
// Auto-refresh session on mount to pick up role changes without requiring re-login // Auto-refresh session once on initial mount to pick up role changes.
// Uses a ref (not state) to avoid triggering an extra re-render.
const sessionRefreshedRef = useRef(false)
useEffect(() => { useEffect(() => {
if (isAuthenticated) { if (isAuthenticated && !sessionRefreshedRef.current) {
updateSession() sessionRefreshedRef.current = true
// Delay so the initial render finishes cleanly before session refresh
const timer = setTimeout(() => updateSession(), 3000)
return () => clearTimeout(timer)
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [isAuthenticated]) }, [isAuthenticated])