1- import React , { useMemo , useState } from 'react'
1+ import React , { useMemo , useState , useEffect } from 'react'
22import {
33 DndContext ,
44 DragEndEvent ,
@@ -15,6 +15,7 @@ import { createPortal } from "react-dom";
1515import Container from './Container' ;
1616import PlusIcon from '../icons/PlusIcon' ;
1717import TaskCard from './TaskCard' ;
18+ import axios from 'axios' ;
1819
1920const defaultCols = [
2021 {
@@ -100,16 +101,35 @@ const defaultTasks = [
100101 } ,
101102] ;
102103
103- const Supervisor = ( { employeeDetails } ) => {
104- console . log ( employeeDetails )
105- const [ columns , setColumns ] = useState ( defaultCols ) ;
106- const updatedTask = [
107- ...defaultTasks ,
108- ...employeeDetails
109- ]
110- console . log ( updatedTask )
104+ const GetPresentEmployeesURL = 'http://localhost:8000/employee/getPresentEmployees'
105+ const UpdateEmployeeColumnURL = 'http://localhost:8000/employee/updateEmployeeColumn'
106+
107+ const Supervisor = ( ) => {
108+
109+ const [ employeeDetails , setEmployeeDetails ] = useState ( [ ] )
111110 const [ tasks , setTasks ] = useState ( employeeDetails ) ;
112111
112+ useEffect ( ( ) => {
113+ axios . get ( GetPresentEmployeesURL )
114+ . then ( response => {
115+ const data = response . data
116+ const empDetails = data . map ( ( emp ) => {
117+ const { employeeID } = emp
118+ return {
119+ ...employeeID ,
120+ // columnId: "justComeIn",
121+ id : employeeID . _id ,
122+ content : employeeID . skills ,
123+ }
124+ } )
125+ setTasks ( empDetails )
126+ } )
127+ . catch ( e => console . log ( e ) )
128+ } , [ ] )
129+
130+
131+ const [ columns , setColumns ] = useState ( defaultCols ) ;
132+
113133 const [ activeColumn , setActiveColumn ] = useState ( null ) ;
114134
115135 const [ activeTask , setActiveTask ] = useState ( null ) ;
@@ -169,6 +189,7 @@ const Supervisor = ({ employeeDetails }) => {
169189 function onDragStart ( event ) {
170190 if ( event . active . data . current ?. type === "Column" ) {
171191 setActiveColumn ( event . active . data . current . column ) ;
192+ console . log ( event . active . data . current . column )
172193 return ;
173194 }
174195
@@ -240,7 +261,18 @@ const Supervisor = ({ employeeDetails }) => {
240261 if ( isActiveATask && isOverAColumn ) {
241262 setTasks ( ( tasks ) => {
242263 const activeIndex = tasks . findIndex ( ( t ) => t . id === activeId ) ;
264+ console . log ( tasks [ activeIndex ] )
265+ const { _id } = tasks [ activeIndex ]
266+
267+ const data = {
268+ columnId : overId ,
269+ id : _id
270+ }
243271
272+ axios . post ( UpdateEmployeeColumnURL , data )
273+ . then ( ( res ) => console . log ( res . data ) )
274+ . catch ( e => console . log ( e ) )
275+
244276 tasks [ activeIndex ] . columnId = overId ;
245277 console . log ( "DROPPING TASK OVER COLUMN" , { activeIndex } ) ;
246278 return arrayMove ( tasks , activeIndex , activeIndex ) ;
0 commit comments