refactor: remove client-side agent fetching in favor of direct prop data usage in FeaturesSection
This commit is contained in:
@@ -4,8 +4,6 @@ import { useState, useEffect } from 'react';
|
||||
import Image from 'next/image';
|
||||
import type { FeaturesContent, FeaturedAgentItem } from '@/types/cms';
|
||||
import { resolveImageUrl } from '@/services/cms.service';
|
||||
import { agentsService } from '@/services/agents.service';
|
||||
import { uploadService } from '@/services/upload.service';
|
||||
|
||||
const defaultContent: FeaturesContent = {
|
||||
title: 'Find Trusted Real Estate Professionals On Demand',
|
||||
@@ -103,49 +101,9 @@ function AgentCard({ agent, className = '' }: { agent: FeaturedAgentItem; classN
|
||||
|
||||
export function FeaturesSection({ content }: { content?: FeaturesContent }) {
|
||||
const data = content ?? defaultContent;
|
||||
const [agents, setAgents] = useState<FeaturedAgentItem[]>([]);
|
||||
const agents = data.featuredAgents || [];
|
||||
const [activeCard, setActiveCard] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchFeaturedAgents = async () => {
|
||||
try {
|
||||
const featured = await agentsService.getFeaturedAgents(3);
|
||||
if (featured.length > 0) {
|
||||
// Map API response to FeaturedAgentItem format
|
||||
const mapped = await Promise.all(
|
||||
featured.map(async (agent) => {
|
||||
let imageUrl = '/assets/icons/user-placeholder-icon.svg';
|
||||
if (agent.avatar) {
|
||||
if (agent.avatar.startsWith('http') || agent.avatar.startsWith('/')) {
|
||||
imageUrl = agent.avatar;
|
||||
} else {
|
||||
try {
|
||||
imageUrl = await uploadService.getPresignedDownloadUrl(agent.avatar);
|
||||
} catch (_e) {
|
||||
// use placeholder
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: `${agent.firstName || ''} ${agent.lastName || ''}`.trim(),
|
||||
role: agent.agentType?.name || '',
|
||||
rating: agent.averageRating ? String(agent.averageRating) : '',
|
||||
location: agent.city || agent.state || '',
|
||||
experience: agent.experience ? `${agent.experience}+ years in the real estate industry.` : '',
|
||||
imageUrl,
|
||||
};
|
||||
}),
|
||||
);
|
||||
setAgents(mapped);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch featured agents:', err);
|
||||
}
|
||||
};
|
||||
|
||||
fetchFeaturedAgents();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<section className="py-16 md:py-20 bg-white">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
|
||||
Reference in New Issue
Block a user