refactor: decouple avatar display URLs from original S3 keys in agent search results
This commit is contained in:
@@ -237,21 +237,22 @@ 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' });
|
||||||
// Resolve avatar presigned URLs for display
|
// Resolve avatar presigned URLs for dropdown display only
|
||||||
const usersWithAvatars = await Promise.all(
|
// Store resolved URLs separately so original S3 keys are preserved for CMS storage
|
||||||
|
const usersWithDisplayAvatars = await Promise.all(
|
||||||
res.users.map(async (user) => {
|
res.users.map(async (user) => {
|
||||||
if (user.profile?.avatar && !user.profile.avatar.startsWith('http')) {
|
if (user.profile?.avatar && !user.profile.avatar.startsWith('http')) {
|
||||||
try {
|
try {
|
||||||
const avatarUrl = await uploadService.getPresignedDownloadUrl(user.profile.avatar);
|
const displayUrl = await uploadService.getPresignedDownloadUrl(user.profile.avatar);
|
||||||
return { ...user, profile: { ...user.profile, avatar: avatarUrl } };
|
return { ...user, _displayAvatar: displayUrl };
|
||||||
} catch {
|
} catch {
|
||||||
return user;
|
return { ...user, _displayAvatar: undefined };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return user;
|
return { ...user, _displayAvatar: user.profile?.avatar || undefined };
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
setAgentSearchResults(usersWithAvatars);
|
setAgentSearchResults(usersWithDisplayAvatars as any);
|
||||||
} catch {
|
} catch {
|
||||||
setAgentSearchResults([]);
|
setAgentSearchResults([]);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -612,8 +613,8 @@ export default function CmsPage() {
|
|||||||
<span className="text-xs font-semibold text-[#f5a623]">
|
<span className="text-xs font-semibold text-[#f5a623]">
|
||||||
{user.profile?.firstName?.[0] || ''}{user.profile?.lastName?.[0] || ''}
|
{user.profile?.firstName?.[0] || ''}{user.profile?.lastName?.[0] || ''}
|
||||||
</span>
|
</span>
|
||||||
{user.profile?.avatar && (
|
{(user as any)._displayAvatar && (
|
||||||
<img src={user.profile.avatar} alt="" className="absolute inset-0 w-full h-full rounded-full object-cover" onError={(e) => { (e.target as HTMLImageElement).style.display = 'none'; }} />
|
<img src={(user as any)._displayAvatar} alt="" className="absolute inset-0 w-full h-full rounded-full object-cover" onError={(e) => { (e.target as HTMLImageElement).style.display = 'none'; }} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
|
|||||||
Reference in New Issue
Block a user