fix some lint errors
This commit is contained in:
@@ -10,8 +10,9 @@ const ToDoShow = () => {
|
||||
const {id} = useParams()
|
||||
const {setLoading, errorCatch, errorLabel, axiosGet, axiosPut} = useAxiosTools(true)
|
||||
const [toDo, setToDo] = useState<toDo|null>(null)
|
||||
const [name, setName] = useState<string>('')
|
||||
const [description, setDescription] = useState<string>('')
|
||||
const [editMode, setEditMode] = useState(false)
|
||||
const [editForm, setEditForm] = useState<toDo|null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
fetchToDo()
|
||||
@@ -29,29 +30,26 @@ const ToDoShow = () => {
|
||||
}
|
||||
|
||||
const handleEditTodoMode = async () => {
|
||||
if (editMode) {
|
||||
if (editMode && toDo) {
|
||||
try {
|
||||
const res = await axiosPut('/api/todos/' + id, editForm)
|
||||
const res = await axiosPut('/api/todos/' + id, {...toDo, name, description})
|
||||
setToDo(res.data)
|
||||
} catch (error) {
|
||||
errorCatch(error)
|
||||
}
|
||||
} else {
|
||||
setEditForm(toDo)
|
||||
setName(toDo?.name ?? '')
|
||||
setDescription(toDo?.description ?? '')
|
||||
}
|
||||
setEditMode(!editMode)
|
||||
}
|
||||
|
||||
const handleEditTodo = (event: React.ChangeEvent<HTMLInputElement|HTMLTextAreaElement>) => {
|
||||
setEditForm({...editForm, [event.target.name]: event.target.value})
|
||||
}
|
||||
|
||||
return <div className="relative p-5">
|
||||
{errorLabel()}
|
||||
{editMode ? <>
|
||||
<button className="absolute right-5 flex" onClick={handleEditTodoMode}>Valider <EditSVG className="w-5"/></button>
|
||||
<Field name="name" value={editForm?.name} onChange={handleEditTodo} />
|
||||
<TextArea name="description" value={editForm?.description} onChange={handleEditTodo} />
|
||||
<Field name="name" value={name} onChange={event => setName(event.target.value)} />
|
||||
<TextArea name="description" value={description} onChange={event => setDescription(event.target.value)} />
|
||||
</> : <>
|
||||
<button className="absolute right-5" onClick={handleEditTodoMode}><EditSVG className="w-5"/></button>
|
||||
<h1 className="text-lg font-bold">{toDo?.name}</h1>
|
||||
@@ -65,7 +63,7 @@ const ToDoShow = () => {
|
||||
|
||||
export default ToDoShow
|
||||
|
||||
const ToDoTimeTrackers: FC<ToDoTimeTrackers> = ({toDo: toDo}) => {
|
||||
const ToDoTimeTrackers: FC<{toDo: toDo}> = ({toDo: toDo}) => {
|
||||
|
||||
const {setLoading, errorCatch, errorLabel, axiosGet} = useAxiosTools(true)
|
||||
const [timeTrackers, setTimeTrackers] = useState<timeTracker[]>([])
|
||||
@@ -125,7 +123,3 @@ const ToDoTimeTrackers: FC<ToDoTimeTrackers> = ({toDo: toDo}) => {
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
interface ToDoTimeTrackers {
|
||||
toDo: toDo,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user