chore: update
This commit is contained in:
@@ -90,6 +90,44 @@ export default function ReviewsTab() {
|
|||||||
const avgRating =
|
const avgRating =
|
||||||
reviews.reduce((sum, r) => sum + r.rating, 0) / reviews.length;
|
reviews.reduce((sum, r) => sum + r.rating, 0) / reviews.length;
|
||||||
|
|
||||||
|
const CustomerName = ({ customerId }: { customerId: string }) => {
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Hàm gọi API
|
||||||
|
const getName = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
const response = await fetch(`/api/customer/${customerId}`);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Mạng lỗi hoặc không tìm thấy nhân viên");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
setName(data["name"]);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Lỗi khi lấy tên:", error);
|
||||||
|
setName("Lỗi tải tên");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (customerId) {
|
||||||
|
getName();
|
||||||
|
}
|
||||||
|
}, [customerId]); // Chạy lại nếu customerId thay đổi
|
||||||
|
|
||||||
|
if (loading)
|
||||||
|
return <span className="animate-pulse text-gray-400">...</span>;
|
||||||
|
|
||||||
|
return <span>{name || "N/A"}</span>;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{/* Summary header */}
|
{/* Summary header */}
|
||||||
@@ -124,7 +162,7 @@ export default function ReviewsTab() {
|
|||||||
<i className="fa-solid fa-user text-xs text-(--color-primary)"></i>
|
<i className="fa-solid fa-user text-xs text-(--color-primary)"></i>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-sm font-medium text-(--color-text-secondary)">
|
<span className="text-sm font-medium text-(--color-text-secondary)">
|
||||||
{review.reviewerId}
|
<CustomerName customerId={review.reviewerId!} />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex shrink-0 flex-col items-end gap-1">
|
<div className="flex shrink-0 flex-col items-end gap-1">
|
||||||
|
|||||||
Reference in New Issue
Block a user