From deaa005b32ba2839e5eec41cbb9ce02ea4a3e798 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Sun, 29 Mar 2026 03:51:55 +0530 Subject: [PATCH] feat: resolve agent avatar presigned URLs and improve agent profile data mapping in CMS dashboard --- src/app/dashboard/cms/page.tsx | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/app/dashboard/cms/page.tsx b/src/app/dashboard/cms/page.tsx index 7ca6f4f..d559382 100644 --- a/src/app/dashboard/cms/page.tsx +++ b/src/app/dashboard/cms/page.tsx @@ -237,7 +237,21 @@ export default function CmsPage() { agentSearchTimeout.current = setTimeout(async () => { try { const res = await usersService.getUsers({ role: 'AGENT', search: query, limit: 10, verificationStatus: 'APPROVED' }); - setAgentSearchResults(res.users); + // Resolve avatar presigned URLs for display + const usersWithAvatars = await Promise.all( + res.users.map(async (user) => { + if (user.profile?.avatar && !user.profile.avatar.startsWith('http')) { + try { + const avatarUrl = await uploadService.getPresignedDownloadUrl(user.profile.avatar); + return { ...user, profile: { ...user.profile, avatar: avatarUrl } }; + } catch { + return user; + } + } + return user; + }) + ); + setAgentSearchResults(usersWithAvatars); } catch { setAgentSearchResults([]); } finally { @@ -248,13 +262,14 @@ export default function CmsPage() { function selectAgent(user: User, onChange: (items: ProfessionalItem[]) => void, currentItems: ProfessionalItem[]) { if (currentItems.length >= 3) return; - const profile = user.profile; const agent = user.agentProfile; - const name = profile ? `${profile.firstName} ${profile.lastName}`.trim() : ''; - const subtitle = agent?.headline || agent?.agentType?.name || ''; - const location = profile ? [profile.city, profile.state].filter(Boolean).join(', ') : ''; + const profile = user.profile; + const name = `${profile?.firstName || ''} ${profile?.lastName || ''}`.trim() || user.email; + const subtitle = agent?.agentType?.name || agent?.headline || ''; + const location = [profile?.city, profile?.state].filter(Boolean).join(', '); const experience = agent?.yearsOfExperience ? `${agent.yearsOfExperience}+ years in real estate.` : ''; const imageUrl = profile?.avatar || ''; + const isVerified = agent?.isVerified || false; const newItem: ProfessionalItem = { name, subtitle, location, experience, expertise: [], imageUrl }; onChange([...currentItems, newItem]); @@ -267,11 +282,11 @@ export default function CmsPage() { function selectFeaturedAgent(user: User) { const data = editContent as FeaturesContent; if ((data.featuredAgents || []).length >= 3) return; - const profile = user.profile; const agent = user.agentProfile; - const name = profile ? `${profile.firstName} ${profile.lastName}`.trim() : ''; + const profile = user.profile; + const name = `${profile?.firstName || ''} ${profile?.lastName || ''}`.trim() || user.email; const role = agent?.agentType?.name || agent?.headline || ''; - const location = profile ? [profile.city, profile.state].filter(Boolean).join(', ') : ''; + const location = [profile?.city, profile?.state].filter(Boolean).join(', '); const experience = agent?.yearsOfExperience ? `${agent.yearsOfExperience}+ years in real estate.` : ''; const rating = ''; const imageUrl = profile?.avatar || '';