import React, {FC, useEffect, useState} from "react" import {useParams} from "react-router-dom" import useAxiosTools from "../../hooks/AxiosTools" import {timeTracker, toDo} from "../../utilities/types" import {EditSVG} from "../../components/SVG" import Field, {TextArea} from "../../components/Field" const ToDoShow = () => { const {id} = useParams() const {setLoading, errorCatch, errorLabel, axiosGet, axiosPut} = useAxiosTools(true) const [toDo, setToDo] = useState(null) const [editMode, setEditMode] = useState(false) const [editForm, setEditForm] = useState(null) useEffect(() => { fetchToDo() }, []) const fetchToDo = async () => { try { const res = await axiosGet('/api/todos/' + id) setToDo(res.data) } catch (error) { errorCatch(error) } finally { setLoading(false) } } const handleEditTodoMode = async () => { if (editMode) { try { const res = await axiosPut('/api/todos/' + id, editForm) setToDo(res.data) } catch (error) { errorCatch(error) } } else { setEditForm(toDo) } setEditMode(!editMode) } const handleEditTodo = (event: React.ChangeEvent) => { setEditForm({...editForm, [event.target.name]: event.target.value}) } return
{errorLabel()} {editMode ? <>