From 063e7eda709d6eb6bcc16f7aab442ce677010d87 Mon Sep 17 00:00:00 2001 From: sosokker Date: Tue, 21 Nov 2023 04:50:22 +0700 Subject: [PATCH] Connect Kanban with Api (Fetch data) + Save Task Position --- .../components/kanbanBoard/kanbanBoard.jsx | 289 +++++++++++------- .../src/components/kanbanBoard/kanbanPage.jsx | 2 + .../src/components/kanbanBoard/taskCard.jsx | 12 +- .../kanbanBoard/taskDetailModal.jsx | 43 ++- 4 files changed, 202 insertions(+), 144 deletions(-) diff --git a/frontend/src/components/kanbanBoard/kanbanBoard.jsx b/frontend/src/components/kanbanBoard/kanbanBoard.jsx index 7866bbb..179702a 100644 --- a/frontend/src/components/kanbanBoard/kanbanBoard.jsx +++ b/frontend/src/components/kanbanBoard/kanbanBoard.jsx @@ -1,100 +1,17 @@ -import { useMemo, useState } from "react"; +import { useMemo, useState, useEffect } from "react"; import ColumnContainerCard from "./columnContainerWrapper"; import { DndContext, DragOverlay, PointerSensor, useSensor, useSensors } from "@dnd-kit/core"; import { SortableContext, arrayMove } from "@dnd-kit/sortable"; import { createPortal } from "react-dom"; import TaskCard from "./taskCard"; import { AiOutlinePlusCircle } from "react-icons/ai"; - -const defaultCols = [ - { - id: "todo", - title: "Todo", - }, - { - id: "doing", - title: "Work in progress", - }, - { - id: "done", - title: "Done", - }, -]; - -const defaultTasks = [ - { - id: "1", - columnId: "todo", - content: "List admin APIs for dashboard", - }, - { - id: "2", - columnId: "todo", - content: - "Develop user registration functionality with OTP delivered on SMS after email confirmation and phone number confirmation", - }, - { - id: "3", - columnId: "doing", - content: "Conduct security testing", - }, - { - id: "4", - columnId: "doing", - content: "Analyze competitors", - }, - { - id: "5", - columnId: "done", - content: "Create UI kit documentation", - }, - { - id: "6", - columnId: "done", - content: "Dev meeting", - }, - { - id: "7", - columnId: "done", - content: "Deliver dashboard prototype", - }, - { - id: "8", - columnId: "todo", - content: "Optimize application performance", - }, - { - id: "9", - columnId: "todo", - content: "Implement data validation", - }, - { - id: "10", - columnId: "todo", - content: "Design database schema", - }, - { - id: "11", - columnId: "todo", - content: "Integrate SSL web certificates into workflow", - }, - { - id: "12", - columnId: "doing", - content: "Implement error logging and monitoring", - }, - { - id: "13", - columnId: "doing", - content: "Design and implement responsive UI", - }, -]; +import axiosInstance from "../../api/configs/AxiosConfig"; function KanbanBoard() { - const [columns, setColumns] = useState(defaultCols); + const [columns, setColumns] = useState([]); const columnsId = useMemo(() => columns.map(col => col.id), [columns]); - const [tasks, setTasks] = useState(defaultTasks); + const [tasks, setTasks] = useState([]); const [activeColumn, setActiveColumn] = useState(null); @@ -108,16 +25,97 @@ function KanbanBoard() { }) ); + // Example + // { + // "id": 95, + // "title": "Test Todo", + // "notes": "Test TodoTest TodoTest Todo", + // "importance": 1, + // "difficulty": 1, + // "challenge": false, + // "fromSystem": false, + // "creation_date": "2023-11-20T19:50:16.369308Z", + // "last_update": "2023-11-20T19:50:16.369308Z", + // "is_active": true, + // "is_full_day_event": false, + // "start_event": "2023-11-20T19:49:49Z", + // "end_event": "2023-11-23T18:00:00Z", + // "google_calendar_id": null, + // "completed": true, + // "completion_date": "2023-11-20T19:50:16.369308Z", + // "priority": 3, + // "user": 1, + // "list_board": 1, + // "tags": [] + // } + // ] + + // [ + // { + // "id": 8, + // "name": "test", + // "position": 2, + // "board": 3 + // } + // ] + + useEffect(() => { + const fetchData = async () => { + try { + const tasksResponse = await axiosInstance.get("/todo"); + + // Transform + const transformedTasks = tasksResponse.data.map(task => ({ + id: task.id, + columnId: task.list_board, + content: task.title, + difficulty: task.difficulty, + notes: task.notes, + importance: task.importance, + difficulty: task.difficulty, + challenge: task.challenge, + fromSystem: task.fromSystem, + creation_date: task.creation_date, + last_update: task.last_update, + is_active: task.is_active, + is_full_day_event: task.is_full_day_event, + start_event: task.start_event, + end_event: task.end_event, + google_calendar_id: task.google_calendar_id, + completed: task.completed, + completion_date: task.completion_date, + priority: task.priority, + user: task.user, + list_board: task.list_board, + tags: task.tags, + })); + setTasks(transformedTasks); + + const columnsResponse = await axiosInstance.get("/lists"); + + // Transform + const transformedColumns = columnsResponse.data.map(column => ({ + id: column.id, + title: column.name, + })); + setColumns(transformedColumns); + } catch (error) { + console.error("Error fetching data from API:", error); + } + }; + fetchData(); + }, []); + return (
+ m-auto + flex + w-full + items-center + overflow-x-auto + overflow-y-hidden + ">
@@ -136,26 +134,26 @@ function KanbanBoard() { ))}
- {/* create new column */} + {/* create new column */}
+
+
); }; diff --git a/frontend/src/components/kanbanBoard/taskCard.jsx b/frontend/src/components/kanbanBoard/taskCard.jsx index 379abf5..3f7d9ac 100644 --- a/frontend/src/components/kanbanBoard/taskCard.jsx +++ b/frontend/src/components/kanbanBoard/taskCard.jsx @@ -4,7 +4,7 @@ import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import TaskDetailModal from "./taskDetailModal"; -function TaskCard({ task, deleteTask, updateTask }) { +function TaskCard({ task, deleteTask, updateTask, description, tags, difficulty, challenge, importance}) { const [mouseIsOver, setMouseIsOver] = useState(false); const { setNodeRef, attributes, listeners, transform, transition, isDragging } = useSortable({ @@ -15,6 +15,7 @@ function TaskCard({ task, deleteTask, updateTask }) { }, }); + const style = { transition, transform: CSS.Transform.toString(transform), @@ -38,7 +39,14 @@ function TaskCard({ task, deleteTask, updateTask }) { return (
- +
{ setChallengeChecked(!isChallengeChecked); @@ -15,8 +15,9 @@ function TaskDetailModal() { const handleImportantChange = () => { setImportantChecked(!isImportantChecked); }; - const handleDifficultyChange = event => { - setDifficulty(parseInt(event.target.value, 10)); + + const handleDifficultyChange = (event) => { + setCurrentDifficulty(parseInt(event.target.value, 10)); }; return ( @@ -26,9 +27,11 @@ function TaskDetailModal() {

- {}Title + + {}{title} +

-

Todo List

+

{title}

@@ -42,25 +45,13 @@ function TaskDetailModal() {
-
+
@@ -72,10 +63,12 @@ function TaskDetailModal() { Description - + - {/* Difficulty, Challenge and Importance */} + {/* Difficulty, Challenge, and Importance */}