/* eslint-disable jsx-a11y/alt-text */ /* eslint-disable @next/next/no-img-element */ /* eslint-disable @typescript-eslint/no-explicit-any */ import React from "react"; import Swal from "sweetalert2"; import { getFormattedAddress } from "../../../lib/Helper"; const DEFAULT_IMAGE = "/images/international/no-image.jpg"; interface Props { users: any[]; handleEdit: (user: any) => void; handleChangeStatus: (user: any) => void; handleResetPassword: (user: any) => void; } const StaffCard = ({ users = [], handleEdit, handleChangeStatus, handleResetPassword, }: Props) => { const [openId, setOpenId] = React.useState(null); const dropdownRef = React.useRef(null); /* ================= CLICK OUTSIDE ================= */ React.useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) ) { setOpenId(null); } }; document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, []); const copyToClipboard = (text: string) => { navigator.clipboard.writeText(text); Swal.fire({ toast: true, position: "top-end", icon: "success", title: "Copied to clipboard", showConfirmButton: false, timer: 1500, }); }; return ( <> {users.map((user: any) => (
{/* ===== HEADER ===== */}
{/* IMAGE */} ((e.target as HTMLImageElement).src = DEFAULT_IMAGE) } /> {/* DETAILS */}
{user?.isActive ? "Active" : "Inactive"}
{/* NAME */} {user?.firstName} {user?.lastName} {/* EMPLOYEE ID */}

{user?.employeeId || "—"}

{/* DROPDOWN */} {openId === user.id && (
)}
{/* ADDRESS */}

{getFormattedAddress(user)}


{/* CONTACT */}
window.open(`tel:${user?.phone}`)} > {user?.phone || "—"} copyToClipboard(user?.email)} title="Click to copy email" > {user?.email || "—"}
))} ); }; export default StaffCard;