feat: resolve agent avatar presigned URLs and improve agent profile data mapping in CMS dashboard

This commit is contained in:
pradeepkumar
2026-03-29 03:51:55 +05:30
parent ceede6d267
commit deaa005b32

View File

@@ -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 || '';