/** * @file dashboard/card/CardActions.tsx * @description Client component rendering the mobile status transition and deletion dropdown for a card. */ "use client"; import { useState, useEffect, useRef } from "react"; import { MoreHorizontal, CornerDownRight, Trash2 } from "lucide-react"; import { COLUMNS, TaskStatus } from "@/types/task"; /** * Properties for the CardActions component. * * @interface CardActionsProps * @property {TaskStatus} currentStatus - The current status category of the task. * @property {boolean} isCreator - Flag indicating whether the current user is the creator of the task. * @property {(newStatus: TaskStatus) => void} onMove - Callback function triggered when a new status column is selected. * @property {() => void} onDelete - Callback function triggered when the delete action is selected. */ interface CardActionsProps { currentStatus: TaskStatus; isCreator: boolean; onMove: (newStatus: TaskStatus) => void; onDelete: () => void; } /** * Renders a mobile-only action menu component allowing users to move a task * between different columns or delete it entirely via a dropdown interface. * * @param {CardActionsProps} props - The component props. * @returns {JSX.Element} The rendered mobile card actions component. */ export default function CardActions({ currentStatus, isCreator, onMove, onDelete, }: CardActionsProps) { const [showMobileActions, setShowMobileActions] = useState(false); const dropdownRef = useRef(null); useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) ) { setShowMobileActions(false); } }; if (showMobileActions) { document.addEventListener("mousedown", handleClickOutside); } return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, [showMobileActions]); /** * Handles clicking an action item to move the task to a target status category. * * @param {React.MouseEvent} e - The mouse event object. * @param {TaskStatus} targetStatus - The target status category to move the task to. */ const handleActionClick = (e: React.MouseEvent, targetStatus: TaskStatus) => { e.stopPropagation(); onMove(targetStatus); setShowMobileActions(false); }; /** * Handles clicking the delete action item to trigger task deletion. * * @param {React.MouseEvent} e - The mouse event object. */ const handleDeleteClick = (e: React.MouseEvent) => { e.stopPropagation(); onDelete(); setShowMobileActions(false); }; return (
{COLUMNS.map((col) => { if (col.id === currentStatus) return null; return ( ); })} {/* Delete Button */} {isCreator && ( <>
)}
); }