import React, { useCallback } from "react"; import { MenuItem, MenuProps, Select, SelectChangeEvent } from "@mui/material"; import { useTranslation } from "react-i18next"; import { TaskGroup } from "@/app/api/tasks"; interface Props { taskGroupsByProject: { [projectId: number]: { value: TaskGroup["id"]; label: string; }[]; }; projectId: number | undefined; value: number | undefined; onTaskGroupSelect: (taskGroupId: number | string) => Promise | void; error?: boolean; } const menuProps: Partial = { slotProps: { paper: { sx: { maxHeight: 400 }, }, }, anchorOrigin: { vertical: "bottom", horizontal: "left", }, transformOrigin: { vertical: "top", horizontal: "left", }, }; const TaskGroupSelect: React.FC = ({ value, projectId, onTaskGroupSelect, taskGroupsByProject, error, }) => { const { t } = useTranslation("home"); const taskGroups = projectId ? taskGroupsByProject[projectId] : []; const onChange = useCallback( (event: SelectChangeEvent) => { const newValue = event.target.value; onTaskGroupSelect(newValue); }, [onTaskGroupSelect], ); return ( ); }; type TaskGroupSelectWithoutProjectProps = Pick< Props, "value" | "onTaskGroupSelect" | "error" > & { taskGroups: TaskGroup[] }; export const TaskGroupSelectWithoutProject: React.FC< TaskGroupSelectWithoutProjectProps > = ({ value, onTaskGroupSelect, error, taskGroups }) => { const { t } = useTranslation("home"); const onChange = useCallback( (event: SelectChangeEvent) => { const newValue = event.target.value; onTaskGroupSelect(newValue); }, [onTaskGroupSelect], ); return ( ); }; export default TaskGroupSelect;