|
| 1 | +import { useState, useEffect } from "react"; |
| 2 | +import { axiosInstance } from "src/api/AxiosConfig"; |
| 3 | + |
| 4 | +export function TableBoard() { |
| 5 | + const [tasks, setTasks] = useState([]); |
| 6 | + |
| 7 | + // ---------------- Fetch Data ---------------- |
| 8 | + useEffect(() => { |
| 9 | + const fetchData = async () => { |
| 10 | + try { |
| 11 | + const tasksResponse = await axiosInstance.get("/todo"); |
| 12 | + |
| 13 | + // Transform |
| 14 | + const transformedTasks = tasksResponse.data.map((task) => ({ |
| 15 | + id: task.id, |
| 16 | + columnId: task.list_board, |
| 17 | + content: task.title, |
| 18 | + difficulty: task.difficulty, |
| 19 | + notes: task.notes, |
| 20 | + importance: task.importance, |
| 21 | + challenge: task.challenge, |
| 22 | + fromSystem: task.fromSystem, |
| 23 | + creation_date: task.creation_date, |
| 24 | + last_update: task.last_update, |
| 25 | + is_active: task.is_active, |
| 26 | + is_full_day_event: task.is_full_day_event, |
| 27 | + start_event: task.start_event, |
| 28 | + end_event: task.end_event, |
| 29 | + google_calendar_id: task.google_calendar_id, |
| 30 | + completed: task.completed, |
| 31 | + completion_date: task.completion_date, |
| 32 | + priority: task.priority, |
| 33 | + user: task.user, |
| 34 | + list_board: task.list_board, |
| 35 | + tags: task.tags, |
| 36 | + subtaskCount: task.sub_task_count, |
| 37 | + })); |
| 38 | + setTasks(transformedTasks); |
| 39 | + } catch (error) { |
| 40 | + console.error("Error fetching data from API:", error); |
| 41 | + } |
| 42 | + }; |
| 43 | + fetchData(); |
| 44 | + }, []); |
| 45 | + |
| 46 | + // ---------------- END Fetch Data ---------------- |
| 47 | + |
| 48 | + return ( |
| 49 | + <div className="overflow-x-auto"> |
| 50 | + <table className="table"> |
| 51 | + {/* head */} |
| 52 | + <thead> |
| 53 | + <tr> |
| 54 | + <th></th> |
| 55 | + <th>Title</th> |
| 56 | + <th>Description</th> |
| 57 | + <th>Priority</th> |
| 58 | + <th>Due Date</th> |
| 59 | + </tr> |
| 60 | + </thead> |
| 61 | + <tbody> |
| 62 | + {/* BODY */} |
| 63 | + {tasks.map((task, index) => ( |
| 64 | + <tr key={index}> |
| 65 | + <th> |
| 66 | + <label></label> |
| 67 | + </th> |
| 68 | + <td> |
| 69 | + <div className="flex items-center gap-3"> |
| 70 | + <div> |
| 71 | + <div className="font-bold">{task.content}</div> |
| 72 | + <div className="text-sm opacity-50">{task.content}</div> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + </td> |
| 76 | + <td> |
| 77 | + {task.notes} |
| 78 | + <br /> |
| 79 | + <span className="badge badge-ghost badge-sm">Description</span> |
| 80 | + </td> |
| 81 | + <td>{task.priority}</td> |
| 82 | + <th> |
| 83 | + <button className="btn btn-ghost btn-xs">{task.end_event}</button> |
| 84 | + </th> |
| 85 | + </tr> |
| 86 | + ))} |
| 87 | + {/* END BODY */} |
| 88 | + </tbody> |
| 89 | + {/* foot */} |
| 90 | + <tfoot> |
| 91 | + <tr> |
| 92 | + <th></th> |
| 93 | + <th>Title</th> |
| 94 | + <th>Description</th> |
| 95 | + <th>Priority</th> |
| 96 | + <th>Due Date</th> |
| 97 | + </tr> |
| 98 | + </tfoot> |
| 99 | + </table> |
| 100 | + </div> |
| 101 | + ); |
| 102 | +} |
0 commit comments