diff --git a/client/src/pages/Projects/components/AddTask.tsx b/client/src/pages/Projects/components/AddTask.tsx new file mode 100644 index 0000000..a097d16 --- /dev/null +++ b/client/src/pages/Projects/components/AddTask.tsx @@ -0,0 +1,57 @@ +import AddTaskIcon from "@mui/icons-material/AddTask"; +import { Box, Button, TextField, Toolbar } from "@mui/material"; +import { useState } from "react"; +import { SubmitHandler, useForm } from "react-hook-form"; +import { KeyedMutator } from "swr"; +import { useAuth } from "../../../hooks/useAuth"; +import { APIProjectTasksList } from "./Project"; + +type NewTaskForm = { + description: string; +}; + +export type AddTaskProps = { + projectId: number; + mutate: KeyedMutator; +}; + +export const AddTask = ({ projectId, mutate }: AddTaskProps) => { + const [isLoading, setIsLoading] = useState(false); + const { apiClient } = useAuth(); + const { register, handleSubmit, reset } = useForm(); + + const onSubmit: SubmitHandler = (data) => { + setIsLoading(true); + apiClient(`projects/${projectId}/tasks`, { + method: "POST", + body: JSON.stringify(data), + }).then(() => { + mutate(); + reset(); + setIsLoading(false); + }); + }; + + return ( + + + + + + + ); +}; diff --git a/client/src/pages/Projects/components/Project.tsx b/client/src/pages/Projects/components/Project.tsx index 84598da..0b00481 100644 --- a/client/src/pages/Projects/components/Project.tsx +++ b/client/src/pages/Projects/components/Project.tsx @@ -11,7 +11,7 @@ import useSWR from "swr"; import { useAuth } from "../../../hooks/useAuth"; import { createSWRFetcher } from "../../../utils/swrFetcher"; import { TaskListProps, TasksList } from "./TasksList"; - +import { AddTask } from "./AddTask"; export type APIProjectTasksList = { data: TaskListProps["tasks"]; }; @@ -44,6 +44,7 @@ export const Project = (props: ProjectProps) => { title={props.name} /> + { password, }), }).then(async (res) => { - setToken((await res.json()).token); - setIsLoginDialogOpen(false); + if (res.status === 200) { + setToken((await res.json()).token); + setIsLoginDialogOpen(false); + } }); }, [apiClient, setToken]