Browse Source

update filter name

pull/1/head
farhantock 1 year ago
parent
commit
31fe46cbcb
  1. 79
      src/views/SimproV2/CreatedProyek/DialogUserGantt.js

79
src/views/SimproV2/CreatedProyek/DialogUserGantt.js

@ -2,11 +2,11 @@ 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_VERSION_GANTT_ADDS, USER_VERSION_GANTT_SEARCH, USER_LIST } from '../../../const/ApiConst';
import { Transfer } from 'antd'; import { Transfer, Spin } from 'antd';
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
const DialogUserGantt = ({ openDialog, closeDialog, toggleDialog, idGantt}) => { const DialogUserGantt = ({ openDialog, closeDialog, toggleDialog, idGantt }) => {
const token = localStorage.getItem("token") const token = localStorage.getItem("token")
const HEADER = { const HEADER = {
headers: { headers: {
@ -17,7 +17,7 @@ const DialogUserGantt = ({ openDialog, closeDialog, toggleDialog, idGantt}) => {
const [id, setId] = useState(0) const [id, setId] = useState(0)
const [targetKeys, setTargetKeys] = useState([]) const [targetKeys, setTargetKeys] = useState([])
const [humanResource, setHumanResource] = useState([]) const [humanResource, setHumanResource] = useState([])
const [loading, setLoading] = useState(true);
const handleCLearData = () => { const handleCLearData = () => {
setId(0) setId(0)
@ -25,16 +25,16 @@ const DialogUserGantt = ({ openDialog, closeDialog, toggleDialog, idGantt}) => {
} }
useEffect(() => { useEffect(() => {
if(!openDialog){ if (!openDialog) {
handleCLearData() handleCLearData()
} else { } else {
getDataHumanResource(); getDataHumanResource();
} }
}, [openDialog]) }, [openDialog])
useEffect(() => { useEffect(() => {
if(idGantt && idGantt > 0){ if (idGantt && idGantt > 0) {
getUserGantt() getUserGantt()
} }
}, [idGantt]) }, [idGantt])
@ -64,28 +64,30 @@ const DialogUserGantt = ({ openDialog, closeDialog, toggleDialog, idGantt}) => {
} }
const getUserGantt = async () => { const getUserGantt = async () => {
setLoading(true)
const payload = { const payload = {
"columns": [ "columns": [
{ "name": "version_gantt_id", "logic_operator": "=", "value": idGantt, "operator": "AND" } { "name": "version_gantt_id", "logic_operator": "=", "value": idGantt, "operator": "AND" }
] ]
} }
const result = await axios const result = await axios
.post(USER_VERSION_GANTT_SEARCH, payload, HEADER) .post(USER_VERSION_GANTT_SEARCH, payload, 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) {
console.log("cek resource get user gantt",result.data.data) console.log("cek resource get user gantt", result.data.data)
setUserGantt(result.data.data); setUserGantt(result.data.data);
}else{ setLoading(false)
} else {
} }
} }
const setUserGantt = (data) => { const setUserGantt = (data) => {
let newTargetKeys = [] let newTargetKeys = []
data.map((val,index)=> { data.map((val, index) => {
newTargetKeys.push(val.user_id) newTargetKeys.push(val.user_id)
}); });
setTargetKeys(newTargetKeys) setTargetKeys(newTargetKeys)
} }
@ -95,11 +97,11 @@ const DialogUserGantt = ({ openDialog, closeDialog, toggleDialog, idGantt}) => {
handleCLearData() handleCLearData()
} }
const saveVersionGantt= async () => { const saveVersionGantt = async () => {
const formData = { const formData = {
user_id:targetKeys, user_id: targetKeys,
version_gantt_id:idGantt version_gantt_id: idGantt
} }
const result = await axios const result = await axios
@ -108,9 +110,9 @@ const DialogUserGantt = ({ openDialog, closeDialog, toggleDialog, idGantt}) => {
.catch((error) => error.response); .catch((error) => error.response);
if(result && result.status==200){ if (result && result.status == 200) {
closeDialog('success') closeDialog('success')
}else{ } else {
closeDialog('failed') closeDialog('failed')
} }
} }
@ -133,17 +135,20 @@ const DialogUserGantt = ({ openDialog, closeDialog, toggleDialog, idGantt}) => {
paddingRight: 20, paddingRight: 20,
overflow: "auto" overflow: "auto"
}}> }}>
<Transfer <Transfer
showSearch showSearch
titles={['Available HR', 'Granted to']} filterOption={(inputValue, option) =>
dataSource={humanResource} option.title.toLowerCase().includes(inputValue.toLowerCase())
targetKeys={targetKeys} }
onChange={handleChange} titles={['Available HR', 'Granted to']}
render={item => item.title} dataSource={humanResource}
listStyle={{ targetKeys={targetKeys}
width: 250, onChange={handleChange}
height: 300, render={item => item.title}
}} listStyle={{
width: 250,
height: 300,
}}
/> />
</div> </div>
) )
@ -152,10 +157,12 @@ const DialogUserGantt = ({ openDialog, closeDialog, toggleDialog, idGantt}) => {
return ( return (
<> <>
<Modal size="lg" style={{maxWidth: '600px', width: '100%'}} isOpen={openDialog} toggle={toggleDialog}> <Modal size="lg" style={{ maxWidth: '600px', width: '100%' }} isOpen={openDialog} toggle={toggleDialog}>
<ModalHeader className="capitalize" toggle={closeDialog}>Gantt Permission</ModalHeader> <ModalHeader className="capitalize" toggle={closeDialog}>Gantt Permission</ModalHeader>
<ModalBody> <ModalBody>
{renderForm()} <Spin tip="Loading..." spinning={loading}>
{renderForm()}
</Spin>
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<Button color="primary" onClick={() => handleSave()}>Save</Button>{' '} <Button color="primary" onClick={() => handleSave()}>Save</Button>{' '}

Loading…
Cancel
Save