jaecoo-kelapagading/components/landing-page/best-agent.tsx

97 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-07-14 11:55:57 +00:00
"use client";
import Image from "next/image";
import { motion } from "framer-motion";
2026-02-02 13:43:48 +00:00
import { useEffect, useState } from "react";
import { getAgentData } from "@/service/agent";
2025-07-14 11:55:57 +00:00
2026-02-02 13:43:48 +00:00
type Agent = {
id: number;
name: string;
job_title: string;
status_id: number;
profile_picture_url: string;
created_at: string;
};
2025-07-14 11:55:57 +00:00
export default function BestAgent() {
2026-02-02 13:43:48 +00:00
const [agents, setAgents] = useState<Agent[]>([]);
useEffect(() => {
const fetchAgents = async () => {
try {
const req = {
limit: "10",
page: 1,
search: "",
};
const res = await getAgentData(req);
const agentsData: Agent[] = res?.data?.data || [];
const latestApprovedAgents = agentsData
.filter((agent) => agent.status_id === 2) // ✅ approved only
.sort(
(a, b) =>
new Date(b.created_at).getTime() -
new Date(a.created_at).getTime(),
) // ✅ newest first
.slice(0, 5); // ✅ max 5
setAgents(latestApprovedAgents);
} catch (error) {
console.error("Failed to fetch agents:", error);
}
};
fetchAgents();
}, []);
2025-07-14 11:55:57 +00:00
return (
2026-02-02 13:43:48 +00:00
<section className="py-16 px-6 md:px-5 bg-[#FAFDFF] text-center mt-0">
2025-07-14 11:55:57 +00:00
<motion.h2
initial={{ opacity: 0, y: 30 }}
whileInView={{ opacity: 1, y: 0 }}
transition={{ duration: 0.6 }}
viewport={{ once: true }}
2026-02-02 13:43:48 +00:00
className="text-3xl md:text-6xl font-semibold text-gray-900 mb-2"
2025-07-14 11:55:57 +00:00
>
Our Teams
</motion.h2>
2026-02-02 13:43:48 +00:00
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-2 place-items-center mt-10">
2025-07-14 11:55:57 +00:00
{agents.map((agent, index) => (
<motion.div
2026-02-02 13:43:48 +00:00
key={agent.id}
2025-07-14 11:55:57 +00:00
initial={{ opacity: 0, y: 40 }}
whileInView={{ opacity: 1, y: 0 }}
transition={{
duration: 0.6,
delay: index * 0.2 + 0.3,
ease: "easeOut",
}}
viewport={{ once: true, amount: 0.3 }}
2026-02-02 13:43:48 +00:00
className="bg-white shadow-md py-4 gap-2 flex flex-col items-center h-[300px] w-[250px]"
2025-07-14 11:55:57 +00:00
>
2026-02-02 13:43:48 +00:00
<div className="relative w-44 h-48 mb-3">
2025-07-14 11:55:57 +00:00
<Image
2026-02-02 13:43:48 +00:00
src={agent.profile_picture_url}
2025-07-14 11:55:57 +00:00
alt={agent.name}
fill
className="rounded-full object-cover"
/>
</div>
2026-02-02 13:43:48 +00:00
2025-07-14 11:55:57 +00:00
<h3 className="text-lg text-gray-900 text-center">{agent.name}</h3>
2026-02-02 13:43:48 +00:00
<p className="text-sm text-gray-600 text-center mt-1">
{agent.job_title}
2025-07-14 11:55:57 +00:00
</p>
</motion.div>
))}
</div>
</section>
);
}