/** * @file components/layout/ServerSettingsMenu.tsx * @description Header menu button providing server-level action options like deleting a server. */ "use client"; import { useState, useRef, useEffect } from "react"; import { Settings, Trash2 } from "lucide-react"; import { DeleteServerModal } from "@/components/modals/DeleteServerModal"; /** * Props for the ServerSettingsMenu component. * * @interface ServerSettingsMenuProps * @property {string} serverId - The unique identifier of the server. * @property {string} serverName - The name of the server used for display and verification during deletion. */ interface ServerSettingsMenuProps { serverId: string; serverName: string; } /** * Renders a dropdown menu button for server settings, including an option to open the server deletion modal. * * @param {ServerSettingsMenuProps} props - The component props. * @param {string} props.serverId - The unique identifier of the server. * @param {string} props.serverName - The display name of the server. * @returns {JSX.Element} The rendered server settings dropdown menu and modal component. */ export function ServerSettingsMenu({ serverId, serverName, }: ServerSettingsMenuProps) { const [isOpen, setIsOpen] = useState(false); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const menuRef = useRef(null); // Close dropdown when clicking outside useEffect(() => { /** * Handles mouse click events outside of the menu container to close the dropdown. * * @param {MouseEvent} event - The mouse click event object. */ function handleClickOutside(event: MouseEvent) { if (menuRef.current && !menuRef.current.contains(event.target as Node)) { setIsOpen(false); } } document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, []); return (
{/* Icon Button */} {/* Dropdown Menu */} {isOpen && (
)} {/* Delete Modal */} setIsDeleteModalOpen(false)} />
); }