Browse Source

add asignCustomer in database

pull/2/head
wahyuun 1 year ago
parent
commit
5f778a2743
  1. 92
      src/views/SimproV2/CreatedProyek/DialogAssignCust.js

92
src/views/SimproV2/CreatedProyek/DialogAssignCust.js

@ -2,12 +2,17 @@ import React, { useEffect, useState } from 'react'
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { Button, Form } from 'reactstrap'; import { Button, Form } from 'reactstrap';
import axios from "../../../const/interceptorApi"; 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 { Transfer } from 'antd';
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
import { NotificationManager } from 'react-notifications';
const role_id = localStorage.getItem('role_id'); 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 token = localStorage.getItem("token")
const HEADER = { const HEADER = {
headers: { headers: {
@ -15,29 +20,24 @@ const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idGantt}) =>
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const [id, setId] = useState(0)
const [targetKeys, setTargetKeys] = useState([]) const [targetKeys, setTargetKeys] = useState([])
const [assignCustomer, setAssignCustomer] = useState([]) const [assignCustomer, setAssignCustomer] = useState([])
const handleCLearData = () => { const handleCLearData = () => {
setId(0)
setTargetKeys([]) setTargetKeys([])
} }
useEffect(() => { useEffect(() => {
if(!openDialog){ if (!openDialog) {
handleCLearData() handleCLearData();
closeDialog('add');
} else { } else {
getDataAssignCustomer(); getDataAssignCustomer();
getCustProject();
} }
}, [openDialog]) }, [openDialog]);
useEffect(() => {
if(idGantt && idGantt > 0){
getUserGantt()
}
}, [idGantt])
const getDataAssignCustomer = async () => { const getDataAssignCustomer = async () => {
const result = await axios const result = await axios
@ -49,8 +49,6 @@ const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idGantt}) =>
let dataRes = result.data.data; let dataRes = result.data.data;
const filteredData = dataRes.filter(item => item.role_id === 44); const filteredData = dataRes.filter(item => item.role_id === 44);
setTransferUser(filteredData); setTransferUser(filteredData);
} else {
} }
} }
@ -66,51 +64,23 @@ const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idGantt}) =>
setAssignCustomer(finalData) 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 () => { const handleSave = async () => {
await saveVersionGantt() await saveCustProject()
handleCLearData() handleCLearData()
} }
const saveVersionGantt= async () => { const saveCustProject= async () => {
const formData = { const formData = {
user_id:targetKeys, user_id: targetKeys,
version_gantt_id:idGantt proyek_id: idTask
} }
const result = await axios const result = await axios
.post(USER_VERSION_GANTT_ADDS, formData, HEADER) .post(ASSIGN_HR_PROJECT_ADD_MULTIPLE, formData, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if(result && result.status==200){ if(result && result.status==200){
closeDialog('success') closeDialog('success')
}else{ }else{
@ -120,13 +90,37 @@ const DialogAssignCust = ({ openDialog, closeDialog, toggleDialog, idGantt}) =>
const handleCancel = () => { const handleCancel = () => {
closeDialog('cancel') closeDialog('cancel')
handleCLearData() handleCLearData();
} }
const handleChange = targetKeys => { const handleChange = targetKeys => {
setTargetKeys(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 = () => { const renderForm = () => {
return ( return (
<div style={{ <div style={{

Loading…
Cancel
Save