feat: Add cache-busting to avatar image URLs and implement show more/less functionality for certifications.
This commit is contained in:
@@ -269,6 +269,28 @@ export default function EditProfilePage() {
|
||||
// Save field values to API
|
||||
await agentsService.saveFieldValues(fieldValues);
|
||||
|
||||
// Also update main profile fields (phone, email) to keep them in sync
|
||||
// This ensures that when the view page checks agentProfile.phone first,
|
||||
// it gets the correct (possibly empty) value
|
||||
const profileUpdates: Partial<{ phone: string | null; email: string | null }> = {};
|
||||
|
||||
// Sync phone field - check multiple possible field slugs
|
||||
// The dynamic fields might use different slugs for phone
|
||||
const phoneFieldSlugs = ['phone', 'phone_number', 'cell_number', 'office_number'];
|
||||
for (const slug of phoneFieldSlugs) {
|
||||
const phoneValue = formData[slug];
|
||||
if (phoneValue !== undefined) {
|
||||
// Set to null if empty, otherwise use the value
|
||||
profileUpdates.phone = phoneValue === '' ? null : (phoneValue as string);
|
||||
break; // Use the first found phone field
|
||||
}
|
||||
}
|
||||
|
||||
// Only update if there are changes to sync
|
||||
if (Object.keys(profileUpdates).length > 0) {
|
||||
await agentsService.updateProfile(profileUpdates);
|
||||
}
|
||||
|
||||
router.push('/agent/dashboard');
|
||||
} catch (err) {
|
||||
console.error('Failed to save:', err);
|
||||
|
||||
@@ -158,7 +158,14 @@ export default function AgentProfileView() {
|
||||
if (profile.avatar && isS3Key(profile.avatar)) {
|
||||
try {
|
||||
const presignedUrl = await uploadService.getPresignedDownloadUrl(profile.avatar);
|
||||
setAvatarUrl(presignedUrl);
|
||||
// Add cache-busting parameter to force browser to fetch fresh image
|
||||
// This prevents showing old cached image when avatar is updated
|
||||
const profileWithTimestamp = profile as unknown as { updatedAt?: string };
|
||||
const cacheBuster = profileWithTimestamp.updatedAt
|
||||
? new Date(profileWithTimestamp.updatedAt).getTime()
|
||||
: Date.now();
|
||||
const urlWithCacheBuster = `${presignedUrl}&_t=${cacheBuster}`;
|
||||
setAvatarUrl(urlWithCacheBuster);
|
||||
} catch (avatarErr) {
|
||||
console.error('Failed to get avatar URL:', avatarErr);
|
||||
// Don't fail the whole page, just use default image
|
||||
|
||||
@@ -73,7 +73,14 @@ function ProfileCard({ profile }: ProfileCardProps) {
|
||||
if (profile.avatar && !profile.avatar.startsWith('http') && !profile.avatar.startsWith('/')) {
|
||||
try {
|
||||
const presignedUrl = await uploadService.getPresignedDownloadUrl(profile.avatar);
|
||||
setAvatarUrl(presignedUrl);
|
||||
// Add cache-busting parameter to force browser to fetch fresh image
|
||||
// This prevents showing old cached image when avatar is updated
|
||||
const profileWithTimestamp = profile as unknown as { updatedAt?: string };
|
||||
const cacheBuster = profileWithTimestamp.updatedAt
|
||||
? new Date(profileWithTimestamp.updatedAt).getTime()
|
||||
: Date.now();
|
||||
const urlWithCacheBuster = `${presignedUrl}&_t=${cacheBuster}`;
|
||||
setAvatarUrl(urlWithCacheBuster);
|
||||
} catch (error) {
|
||||
console.error('Failed to get avatar URL:', error);
|
||||
}
|
||||
@@ -82,7 +89,7 @@ function ProfileCard({ profile }: ProfileCardProps) {
|
||||
}
|
||||
};
|
||||
fetchAvatarUrl();
|
||||
}, [profile.avatar]);
|
||||
}, [profile.avatar, profile]);
|
||||
|
||||
const getProfileImageUrl = () => {
|
||||
if (avatarUrl) return avatarUrl;
|
||||
|
||||
Reference in New Issue
Block a user