feat: Introduce user profile service and enable role-based profile management for users and agents, including avatar uploads and a dismissible error message in the hero section.
This commit is contained in:
@@ -5,6 +5,7 @@ import Link from 'next/link';
|
||||
import Image from 'next/image';
|
||||
import { useSession, signOut } from 'next-auth/react';
|
||||
import { agentsService } from '@/services/agents.service';
|
||||
import { usersService } from '@/services/users.service';
|
||||
import { uploadService } from '@/services/upload.service';
|
||||
|
||||
const navLinks = [
|
||||
@@ -36,17 +37,27 @@ export function CommonHeader() {
|
||||
};
|
||||
}, [showProfileMenu]);
|
||||
|
||||
// Fetch profile image from backend
|
||||
// Fetch profile image from backend based on user role
|
||||
useEffect(() => {
|
||||
const fetchProfileImage = async () => {
|
||||
try {
|
||||
const profile = await agentsService.getMyProfile();
|
||||
if (profile.avatar) {
|
||||
const role = (session?.user as any)?.role;
|
||||
let avatar: string | null = null;
|
||||
|
||||
if (role === 'AGENT') {
|
||||
const profile = await agentsService.getMyProfile();
|
||||
avatar = profile.avatar;
|
||||
} else if (role === 'USER') {
|
||||
const profile = await usersService.getMyProfile();
|
||||
avatar = profile.avatar;
|
||||
}
|
||||
|
||||
if (avatar) {
|
||||
try {
|
||||
const avatarUrl = await uploadService.getPresignedDownloadUrl(profile.avatar);
|
||||
const avatarUrl = await uploadService.getPresignedDownloadUrl(avatar);
|
||||
setProfileImage(avatarUrl);
|
||||
} catch {
|
||||
setProfileImage(profile.avatar);
|
||||
setProfileImage(avatar);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user