- {friendRequests.outgoing.map((userId) => {
- // Find the user details from allUsernames array
- const user = allUsernames.find(u => u.id === userId);
- return (
-
-
-
- {user ? getInitials(user) : 'U'}
-
-
-
-
{user ? `${user.firstName} ${user.lastName}` : 'User'}
-
- Pending
-
-
-
{user ? `@${user.username}` : ''}
+ {friendRequests.outgoing.map((outgoingUser) => (
+
+
+
+ {getInitials(outgoingUser)}
+
+
+
+
{outgoingUser.firstName} {outgoingUser.lastName}
+
+ Pending
+
+
@{outgoingUser.username}
-
- );
- })}
+
+
+ ))}
)}
diff --git a/src/utils/auth.tsx b/src/utils/auth.tsx
index f5400bd..5fd471b 100644
--- a/src/utils/auth.tsx
+++ b/src/utils/auth.tsx
@@ -11,7 +11,7 @@ interface AuthContextType {
firebaseInitialized: boolean;
friendRequests: {
incoming: UserProfile[];
- outgoing: string[];
+ outgoing: UserProfile[];
};
friends: UserProfile[];
accountabilityPartners: UserProfile[];
@@ -47,7 +47,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
const [isLoading, setIsLoading] = useState(true);
const [firebaseInitialized, setFirebaseInitialized] = useState(!!auth);
const [isAdmin, setIsAdmin] = useState(false);
- const [friendRequests, setFriendRequests] = useState<{ incoming: UserProfile[], outgoing: string[] }>({
+ const [friendRequests, setFriendRequests] = useState<{ incoming: UserProfile[], outgoing: UserProfile[] }>({
incoming: [],
outgoing: []
});
@@ -80,10 +80,20 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
}
}
}
+
+ const outgoingRequests: UserProfile[] = [];
+ if (profile.friendRequests?.outgoing?.length) {
+ for (const recipientId of profile.friendRequests.outgoing) {
+ const recipientProfile = await getUserProfile(recipientId);
+ if (recipientProfile) {
+ outgoingRequests.push(recipientProfile);
+ }
+ }
+ }
setFriendRequests({
incoming: incomingRequests,
- outgoing: profile.friendRequests?.outgoing || []
+ outgoing: outgoingRequests
});
const friendsList: UserProfile[] = [];