diff --git a/components/organisms/shift-schedule/ShiftDetailModal.tsx b/components/organisms/shift-schedule/ShiftDetailModal.tsx index b4dd6da..1fd7547 100644 --- a/components/organisms/shift-schedule/ShiftDetailModal.tsx +++ b/components/organisms/shift-schedule/ShiftDetailModal.tsx @@ -3,7 +3,7 @@ import { useAuth } from "@/lib/auth-context"; import { DEPARTMENTS } from "@/lib/constants"; import { useShift } from "@/lib/shift-context"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import type { ShiftDetailModalProps } from "./ShiftSchedule.types"; @@ -82,6 +82,44 @@ export default function ShiftDetailModal({ absent: "bg-red-100 text-red-700", }; + const StaffName = ({ staffId }: { staffId: 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/staff/${staffId}`); + + 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 (staffId) { + getName(); + } + }, [staffId]); // Chạy lại nếu staffId thay đổi + + if (loading) + return ...; + + return {name || "N/A"}; + }; + return (