diff --git a/frontend/src/components/EisenhowerMatrix/Eisenhower.jsx b/frontend/src/components/EisenhowerMatrix/Eisenhower.jsx
index 7c31328..86958d6 100644
--- a/frontend/src/components/EisenhowerMatrix/Eisenhower.jsx
+++ b/frontend/src/components/EisenhowerMatrix/Eisenhower.jsx
@@ -1,13 +1,20 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import { FiAlertCircle, FiClock, FiXCircle, FiCheckCircle } from "react-icons/fi";
+import { readTodoTasks } from "../../api/TaskApi";
+import axiosInstance from "../../api/configs/AxiosConfig";
function EachBlog({ name, colorCode, contentList, icon }) {
- const [tasks, setTasks] = useState(contentList);
+ const handleCheckboxChange = async (index) => {
+ const updatedTasks = [...contentList];
+ const taskId = updatedTasks[index].id;
- const handleCheckboxChange = index => {
- const updatedTasks = [...tasks];
- updatedTasks[index].checked = !updatedTasks[index].checked;
- setTasks(updatedTasks);
+ try {
+ await axiosInstance.patch(`todo/${taskId}/`, { completed: true });
+
+ updatedTasks[index].completed = true;
+ } catch (error) {
+ console.error('Error updating task:', error);
+ }
};
return (
@@ -18,20 +25,24 @@ function EachBlog({ name, colorCode, contentList, icon }) {
- {tasks.length === 0 ? (
-
No tasks
- ) : (
- tasks.map((item, index) => (
+ {contentList && contentList.length > 0 ? (
+ contentList.map((item, index) => (
handleCheckboxChange(index)}
/>
-
+
))
+ ) : (
+
No tasks
)}
@@ -39,38 +50,53 @@ function EachBlog({ name, colorCode, contentList, icon }) {
}
function Eisenhower() {
- const contentList_ui = [
- { text: "Complete report for the meeting", checked: true },
- { text: "Review project proposal", checked: false },
- { text: "Submit expense report", checked: false },
- { text: "Complete report for the meeting", checked: true },
- { text: "Review project proposal", checked: false },
- { text: "Submit expense report", checked: false },
- { text: "Complete report for the meeting", checked: true },
- { text: "Review project proposal", checked: false },
- { text: "Submit expense report", checked: false },
- ];
+ const [tasks, setTasks] = useState([]);
- const contentList_uni = [];
- const contentList_nui = [];
- const contentList_nuni = [];
+ useEffect(() => {
+ readTodoTasks()
+ .then(data => {
+ console.log(data)
+ const contentList_ui = data.filter(task => task.priority === 1);
+ const contentList_uni = data.filter(task => task.priority === 2);
+ const contentList_nui = data.filter(task => task.priority === 3);
+ const contentList_nuni = data.filter(task => task.priority === 4);
+
+ setTasks({
+ contentList_ui,
+ contentList_uni,
+ contentList_nui,
+ contentList_nuni,
+ });
+ })
+ .catch(error => console.error("Error fetching tasks:", error));
+ }, []);
return (
- } contentList={contentList_ui} />
- } contentList={contentList_uni} />
+ }
+ contentList={tasks.contentList_ui}
+ />
+ }
+ contentList={tasks.contentList_uni}
+ />
}
- contentList={contentList_nui}
+ contentList={tasks.contentList_nui}
/>
}
- contentList={contentList_nuni}
+ contentList={tasks.contentList_nuni}
/>