@ -4,7 +4,7 @@ import { Button, Form } from 'reactstrap';
import { Table , Tooltip } from 'antd' ;
import { Table , Tooltip } from 'antd' ;
import 'antd/dist/antd.css' ;
import 'antd/dist/antd.css' ;
import moment from 'moment' ;
import moment from 'moment' ;
import { ASSIGN _HR _PROJECT _SEARCH , ASSIGN _HR _PROJECT _DELETE , USER _LIST , PROJECT _ROLE _SEARCH , ASSIGN _HR _PROJECT _ADD , ASSIGN _HR _PROJECT _EDIT } from '../../../const/ApiConst' ;
import { API _ADW , TOKEN _ADW , A SSIGN _HR _PROJECT _SEARCH , ASSIGN _HR _PROJECT _DELETE , USER _LIST , PROJECT _ROLE _SEARCH , ASSIGN _HR _PROJECT _ADD , ASSIGN _HR _PROJECT _EDIT } from '../../../const/ApiConst' ;
import axios from "../../../const/interceptorApi"
import axios from "../../../const/interceptorApi"
import { NotificationContainer , NotificationManager } from 'react-notifications' ;
import { NotificationContainer , NotificationManager } from 'react-notifications' ;
import SweetAlert from 'react-bootstrap-sweetalert' ;
import SweetAlert from 'react-bootstrap-sweetalert' ;
@ -12,286 +12,290 @@ import FormAsignHr from './FormAsignHr';
import { formatThousand } from '../../../const/CustomFunc' ;
import { formatThousand } from '../../../const/CustomFunc' ;
const AssignHrProject = ( { openDialog , closeDialog , toggleDialog , idTask , toolsResource , proyekName } ) => {
const AssignHrProject = ( { openDialog , closeDialog , toggleDialog , idTask , toolsResource , proyekName } ) => {
const token = localStorage . getItem ( "token" )
const token = localStorage . getItem ( "token" )
const HEADER = {
const HEADER = {
headers : {
headers : {
"Content-Type" : "application/json" ,
"Content-Type" : "application/json" ,
"Authorization" : ` Bearer ${ token } `
"Authorization" : ` Bearer ${ token } `
}
}
}
}
const [ dataUserToProject , setdataUserToProject ] = useState ( [ ] )
const [ dataUserToProject , setdataUserToProject ] = useState ( [ ] )
const [ alertDelete , setAlertDelete ] = useState ( false )
const [ alertDelete , setAlertDelete ] = useState ( false )
const [ idDelete , setIdDelete ] = useState ( 0 )
const [ idDelete , setIdDelete ] = useState ( 0 )
const [ openDialogFormTools , setOpenDialogFormTools ] = useState ( false )
const [ openDialogFormTools , setOpenDialogFormTools ] = useState ( false )
const [ dataEdit , setDataEdit ] = useState ( null )
const [ dataEdit , setDataEdit ] = useState ( null )
const [ listUser , setListUser ] = useState ( [ ] )
const [ listUser , setListUser ] = useState ( [ ] )
const [ listRole , setListRole ] = useState ( [ ] )
const [ listRole , setListRole ] = useState ( [ ] )
useEffect ( ( ) => {
useEffect ( ( ) => {
if ( idTask > 0 ) {
if ( idTask > 0 ) {
getDataAssignHr ( ) ;
getDataAssignHr ( ) ;
}
}
} , [ openDialog ] ) ;
} , [ openDialog ] ) ;
useEffect ( ( ) => {
useEffect ( ( ) => {
getDataUser ( ) ;
getDataUser ( ) ;
getDataProjectRole ( ) ;
getDataProjectRole ( ) ;
} , [ ] )
} , [ ] )
const getDataAssignHr = async ( ) => {
const getDataAssignHr = async ( ) => {
const payload = {
const payload = {
"paging" : {
"paging" : {
"start" : 0 ,
"start" : 0 ,
"length" : - 1
"length" : - 1
} ,
} ,
"columns" : [
"columns" : [
{ "name" : "name" , "logic_operator" : "ilike" , "value" : "" , "table_name" : "m_users" } ,
{ "name" : "name" , "logic_operator" : "ilike" , "value" : "" , "table_name" : "m_users" } ,
{ "name" : "proyek_id" , "logic_operator" : "=" , "value" : idTask }
{ "name" : "proyek_id" , "logic_operator" : "=" , "value" : idTask }
] ,
] ,
"joins" : [
"joins" : [
{ "name" : "m_users" , "column_join" : "user_id" , "column_results" : [ "name" ] } ,
{ "name" : "m_users" , "column_join" : "user_id" , "column_results" : [ "name" ] } ,
{ "name" : "m_role_proyek" , "column_join" : "project_role" , "column_results" : [ "name" ] } ,
{ "name" : "m_role_proyek" , "column_join" : "project_role" , "column_results" : [ "name" ] } ,
] ,
] ,
"orders" : {
"orders" : {
"columns" : [
"columns" : [
"id"
"id"
] ,
] ,
"ascending" : false
"ascending" : false
}
}
}
}
const URL = ASSIGN _HR _PROJECT _SEARCH
const URL = ASSIGN _HR _PROJECT _SEARCH
const result = await axios
const result = await axios
. post ( URL , payload , HEADER )
. post ( URL , payload , HEADER )
. then ( res => res )
. then ( res => res )
. catch ( ( error ) => error . response ) ;
. catch ( ( error ) => error . response ) ;
if ( result && result . data && result . data . code == 200 ) {
if ( result && result . data && result . data . code == 200 ) {
let dataRes = result . data . data || [ ]
let dataRes = result . data . data || [ ]
setdataUserToProject ( dataRes ) ;
setdataUserToProject ( dataRes ) ;
} else {
} else {
NotificationManager . error ( 'Gagal Mengambil Data!!' , 'Failed' ) ;
NotificationManager . error ( 'Gagal Mengambil Data!!' , 'Failed' ) ;
}
}
}
}
const getDataUser = async ( ) => {
const getDataUser = async ( ) => {
const result = await axios
const HEADER _ADW = {
. get ( USER _LIST , HEADER )
headers : {
. then ( res => res )
"Authorization" : ` ${ TOKEN _ADW } `
. catch ( ( error ) => error . response ) ;
}
}
if ( result && result . data && result . data . code == 200 ) {
const result = await axios
let dataRes = result . data . data
. get ( ` ${ API _ADW } employees ` , HEADER _ADW )
setListUser ( dataRes )
// .get(USER_LIST, HEADER)
} else {
. then ( res => res )
}
. catch ( ( error ) => error . response ) ;
}
if ( result && result . data && result . data . data . length != 0 ) {
let dataRes = result . data . data
const getDataProjectRole = async ( ) => {
setListUser ( dataRes )
const payload = {
}
"paging" : {
}
"start" : 0 ,
"length" : - 1
const getDataProjectRole = async ( ) => {
} ,
const payload = {
"columns" : [
"paging" : {
{ "name" : "created_by" , "logic_operator" : "ilike" , "value" : "" } ,
"start" : 0 ,
] ,
"length" : - 1
"joins" : [ ] ,
} ,
"orders" : {
"columns" : [
"columns" : [
{ "name" : "created_by" , "logic_operator" : "ilike" , "value" : "" } ,
"id"
] ,
] ,
"joins" : [ ] ,
"ascending" : false
"orders" : {
}
"columns" : [
}
"id"
] ,
const result = await axios
"ascending" : false
. post ( PROJECT _ROLE _SEARCH , payload , HEADER )
}
. then ( res => res )
}
. catch ( ( error ) => error . response ) ;
const result = await axios
if ( result && result . data && result . data . code == 200 ) {
. post ( PROJECT _ROLE _SEARCH , payload , HEADER )
let dataRes = result . data . data || [ ]
. then ( res => res )
setListRole ( dataRes ) ;
. catch ( ( error ) => error . response ) ;
} else {
}
if ( result && result . data && result . data . code == 200 ) {
}
let dataRes = result . data . data || [ ]
setListRole ( dataRes ) ;
const handleDelete = ( id ) => {
} else {
setIdDelete ( id )
}
setAlertDelete ( true )
}
}
const handleDelete = ( id ) => {
const cancelDelete = ( ) => {
setIdDelete ( id )
setAlertDelete ( false )
setAlertDelete ( true )
setIdDelete ( 0 )
}
}
const cancelDelete = ( ) => {
const onConfirmDelete = async ( ) => {
setAlertDelete ( false )
let urlDel = ASSIGN _HR _PROJECT _DELETE ( idDelete )
setIdDelete ( 0 )
const result = await axios . delete ( urlDel , HEADER )
}
. then ( res => res )
. catch ( ( error ) => error . response ) ;
const onConfirmDelete = async ( ) => {
let urlDel = ASSIGN _HR _PROJECT _DELETE ( idDelete )
if ( result && result . data && result . data . code === 200 ) {
const result = await axios . delete ( urlDel , HEADER )
getDataAssignHr ( )
. then ( res => res )
setIdDelete ( 0 )
. catch ( ( error ) => error . response ) ;
setAlertDelete ( false )
NotificationManager . success ( ` Data assign human resource berhasil dihapus ` , 'Success!!' ) ;
if ( result && result . data && result . data . code === 200 ) {
} else {
getDataAssignHr ( )
setIdDelete ( 0 )
setIdDelete ( 0 )
setAlertDelete ( false )
setAlertDelete ( false )
NotificationManager . error ( ` Data assign human resource gagal dihapus ` , 'Failed!!' ) ;
NotificationManager . success ( ` Data assign human resource berhasil dihapus ` , 'Success!!' ) ;
}
} else {
}
setIdDelete ( 0 )
setAlertDelete ( false )
const handleEdit = async ( data ) => {
NotificationManager . error ( ` Data assign human resource gagal dihapus ` , 'Failed!!' ) ;
await setDataEdit ( data )
}
setOpenDialogFormTools ( true )
}
}
const handleEdit = async ( data ) => {
const handleOpenDialogFormTools = ( ) => {
await setDataEdit ( data )
setOpenDialogFormTools ( true )
setOpenDialogFormTools ( true )
}
}
const handleCancel = ( ) => {
const handleOpenDialogFormTools = ( ) => {
closeDialog ( 'cancel' , 'none' )
setOpenDialogFormTools ( true )
}
}
const handleCancel = ( ) => {
const RenderTable = useMemo ( ( ) => {
closeDialog ( 'cancel' , 'none' )
const columns = [
}
{
title : 'Action' ,
dataIndex : '' ,
const RenderTable = useMemo ( ( ) => {
key : 'x' ,
const columns = [
className : "nowrap" ,
{
render : ( text , record ) => < > < Tooltip title = "Delete Request Resource" >
title : 'Action' ,
< Button size = { "sm" } color = 'danger' onClick = { ( ) => handleDelete ( text . id ) } > < i className = "fa fa-trash" > < / i > < / B u t t o n >
dataIndex : '' ,
< / T o o l t i p > { " " } < T o o l t i p t i t l e = " E d i t R e q u e s t R e s o u r c e " >
key : 'x' ,
< Button size = { "sm" } color = 'primary' onClick = { ( ) => handleEdit ( text ) } > < i className = "fa fa-edit" > < / i > < / B u t t o n >
className : "nowrap" ,
< /Tooltip></ > ,
render : ( text , record ) => < > < Tooltip title = "Delete Request Resource" >
} ,
< Button size = { "sm" } color = 'danger' onClick = { ( ) => handleDelete ( text . id ) } > < i className = "fa fa-trash" > < / i > < / B u t t o n >
{ title : 'Name Human Resource' , dataIndex : 'join_first_name' , key : 'join_first_name' , className : "nowrap" } ,
< / T o o l t i p > { " " } < T o o l t i p t i t l e = " E d i t R e q u e s t R e s o u r c e " >
{ title : 'Role Human Resource' , dataIndex : 'join_second_name' , key : 'join_second_name' , className : "nowrap" } ,
< Button size = { "sm" } color = 'primary' onClick = { ( ) => handleEdit ( text ) } > < i className = "fa fa-edit" > < / i > < / B u t t o n >
{ title : 'Percentage Available User' , dataIndex : 'max_used' , key : 'max_used' , className : "nowrap" , render : ( text , record ) => record . max _used ? formatThousand ( record . max _used ) : '-' } ,
< /Tooltip></ > ,
{ title : 'Standard Rate' , dataIndex : 'standart_rate' , key : 'standart_rate' , className : "nowrap" , render : ( text , record ) => record . standart _rate ? formatThousand ( record . standart _rate ) : '-' } ,
} ,
{ title : 'UOM Standard Rate' , dataIndex : 'uom_standart_rate' , key : 'uom_standart_rate' , className : "nowrap" } ,
{ title : 'Name Human Resource' , dataIndex : 'join_first_name' , key : 'join_first_name' , className : "nowrap" } ,
{ title : 'Overtime Rate' , dataIndex : 'overtime_rate' , key : 'overtime_rate' , className : "nowrap" , render : ( text , record ) => record . overtime _rate ? formatThousand ( record . overtime _rate ) : '-' } ,
{ title : 'Role Human Resource' , dataIndex : 'join_second_name' , key : 'join_second_name' , className : "nowrap" } ,
{ title : 'UOM Overtime Rate' , dataIndex : 'uom_overtime_rate' , key : 'uom_overtime_rate' , className : "nowrap" } ,
{ title : 'Percentage Available User' , dataIndex : 'max_used' , key : 'max_used' , className : "nowrap" , render : ( text , record ) => record . max _used ? formatThousand ( record . max _used ) : '-' } ,
{ title : 'Standard Rate' , dataIndex : 'standart_rate' , key : 'standart_rate' , className : "nowrap" , render : ( text , record ) => record . standart _rate ? formatThousand ( record . standart _rate ) : '-' } ,
] ;
{ title : 'UOM Standard Rate' , dataIndex : 'uom_standart_rate' , key : 'uom_standart_rate' , className : "nowrap" } ,
{ title : 'Overtime Rate' , dataIndex : 'overtime_rate' , key : 'overtime_rate' , className : "nowrap" , render : ( text , record ) => record . overtime _rate ? formatThousand ( record . overtime _rate ) : '-' } ,
return (
{ title : 'UOM Overtime Rate' , dataIndex : 'uom_overtime_rate' , key : 'uom_overtime_rate' , className : "nowrap" } ,
< Table
size = "small"
] ;
columns = { columns }
dataSource = { dataUserToProject }
return (
pagination = { { position : [ "bottomLeft" ] } }
< Table
/ >
size = "small"
)
columns = { columns }
} , [ dataUserToProject ] )
dataSource = { dataUserToProject }
pagination = { { position : [ "bottomLeft" ] } }
const renderForm = ( ) => {
/ >
return (
)
< div style = { { "overflowX" : "scroll" } } >
} , [ dataUserToProject ] )
{ RenderTable }
< / d i v >
const renderForm = ( ) => {
)
return (
}
< div style = { { "overflowX" : "scroll" } } >
{ RenderTable }
const handleCloseDialogFormTools = ( type , data ) => {
< / d i v >
if ( type == "add" ) {
)
addDataAssignHr ( data ) ;
}
} else if ( type == "edit" ) {
editDataAssignHr ( data ) ;
const handleCloseDialogFormTools = ( type , data ) => {
} else {
if ( type == "add" ) {
setDataEdit ( null )
addDataAssignHr ( data ) ;
setOpenDialogFormTools ( false )
} else if ( type == "edit" ) {
}
editDataAssignHr ( data ) ;
}
} else {
setDataEdit ( null )
const addDataAssignHr = async ( payload ) => {
setOpenDialogFormTools ( false )
const result = await axios
}
. post ( ASSIGN _HR _PROJECT _ADD , payload , HEADER )
}
. then ( res => res )
. catch ( ( error ) => error . response ) ;
const addDataAssignHr = async ( payload ) => {
const result = await axios
if ( result && result . data && result . data . code == 200 ) {
. post ( ASSIGN _HR _PROJECT _ADD , payload , HEADER )
getDataAssignHr ( ) ;
. then ( res => res )
NotificationManager . success ( 'assign human resource berhasil!!' , 'Success' ) ;
. catch ( ( error ) => error . response ) ;
setDataEdit ( null )
setOpenDialogFormTools ( false )
if ( result && result . data && result . data . code == 200 ) {
} else {
getDataAssignHr ( ) ;
NotificationManager . error ( 'assign human resource gagal!!' , 'Failed' ) ;
NotificationManager . success ( 'assign human resource berhasil!!' , 'Success' ) ;
}
setDataEdit ( null )
}
setOpenDialogFormTools ( false )
} else {
const editDataAssignHr = async ( payload ) => {
NotificationManager . error ( 'assign human resource gagal!!' , 'Failed' ) ;
let url = ASSIGN _HR _PROJECT _EDIT ( payload . id )
}
const result = await axios
}
. put ( url , payload , HEADER )
. then ( res => res )
const editDataAssignHr = async ( payload ) => {
. catch ( ( error ) => error . response ) ;
let url = ASSIGN _HR _PROJECT _EDIT ( payload . id )
const result = await axios
if ( result && result . data && result . data . code == 200 ) {
. put ( url , payload , HEADER )
getDataAssignHr ( ) ;
. then ( res => res )
NotificationManager . success ( 'assign human resource berhasil diedit!!' , 'Success' ) ;
. catch ( ( error ) => error . response ) ;
setDataEdit ( null )
setOpenDialogFormTools ( false )
if ( result && result . data && result . data . code == 200 ) {
} else {
getDataAssignHr ( ) ;
NotificationManager . error ( 'assign human resource gagal diedit!!' , 'Failed' ) ;
NotificationManager . success ( 'assign human resource berhasil diedit!!' , 'Success' ) ;
}
setDataEdit ( null )
}
setOpenDialogFormTools ( false )
} else {
const toogleDialogFormTools = ( ) => {
NotificationManager . error ( 'assign human resource gagal diedit!!' , 'Failed' ) ;
if ( openDialogFormTools ) {
}
setDataEdit ( null )
}
}
setOpenDialogFormTools ( ! openDialogFormTools )
const toogleDialogFormTools = ( ) => {
}
if ( openDialogFormTools ) {
setDataEdit ( null )
}
return (
setOpenDialogFormTools ( ! openDialogFormTools )
< >
}
< NotificationContainer / >
< SweetAlert
show = { alertDelete }
return (
warning
< >
showCancel
< NotificationContainer / >
confirmBtnText = "Delete"
< SweetAlert
confirmBtnBsStyle = "danger"
show = { alertDelete }
title = { ` Are you sure? ` }
warning
onConfirm = { onConfirmDelete }
showCancel
onCancel = { ( ) => cancelDelete ( ) }
confirmBtnText = "Delete"
focusCancelBtn
confirmBtnBsStyle = "danger"
>
title = { ` Are you sure? ` }
Delete this data
onConfirm = { onConfirmDelete }
< / S w e e t A l e r t >
onCancel = { ( ) => cancelDelete ( ) }
< Modal size = "xl" isOpen = { openDialog } toggle = { toggleDialog } >
focusCancelBtn
< ModalHeader className = "capitalize withBtn" toggle = { closeDialog } >
>
Delete this data
< div > Assign Human Resource - { proyekName } < /div> <Button onClick={handleOpenDialogFormTools} size='sm' color="primary"><i className='fa fa-plus'></i > < / B u t t o n >
< / S w e e t A l e r t >
< / M o d a l H e a d e r >
< Modal size = "xl" isOpen = { openDialog } toggle = { toggleDialog } >
< ModalBody >
< ModalHeader className = "capitalize withBtn" toggle = { closeDialog } >
{ renderForm ( ) }
< / M o d a l B o d y >
< div > Assign Human Resource - { proyekName } < /div> <Button onClick={handleOpenDialogFormTools} size='sm' color="primary"><i className='fa fa-plus'></i > < / B u t t o n >
{ / * < M o d a l F o o t e r >
< / M o d a l H e a d e r >
< Button className = "capitalize" color = "secondary" onClick = { ( ) => handleCancel ( ) } > Close < / B u t t o n >
< ModalBody >
< /ModalFooter> */ }
{ renderForm ( ) }
< / M o d a l >
< / M o d a l B o d y >
< FormAsignHr
{ / * < M o d a l F o o t e r >
openDialog = { openDialogFormTools }
< Button className = "capitalize" color = "secondary" onClick = { ( ) => handleCancel ( ) } > Close < / B u t t o n >
closeDialog = { handleCloseDialogFormTools }
< /ModalFooter> */ }
toggleDialog = { toogleDialogFormTools }
< / M o d a l >
idTask = { idTask }
< FormAsignHr
dataEdit = { dataEdit }
openDialog = { openDialogFormTools }
dataHr = { listUser }
closeDialog = { handleCloseDialogFormTools }
dataRole = { listRole }
toggleDialog = { toogleDialogFormTools }
dataCurrentHr = { dataUserToProject }
idTask = { idTask }
/ >
dataEdit = { dataEdit }
< / >
dataHr = { listUser }
)
dataRole = { listRole }
dataCurrentHr = { dataUserToProject }
/ >
< / >
)
}
}