feat: resolve agent avatar presigned URLs and improve agent profile data mapping in CMS dashboard
This commit is contained in:
@@ -237,7 +237,21 @@ export default function CmsPage() {
|
|||||||
agentSearchTimeout.current = setTimeout(async () => {
|
agentSearchTimeout.current = setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await usersService.getUsers({ role: 'AGENT', search: query, limit: 10, verificationStatus: 'APPROVED' });
|
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 {
|
} catch {
|
||||||
setAgentSearchResults([]);
|
setAgentSearchResults([]);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -248,13 +262,14 @@ export default function CmsPage() {
|
|||||||
|
|
||||||
function selectAgent(user: User, onChange: (items: ProfessionalItem[]) => void, currentItems: ProfessionalItem[]) {
|
function selectAgent(user: User, onChange: (items: ProfessionalItem[]) => void, currentItems: ProfessionalItem[]) {
|
||||||
if (currentItems.length >= 3) return;
|
if (currentItems.length >= 3) return;
|
||||||
const profile = user.profile;
|
|
||||||
const agent = user.agentProfile;
|
const agent = user.agentProfile;
|
||||||
const name = profile ? `${profile.firstName} ${profile.lastName}`.trim() : '';
|
const profile = user.profile;
|
||||||
const subtitle = agent?.headline || agent?.agentType?.name || '';
|
const name = `${profile?.firstName || ''} ${profile?.lastName || ''}`.trim() || user.email;
|
||||||
const location = profile ? [profile.city, profile.state].filter(Boolean).join(', ') : '';
|
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 experience = agent?.yearsOfExperience ? `${agent.yearsOfExperience}+ years in real estate.` : '';
|
||||||
const imageUrl = profile?.avatar || '';
|
const imageUrl = profile?.avatar || '';
|
||||||
|
const isVerified = agent?.isVerified || false;
|
||||||
|
|
||||||
const newItem: ProfessionalItem = { name, subtitle, location, experience, expertise: [], imageUrl };
|
const newItem: ProfessionalItem = { name, subtitle, location, experience, expertise: [], imageUrl };
|
||||||
onChange([...currentItems, newItem]);
|
onChange([...currentItems, newItem]);
|
||||||
@@ -267,11 +282,11 @@ export default function CmsPage() {
|
|||||||
function selectFeaturedAgent(user: User) {
|
function selectFeaturedAgent(user: User) {
|
||||||
const data = editContent as FeaturesContent;
|
const data = editContent as FeaturesContent;
|
||||||
if ((data.featuredAgents || []).length >= 3) return;
|
if ((data.featuredAgents || []).length >= 3) return;
|
||||||
const profile = user.profile;
|
|
||||||
const agent = user.agentProfile;
|
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 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 experience = agent?.yearsOfExperience ? `${agent.yearsOfExperience}+ years in real estate.` : '';
|
||||||
const rating = '';
|
const rating = '';
|
||||||
const imageUrl = profile?.avatar || '';
|
const imageUrl = profile?.avatar || '';
|
||||||
|
|||||||
Reference in New Issue
Block a user