Skip to content

Commit

Permalink
feat:add useKanban hook
Browse files Browse the repository at this point in the history
  • Loading branch information
maceteligolden committed Dec 5, 2023
1 parent 5ac1e72 commit aab827f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions apps/web/app/hooks/features/useKanban.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { kanbanBoardState } from "@app/stores/kanban";
import { useTaskStatus } from "./useTaskStatus";
import { useRecoilState } from "recoil";
import { useEffect, useState } from "react";
import { ITaskStatusItemList } from "@app/interfaces";

export function useKanban() {

const [loading, setLoading] = useState<boolean>(true);

const [kanbanBoard, setKanbanBoard] = useRecoilState(kanbanBoardState);

const taskStatusHook = useTaskStatus();

/**
* format data for kanban board
*/
useEffect(()=> {
if(taskStatusHook.loading) {
let kanban = {};
taskStatusHook.taskStatus.map((taskStatus: ITaskStatusItemList,)=> {
kanban = {
...kanban,
[taskStatus.name ? taskStatus.name : ''] : []
}
});
setKanbanBoard(kanban)
setLoading(false)
}
},[taskStatusHook.loading])

return {
data: kanbanBoard,
isLoading: loading,
columns: taskStatusHook.taskStatus
}
}

0 comments on commit aab827f

Please sign in to comment.