From ad06833842b565e3e310eab0b77f4befbd5360e2 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Sun, 16 Nov 2025 21:46:40 +0000 Subject: [PATCH] fix: resolve React key duplicates and NaN in profile page - Fix NaN error in impact score calculation by handling undefined reportCount/eventCount - Fix duplicate React keys in activity timeline by using unique composite keys - Add reportCount and eventCount to backend profile response to match frontend expectations - Keep stats object for backward compatibility Fixes: - 'Received NaN for children attribute' warning - 'Encountered two children with the same key' errors --- server/src/services/userService.ts | 2 ++ src/pages/UserProfilePage.tsx | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/src/services/userService.ts b/server/src/services/userService.ts index 934a995..f1ecb30 100644 --- a/server/src/services/userService.ts +++ b/server/src/services/userService.ts @@ -98,6 +98,8 @@ export class UserService { return { ...user, + reportCount: user._count.reports, + eventCount: user._count.eventRegistrations, stats: { reportsSubmitted: user._count.reports, eventsAttended: user._count.eventRegistrations, diff --git a/src/pages/UserProfilePage.tsx b/src/pages/UserProfilePage.tsx index efafaab..fb6d896 100644 --- a/src/pages/UserProfilePage.tsx +++ b/src/pages/UserProfilePage.tsx @@ -111,7 +111,9 @@ export function UserProfilePage() { const calculateImpactScore = () => { if (!profile) return 0; // Impact score calculation: reports * 10 + events attended * 20 - return profile.reportCount * 10 + profile.eventCount * 20; + const reportCount = profile.reportCount || 0; + const eventCount = profile.eventCount || 0; + return reportCount * 10 + eventCount * 20; }; const formatDate = (date: Date) => { @@ -422,8 +424,8 @@ export function UserProfilePage() {

Activity Timeline

{activity.length > 0 ? (
- {activity.map((item) => ( -
+ {activity.map((item, index) => ( +
{item.type === 'report' && 📍}