|
|
|
@ -2,12 +2,17 @@ import React, { useEffect, useState } from 'react'
|
|
|
|
|
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; |
|
|
|
|
import { Button, Form } from 'reactstrap'; |
|
|
|
|
import axios from "../../../const/interceptorApi"; |
|
|
|
|
import { USER_VERSION_GANTT_ADDS, USER_VERSION_GANTT_SEARCH, USER_LIST} from '../../../const/ApiConst'; |
|
|
|
|
import { |
|
|
|
|
USER_LIST, |
|
|
|
|
ASSIGN_HR_PROJECT_SEARCH, |
|
|
|
|
ASSIGN_HR_PROJECT_ADD_MULTIPLE |
|
|
|
|
} from '../../../const/ApiConst'; |
|
|
|
|
import { Transfer } from 'antd'; |
|
|
|
|
import 'antd/dist/antd.css'; |
|
|
|
|
import { NotificationManager } from 'react-notifications'; |
|
|
|
|
|
|
|
|
|
const role_id = localStorage.getItem('role_id'); |
|
|
|
|
const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idGantt}) => { |
|
|
|
|
const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idTask }) => { |
|
|
|
|
const token = localStorage.getItem("token") |
|
|
|
|
const HEADER = { |
|
|
|
|
headers: { |
|
|
|
@ -15,29 +20,24 @@ const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idGantt}) =>
|
|
|
|
|
"Authorization": `Bearer ${token}` |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const [id, setId] = useState(0) |
|
|
|
|
const [targetKeys, setTargetKeys] = useState([]) |
|
|
|
|
const [assignCustomer, setAssignCustomer] = useState([]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleCLearData = () => { |
|
|
|
|
setId(0) |
|
|
|
|
setTargetKeys([]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if(!openDialog){ |
|
|
|
|
handleCLearData() |
|
|
|
|
if (!openDialog) { |
|
|
|
|
handleCLearData(); |
|
|
|
|
closeDialog('add'); |
|
|
|
|
} else { |
|
|
|
|
getDataAssignCustomer(); |
|
|
|
|
getDataAssignCustomer(); |
|
|
|
|
getCustProject(); |
|
|
|
|
} |
|
|
|
|
}, [openDialog]) |
|
|
|
|
}, [openDialog]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if(idGantt && idGantt > 0){ |
|
|
|
|
getUserGantt() |
|
|
|
|
} |
|
|
|
|
}, [idGantt]) |
|
|
|
|
|
|
|
|
|
const getDataAssignCustomer = async () => { |
|
|
|
|
const result = await axios |
|
|
|
@ -49,8 +49,6 @@ const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idGantt}) =>
|
|
|
|
|
let dataRes = result.data.data; |
|
|
|
|
const filteredData = dataRes.filter(item => item.role_id === 44); |
|
|
|
|
setTransferUser(filteredData); |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -66,51 +64,23 @@ const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idGantt}) =>
|
|
|
|
|
setAssignCustomer(finalData) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getUserGantt = async () => { |
|
|
|
|
const payload = { |
|
|
|
|
"columns": [ |
|
|
|
|
{ "name": "version_gantt_id", "logic_operator": "=", "value": idGantt, "operator": "AND" } |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
const result = await axios |
|
|
|
|
.post(USER_VERSION_GANTT_SEARCH, payload, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if(result && result.status==200){ |
|
|
|
|
console.log("cek resource get user gantt",result.data.data) |
|
|
|
|
setUserGantt(result.data.data); |
|
|
|
|
}else{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const setUserGantt = (data) => { |
|
|
|
|
let newTargetKeys = [] |
|
|
|
|
data.map((val,index)=> { |
|
|
|
|
newTargetKeys.push(val.user_id) |
|
|
|
|
}); |
|
|
|
|
setTargetKeys(newTargetKeys) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleSave = async () => { |
|
|
|
|
await saveVersionGantt() |
|
|
|
|
await saveCustProject() |
|
|
|
|
handleCLearData() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const saveVersionGantt= async () => { |
|
|
|
|
const saveCustProject= async () => { |
|
|
|
|
|
|
|
|
|
const formData = { |
|
|
|
|
user_id:targetKeys, |
|
|
|
|
version_gantt_id:idGantt |
|
|
|
|
user_id: targetKeys, |
|
|
|
|
proyek_id: idTask |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
.post(USER_VERSION_GANTT_ADDS, formData, HEADER) |
|
|
|
|
.post(ASSIGN_HR_PROJECT_ADD_MULTIPLE, formData, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(result && result.status==200){ |
|
|
|
|
closeDialog('success') |
|
|
|
|
}else{ |
|
|
|
@ -120,13 +90,37 @@ const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idGantt}) =>
|
|
|
|
|
|
|
|
|
|
const handleCancel = () => { |
|
|
|
|
closeDialog('cancel') |
|
|
|
|
handleCLearData() |
|
|
|
|
handleCLearData(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleChange = targetKeys => { |
|
|
|
|
setTargetKeys(targetKeys) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const getCustProject = async () => { |
|
|
|
|
const payload = { |
|
|
|
|
"columns": [ |
|
|
|
|
{ "name": "proyek_id", "logic_operator": "=", "value": idTask }, |
|
|
|
|
{"name": "is_customer", "logic_operator": "=", "value": "true"} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
const result = await axios |
|
|
|
|
.post(ASSIGN_HR_PROJECT_SEARCH, payload, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if(result && result.status==200){ |
|
|
|
|
console.log("cek get assign HR is custumer",result.data.data) |
|
|
|
|
let data = result.data.data || [] |
|
|
|
|
let newTargetKeys = [] |
|
|
|
|
if (data.length > 0) { |
|
|
|
|
data.map((val,index)=> { |
|
|
|
|
newTargetKeys.push(val.user_id) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
setTargetKeys(newTargetKeys) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const renderForm = () => { |
|
|
|
|
return ( |
|
|
|
|
<div style={{ |
|
|
|
|