import { useContext } from "react"; import { twMerge } from "tailwind-merge"; import Row from "@moduletrace/twui/layout/Row"; import Span from "@moduletrace/twui/layout/Span"; import Stack from "@moduletrace/twui/layout/Stack"; import Button from "@moduletrace/twui/layout/Button"; import type { TaskWithNames } from "@/src/types"; import { AppContext } from "@/src/pages/__root"; import BotAvatar from "@/src/components/general/bot-avatar"; import type { BotFace } from "@/src/dict/bot-dict"; import botStoneProps from "@/src/utils/bot-stone-props"; import canManageCrew from "@/src/utils/rbac/can-manage-crew"; import relativeTime from "@/src/utils/relative-time"; import taskPlaceLabel from "@/src/utils/task-place-label"; import { Trash2 } from "lucide-react"; import RowIconButton from "./row-icon-button"; import TaskStatusChip from "./task-status-chip"; import TaskStatusMoves from "./task-status-moves"; type Props = { task: TaskWithNames; /** * Opens the task in its modal: everything about it, and for a crew * manager its edit, hand-over, files and delete. The title opens it. */ onOpen?: () => void; /** * Moves it to one status; only crew managers get the controls. */ onStatusChange?: (status: string) => void; /** * Deletes it after asking; only crew managers get the button. */ onDelete?: () => void; busy?: boolean; }; /** * One task: whose it is (a bot's stone), its title and status, where it * is and who has it, what it's blocked on, its latest note and how long ago it * moved. Its title opens it in a modal. */ export default function TaskListItem({ task, onOpen, onStatusChange, onDelete, busy }: Props) { const { pageProps } = useContext(AppContext); const can_manage = canManageCrew({ user_types: pageProps?.user_types }); const done = task.status == "done" || task.status == "cancelled"; return ( {can_manage && onDelete ? ( ) : null} {taskPlaceLabel({ task })} {task.status == "blocked" && task.blocked_reason ? ( {`Waiting on you: ${task.blocked_reason}`} ) : null} {task.updated_at ? ( {relativeTime({ at: Number(task.updated_at) })} ) : null} {task.latest_note ? ( {task.latest_note} ) : null} {can_manage && onStatusChange ? ( ) : null} ); }