import { useState, useEffect } from "react"; import { Link } from "react-router-dom"; import todoApi from "../../apis/todo.api"; import { useAuth } from "../../utils/context.js"; import catchErrors from "../../utils/catchErrors"; import moment from "moment"; import styles from "./menu.module.scss"; const Menu = () => { const { user, logout } = useAuth(); const [todoList, setTodoList] = useState({ percent: 0, list: [] }) const [error, setError] = useState(""); useEffect(() => { todayTodo() }, []) async function todayTodo() { try { setError("") const result = await todoApi.getTodopercent(user.id, moment().format("YYYY-MM-DD")) setTodoList({ ...todoList, ...result }) } catch (error) { catchErrors(error, setError) } } async function checkFn(e, todoId) { try { setError("") const check_v = e.target.value === "true" ? true : false await todoApi.edit({id: todoId, done: check_v}, user.id) todayTodo() } catch (error) { catchErrors(error, setError) } } return ( <> ) } export default Menu