diff --git a/client/src/pages/Projects/components/Project/Project.tsx b/client/src/pages/Projects/components/Project/Project.tsx index b2a36c8..2719673 100644 --- a/client/src/pages/Projects/components/Project/Project.tsx +++ b/client/src/pages/Projects/components/Project/Project.tsx @@ -8,7 +8,7 @@ import { ProjectProvider } from "../../../../providers/ProjectProvider"; import { createSWRFetcher } from "../../../../utils/swrFetcher"; import { AddTask } from "./AddTask"; import { ProjectOptions } from "./ProjectOptions"; -import { TaskListProps, TasksList } from "./TasksList"; +import { TaskListProps, TasksList } from "./TaskList/TasksList"; export type APIProjectTasksList = { data: TaskListProps["tasks"]; diff --git a/client/src/pages/Projects/components/Project/TaskList/EditTaskDialog.tsx b/client/src/pages/Projects/components/Project/TaskList/EditTaskDialog.tsx new file mode 100644 index 0000000..a25a221 --- /dev/null +++ b/client/src/pages/Projects/components/Project/TaskList/EditTaskDialog.tsx @@ -0,0 +1,80 @@ +import { + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + TextField, +} from "@mui/material"; +import { SetStateAction, useState } from "react"; +import { SubmitHandler, useForm } from "react-hook-form"; +import { useAuth } from "../../../../../hooks/useAuth"; +import { useProject } from "../../../../../hooks/useProject"; +import { Task } from "./TasksListItem"; + +type EditProjectForm = { + description: string; +}; + +export type EditTaskDialogProps = { + open: boolean; + setOpen: (value: SetStateAction) => void; + task: Task; +}; + +export const EditTaskDialog = ({ + task, + open, + setOpen, +}: EditTaskDialogProps) => { + const [isLoading, setIsLoading] = useState(false); + const { apiClient } = useAuth(); + const { tasksMutate, project } = useProject(); + const { register, handleSubmit, reset } = useForm({ + defaultValues: task, + }); + + const handleClose = () => { + reset(); + setOpen(false); + }; + + const onSubmit: SubmitHandler = (data) => { + setIsLoading(true); + + apiClient(`projects/${project.id}/tasks/${task.id}`, { + method: "PUT", + body: JSON.stringify(data), + }).then(() => { + tasksMutate(); + setIsLoading(false); + handleClose(); + }); + }; + + return ( + +
+ Rename task + + + + + + + +
+
+ ); +}; diff --git a/client/src/pages/Projects/components/Project/TasksList.tsx b/client/src/pages/Projects/components/Project/TaskList/TasksList.tsx similarity index 89% rename from client/src/pages/Projects/components/Project/TasksList.tsx rename to client/src/pages/Projects/components/Project/TaskList/TasksList.tsx index 25966e2..70ee387 100644 --- a/client/src/pages/Projects/components/Project/TasksList.tsx +++ b/client/src/pages/Projects/components/Project/TaskList/TasksList.tsx @@ -1,6 +1,6 @@ import { List, ListSubheader } from "@mui/material"; -import { useAuth } from "../../../../hooks/useAuth"; -import { useProject } from "../../../../hooks/useProject"; +import { useAuth } from "../../../../../hooks/useAuth"; +import { useProject } from "../../../../../hooks/useProject"; import { Task, TasksListItem } from "./TasksListItem"; export type TaskListProps = { diff --git a/client/src/pages/Projects/components/Project/TaskList/TasksListItem.tsx b/client/src/pages/Projects/components/Project/TaskList/TasksListItem.tsx new file mode 100644 index 0000000..4b1ad00 --- /dev/null +++ b/client/src/pages/Projects/components/Project/TaskList/TasksListItem.tsx @@ -0,0 +1,103 @@ +import DeleteIcon from "@mui/icons-material/Delete"; +import EditIcon from "@mui/icons-material/Edit"; + +import { + Checkbox, + IconButton, + ListItem, + ListItemAvatar, + ListItemText, + Tooltip, +} from "@mui/material"; +import { useState } from "react"; +import { formatDate } from "../../../../../utils/formatDate"; +import { EditTaskDialog } from "./EditTaskDialog"; + +export type Task = { + id: number; + description: string; + createdAt: string; + finishedAt?: string; +}; + +export type TasksListItemProps = { + task: Task; + onCheck: (taskId: number) => void; + onDelete: (taskId: number) => void; +}; + +export const TasksListItem = ({ + task, + onCheck, + onDelete, +}: TasksListItemProps) => { + const [isLoading, setIsLoading] = useState(false); + const [openEditDialog, setOpenEditDialog] = useState(false); + const finished = !!task.finishedAt; + const blockInteration = finished || isLoading; + + const handleCheck = () => { + setIsLoading(true); + onCheck(task.id); + }; + + const handleDelete = () => { + setIsLoading(true); + onDelete(task.id); + }; + + const handleEdit = () => { + setOpenEditDialog(true); + }; + + const tooltipText = ` + ${task.finishedAt ? `Finished at: ${formatDate(task.finishedAt)} |` : ""} + ${`Created at: ${formatDate(task.createdAt)}`} + `; + + return ( + <> + + + + + + + + + + + ) + } + > + + + + + + + + ); +}; diff --git a/client/src/pages/Projects/components/Project/TaskList/index.ts b/client/src/pages/Projects/components/Project/TaskList/index.ts new file mode 100644 index 0000000..45c6bc3 --- /dev/null +++ b/client/src/pages/Projects/components/Project/TaskList/index.ts @@ -0,0 +1 @@ +export * from './TasksList' \ No newline at end of file diff --git a/client/src/pages/Projects/components/Project/TasksListItem.tsx b/client/src/pages/Projects/components/Project/TasksListItem.tsx deleted file mode 100644 index ac2eabf..0000000 --- a/client/src/pages/Projects/components/Project/TasksListItem.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import DeleteIcon from "@mui/icons-material/Delete"; -import { - Checkbox, - IconButton, - ListItem, - ListItemAvatar, - ListItemText, - Tooltip, -} from "@mui/material"; -import { useState } from "react"; -import { formatDate } from "../../../../utils/formatDate"; - -export type Task = { - id: number; - description: string; - createdAt: string; - finishedAt?: string; -}; - -export type TasksListItemProps = { - task: Task; - onCheck: (taskId: number) => void; - onDelete: (taskId: number) => void; -}; - -export const TasksListItem = ({ - task, - onCheck, - onDelete, -}: TasksListItemProps) => { - const finished = !!task.finishedAt; - const [isLoading, setIsLoading] = useState(false); - - const handleCheck = () => { - setIsLoading(true); - onCheck(task.id); - }; - - const handleDelete = () => { - setIsLoading(true); - onDelete(task.id); - }; - - const blockInteration = finished || isLoading; - - return ( - - - - - ) - } - > - - - - - - - ); -};