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 () => {
|
||||
try {
|
||||
const res = await usersService.getUsers({ role: 'AGENT', search: query, limit: 10, verificationStatus: 'APPROVED' });
|
||||
// Resolve avatar presigned URLs for display
|
||||
const usersWithAvatars = await Promise.all(
|
||||
// Resolve avatar presigned URLs for dropdown display only
|
||||
// Store resolved URLs separately so original S3 keys are preserved for CMS storage
|
||||
const usersWithDisplayAvatars = 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 } };
|
||||
const displayUrl = await uploadService.getPresignedDownloadUrl(user.profile.avatar);
|
||||
return { ...user, _displayAvatar: displayUrl };
|
||||
} catch {
|
||||
return user;
|
||||
return { ...user, _displayAvatar: undefined };
|
||||
}
|
||||
}
|
||||
return user;
|
||||
return { ...user, _displayAvatar: user.profile?.avatar || undefined };
|
||||
})
|
||||
);
|
||||
setAgentSearchResults(usersWithAvatars);
|
||||
setAgentSearchResults(usersWithDisplayAvatars as any);
|
||||
} catch {
|
||||
setAgentSearchResults([]);
|
||||
} finally {
|
||||
@@ -612,8 +613,8 @@ export default function CmsPage() {
|
||||
<span className="text-xs font-semibold text-[#f5a623]">
|
||||
{user.profile?.firstName?.[0] || ''}{user.profile?.lastName?.[0] || ''}
|
||||
</span>
|
||||
{user.profile?.avatar && (
|
||||
<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'; }} />
|
||||
{(user as any)._displayAvatar && (
|
||||
<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 className="min-w-0">
|
||||
|
||||
Reference in New Issue
Block a user