|
|
|
@ -9,7 +9,7 @@ import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
|
|
|
|
|
import { DownloadOutlined } from '@ant-design/icons'; |
|
|
|
|
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
|
|
|
|
import { PROJECT_TYPE_ADD, PROJECT_TYPE_EDIT, PROJECT_TYPE_DELETE, PROJECT_TYPE_SEARCH } from '../../../const/ApiConst'; |
|
|
|
|
import { Pagination, Button, Tooltip, Table} from 'antd'; |
|
|
|
|
import { Pagination, Button, Tooltip, Table } from 'antd'; |
|
|
|
|
|
|
|
|
|
const url = ""; |
|
|
|
|
const proyek_id = localStorage.getItem('proyek_id'); |
|
|
|
@ -17,361 +17,378 @@ const role_id = localStorage.getItem('role_id');
|
|
|
|
|
const format = "DD-MM-YYYY"; |
|
|
|
|
const token = window.localStorage.getItem('token'); |
|
|
|
|
const config = { |
|
|
|
|
headers: |
|
|
|
|
{ |
|
|
|
|
Authorization : `Bearer ${token}`, |
|
|
|
|
"Content-type" : `application/json` |
|
|
|
|
} |
|
|
|
|
headers: |
|
|
|
|
{ |
|
|
|
|
Authorization: `Bearer ${token}`, |
|
|
|
|
"Content-type": `application/json` |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const column = [ |
|
|
|
|
{ name: "Nama" }, |
|
|
|
|
{ name: "Deskripsi" }, |
|
|
|
|
{ name: "Nama" }, |
|
|
|
|
{ name: "Deskripsi" }, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
const ProjectType = ({params}) => { |
|
|
|
|
const token = localStorage.getItem("token") |
|
|
|
|
const HEADER = { |
|
|
|
|
headers: { |
|
|
|
|
"Content-Type": "application/json", |
|
|
|
|
"Authorization": `Bearer ${token}` |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const pageName = params.name; |
|
|
|
|
|
|
|
|
|
const [alertDelete, setAlertDelete] = useState(false) |
|
|
|
|
const [allDataMenu, setAllDataMenu] = useState([]) |
|
|
|
|
const [clickOpenModal, setClickOpenModal] = useState(false) |
|
|
|
|
const [currentPage, setCurrentPage] = useState(1) |
|
|
|
|
const [dataEdit, setDataEdit] = useState([]) |
|
|
|
|
const [dataExport, setDataExport] = useState([]) |
|
|
|
|
const [dataTable, setDatatable] = useState([]) |
|
|
|
|
const [idDelete, setIdDelete] = useState(0) |
|
|
|
|
const [idTypeProject, setIdTypeProject] = useState(0) |
|
|
|
|
const [openDialog, setOpenDialog] = useState(false) |
|
|
|
|
const [openDialogIG, setOpenDialogIG] = useState(false) |
|
|
|
|
const [rowsPerPage, setRowsPerPage] = useState(10) |
|
|
|
|
const [search, setSearch] = useState('') |
|
|
|
|
const [totalPage, setTotalPage] = useState(0) |
|
|
|
|
const [typeDialog, setTypeDialog] = useState('Save') |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getDataProjectType() |
|
|
|
|
}, [currentPage, rowsPerPage, search]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const cekData = dataExport || [] |
|
|
|
|
if (cekData.length > 0) { |
|
|
|
|
exportExcel() |
|
|
|
|
} |
|
|
|
|
}, [dataExport]) |
|
|
|
|
|
|
|
|
|
const getDataProjectType = async () => { |
|
|
|
|
|
|
|
|
|
let start = 0; |
|
|
|
|
|
|
|
|
|
if (currentPage !== 1 && currentPage > 1) { |
|
|
|
|
start = (currentPage * rowsPerPage) - rowsPerPage |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
"columns": [ |
|
|
|
|
{ |
|
|
|
|
"name":"name", |
|
|
|
|
"logic_operator":"like", |
|
|
|
|
"value":search, |
|
|
|
|
"operator":"AND" |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"orders": { |
|
|
|
|
"ascending": true, |
|
|
|
|
"columns": [ |
|
|
|
|
'id' |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"paging": { |
|
|
|
|
"length": rowsPerPage, |
|
|
|
|
"start": start |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
.post(PROJECT_TYPE_SEARCH, payload, config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if(result && result.data && result.data.code == 200){ |
|
|
|
|
setDatatable(result.data.data); |
|
|
|
|
setTotalPage(result.data.totalRecord); |
|
|
|
|
}else{ |
|
|
|
|
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleSearch = e => { |
|
|
|
|
const value = e.target.value |
|
|
|
|
setSearch(value); |
|
|
|
|
setCurrentPage(1) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const handleOpenDialog = (type) => { |
|
|
|
|
setOpenDialog(true) |
|
|
|
|
setTypeDialog(type) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleExportExcel = async () => { |
|
|
|
|
let start = 0; |
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
"paging": { "start": start, "length": -1 }, |
|
|
|
|
"columns": [ |
|
|
|
|
{ "name": "name", "logic_operator": "ilike", "value": search, "operator": "AND" } |
|
|
|
|
], |
|
|
|
|
"joins": [], |
|
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
.post(PROJECT_TYPE_SEARCH, payload) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
let resData = result.data.data; |
|
|
|
|
const excelData = []; |
|
|
|
|
resData.map((val, index) => { |
|
|
|
|
let dataRow = { |
|
|
|
|
"Nama": val.name, |
|
|
|
|
"Deskripsi": val.description, |
|
|
|
|
} |
|
|
|
|
excelData.push(dataRow) |
|
|
|
|
}) |
|
|
|
|
await setDataExport(excelData); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error('Gagal Export Data!!', 'Failed'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const exportExcel = () => { |
|
|
|
|
const dataExcel = dataExport || []; |
|
|
|
|
const fileName = `Data ${pageName}.xlsx`; |
|
|
|
|
const ws = XLSX.utils.json_to_sheet(dataExcel); |
|
|
|
|
const wb = XLSX.utils.book_new(); |
|
|
|
|
XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`); |
|
|
|
|
XLSX.writeFile(wb, fileName); |
|
|
|
|
setDataExport([]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleEdit = (data) => { |
|
|
|
|
setDataEdit(data) |
|
|
|
|
handleOpenDialog('Edit'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleDelete = async (id) => { |
|
|
|
|
await setAlertDelete(true) |
|
|
|
|
await setIdDelete(id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleCloseDialog = (type, data) => { |
|
|
|
|
if (type === "save") { |
|
|
|
|
saveProjectType(data); |
|
|
|
|
} else if (type === "edit") { |
|
|
|
|
editMaterialR(data); |
|
|
|
|
} |
|
|
|
|
setDataEdit([]) |
|
|
|
|
setOpenDialog(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const saveProjectType = async (data) => { |
|
|
|
|
const formData = data |
|
|
|
|
const result = await axios.post(PROJECT_TYPE_ADD, formData, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
|
getDataProjectType() |
|
|
|
|
NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error(`${result.data.message}`, 'Failed!!'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const editMaterialR = async (data) => { |
|
|
|
|
let urlEdit = PROJECT_TYPE_EDIT(data.id) |
|
|
|
|
const formData = data |
|
|
|
|
|
|
|
|
|
const result = await axios.put(urlEdit, formData, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
|
getDataProjectType(); |
|
|
|
|
NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const toggleAddDialog = () => { |
|
|
|
|
setOpenDialog(!openDialog) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleDialogIg = (id) => { |
|
|
|
|
setIdTypeProject(id) |
|
|
|
|
setOpenDialogIG(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const closeDialogIG = () => { |
|
|
|
|
setIdTypeProject(0) |
|
|
|
|
setOpenDialogIG(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const toggleDialogIG = () => { |
|
|
|
|
if(openDialogIG){ |
|
|
|
|
setIdTypeProject(0) |
|
|
|
|
} |
|
|
|
|
setOpenDialogIG(!openDialogIG); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onConfirmDelete = async () => { |
|
|
|
|
let url = PROJECT_TYPE_DELETE(idDelete); |
|
|
|
|
|
|
|
|
|
const result = await axios.delete(url,config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
|
getDataProjectType() |
|
|
|
|
setIdDelete(0) |
|
|
|
|
setAlertDelete(false) |
|
|
|
|
NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); |
|
|
|
|
} else { |
|
|
|
|
setIdDelete(0) |
|
|
|
|
setAlertDelete(false) |
|
|
|
|
NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const cancelDelete = () => { |
|
|
|
|
setAlertDelete(false) |
|
|
|
|
setIdDelete(0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onShowSizeChange = (current, pageSize) => { |
|
|
|
|
setRowsPerPage(pageSize) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onPagination = (current, pageSize) => { |
|
|
|
|
setCurrentPage(current) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const dataNotAvailable = () => { |
|
|
|
|
if(dataTable.length===0){ |
|
|
|
|
return ( |
|
|
|
|
<tr> |
|
|
|
|
<td align="center" colSpan="3">Tidak ada data project type</td> |
|
|
|
|
</tr> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const renderTable = useMemo(() => { |
|
|
|
|
const columns = [ |
|
|
|
|
{ |
|
|
|
|
title: 'Action', |
|
|
|
|
dataIndex: '', |
|
|
|
|
key: 'x', |
|
|
|
|
className:'nowrap', |
|
|
|
|
render: (text, record) => <> |
|
|
|
|
<Tooltip title="Delete"> |
|
|
|
|
<i className="fa fa-trash" style={{ color: 'red', marginRight: '10px', cursor: "pointer" }} onClick={() => handleDelete(text.id)}></i> |
|
|
|
|
</Tooltip> |
|
|
|
|
<Tooltip title="Edit"> |
|
|
|
|
<i className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(text)}></i> |
|
|
|
|
</Tooltip>{" "} |
|
|
|
|
<Tooltip title="Template Gantt"> |
|
|
|
|
<i className="fa fa-gears" style={{ color: 'blue', cursor: "pointer" }} onClick={() => handleDialogIg(text.id)}></i> |
|
|
|
|
</Tooltip> |
|
|
|
|
</>, |
|
|
|
|
}, |
|
|
|
|
{ title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, |
|
|
|
|
{ title: 'Description', dataIndex: 'description', key: 'description' }, |
|
|
|
|
]; |
|
|
|
|
return ( |
|
|
|
|
<Table |
|
|
|
|
rowKey="id" |
|
|
|
|
size="small" |
|
|
|
|
columns={columns} |
|
|
|
|
dataSource={dataTable} |
|
|
|
|
pagination={false} |
|
|
|
|
/> |
|
|
|
|
) |
|
|
|
|
}, [dataTable]) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div> |
|
|
|
|
<NotificationContainer /> |
|
|
|
|
<SweetAlert |
|
|
|
|
show={alertDelete} |
|
|
|
|
warning |
|
|
|
|
showCancel |
|
|
|
|
confirmBtnText="Delete" |
|
|
|
|
confirmBtnBsStyle="danger" |
|
|
|
|
title={`Are you sure?`} |
|
|
|
|
onConfirm={onConfirmDelete} |
|
|
|
|
onCancel={() => cancelDelete()} |
|
|
|
|
focusCancelBtn |
|
|
|
|
> |
|
|
|
|
Delete this data |
|
|
|
|
</SweetAlert> |
|
|
|
|
<DialogForm |
|
|
|
|
openDialog={openDialog} |
|
|
|
|
closeDialog={handleCloseDialog} |
|
|
|
|
toggleDialog={() => toggleAddDialog} |
|
|
|
|
typeDialog={typeDialog} |
|
|
|
|
dataEdit={dataEdit} |
|
|
|
|
clickOpenModal={clickOpenModal} |
|
|
|
|
dataParent={allDataMenu} |
|
|
|
|
/> |
|
|
|
|
<DialogInitialGantt |
|
|
|
|
openDialog={openDialogIG} |
|
|
|
|
closeDialog={closeDialogIG} |
|
|
|
|
toggleDialog={toggleDialogIG} |
|
|
|
|
idTypeProject={idTypeProject} |
|
|
|
|
/> |
|
|
|
|
<Card> |
|
|
|
|
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> |
|
|
|
|
<h4 className="capitalize">{pageName}</h4> |
|
|
|
|
<Row> |
|
|
|
|
<Col> |
|
|
|
|
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search project type...`} /> |
|
|
|
|
</Col> |
|
|
|
|
<Col> |
|
|
|
|
<Tooltip title="Add Material Resource"> |
|
|
|
|
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> |
|
|
|
|
</Tooltip> |
|
|
|
|
<Tooltip title="Export Excel"> |
|
|
|
|
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> |
|
|
|
|
</Tooltip> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
</CardHeader> |
|
|
|
|
<CardBody> |
|
|
|
|
{renderTable} |
|
|
|
|
<Pagination |
|
|
|
|
style={{marginTop:"25px"}} |
|
|
|
|
showSizeChanger |
|
|
|
|
onShowSizeChange={onShowSizeChange} |
|
|
|
|
onChange={onPagination} |
|
|
|
|
defaultCurrent={currentPage} |
|
|
|
|
pageSize={rowsPerPage} |
|
|
|
|
total={totalPage} |
|
|
|
|
pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]} |
|
|
|
|
/> |
|
|
|
|
</CardBody> |
|
|
|
|
</Card> |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|
const ProjectType = ({ params }) => { |
|
|
|
|
const token = localStorage.getItem("token") |
|
|
|
|
const HEADER = { |
|
|
|
|
headers: { |
|
|
|
|
"Content-Type": "application/json", |
|
|
|
|
"Authorization": `Bearer ${token}` |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const pageName = params.name; |
|
|
|
|
|
|
|
|
|
const [alertDelete, setAlertDelete] = useState(false) |
|
|
|
|
const [allDataMenu, setAllDataMenu] = useState([]) |
|
|
|
|
const [clickOpenModal, setClickOpenModal] = useState(false) |
|
|
|
|
const [currentPage, setCurrentPage] = useState(1) |
|
|
|
|
const [dataEdit, setDataEdit] = useState([]) |
|
|
|
|
const [dataExport, setDataExport] = useState([]) |
|
|
|
|
const [dataTable, setDatatable] = useState([]) |
|
|
|
|
const [idDelete, setIdDelete] = useState(0) |
|
|
|
|
const [idTypeProject, setIdTypeProject] = useState(0) |
|
|
|
|
const [openDialog, setOpenDialog] = useState(false) |
|
|
|
|
const [openDialogIG, setOpenDialogIG] = useState(false) |
|
|
|
|
const [rowsPerPage, setRowsPerPage] = useState(10) |
|
|
|
|
const [search, setSearch] = useState('') |
|
|
|
|
const [totalPage, setTotalPage] = useState(0) |
|
|
|
|
const [typeDialog, setTypeDialog] = useState('Save') |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getDataProjectType() |
|
|
|
|
}, [currentPage, rowsPerPage, search]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const cekData = dataExport || [] |
|
|
|
|
if (cekData.length > 0) { |
|
|
|
|
exportExcel() |
|
|
|
|
} |
|
|
|
|
}, [dataExport]) |
|
|
|
|
|
|
|
|
|
const getDataProjectType = async () => { |
|
|
|
|
|
|
|
|
|
let start = 0; |
|
|
|
|
|
|
|
|
|
if (currentPage !== 1 && currentPage > 1) { |
|
|
|
|
start = (currentPage * rowsPerPage) - rowsPerPage |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
"columns": [ |
|
|
|
|
{ |
|
|
|
|
"name": "name", |
|
|
|
|
"logic_operator": "like", |
|
|
|
|
"value": search, |
|
|
|
|
"operator": "AND" |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"orders": { |
|
|
|
|
"ascending": true, |
|
|
|
|
"columns": [ |
|
|
|
|
'id' |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"paging": { |
|
|
|
|
"length": rowsPerPage, |
|
|
|
|
"start": start |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
.post(PROJECT_TYPE_SEARCH, payload, config, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
setDatatable(result.data.data); |
|
|
|
|
setTotalPage(result.data.totalRecord); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleSearch = e => { |
|
|
|
|
const value = e.target.value |
|
|
|
|
setSearch(value); |
|
|
|
|
setCurrentPage(1) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const handleOpenDialog = (type) => { |
|
|
|
|
setOpenDialog(true) |
|
|
|
|
setTypeDialog(type) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleExportExcel = async () => { |
|
|
|
|
let start = 0; |
|
|
|
|
|
|
|
|
|
if (currentPage !== 1 && currentPage > 1) { |
|
|
|
|
start = (currentPage * rowsPerPage) - rowsPerPage |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
"columns": [ |
|
|
|
|
{ |
|
|
|
|
"name": "name", |
|
|
|
|
"logic_operator": "like", |
|
|
|
|
"value": search, |
|
|
|
|
"operator": "AND" |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"orders": { |
|
|
|
|
"ascending": true, |
|
|
|
|
"columns": [ |
|
|
|
|
'id' |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"paging": { |
|
|
|
|
"length": rowsPerPage, |
|
|
|
|
"start": start |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
.post(PROJECT_TYPE_SEARCH, payload, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
let resData = result.data.data; |
|
|
|
|
const excelData = []; |
|
|
|
|
resData.map((val, index) => { |
|
|
|
|
let dataRow = { |
|
|
|
|
"Nama": val.name, |
|
|
|
|
"Deskripsi": val.description, |
|
|
|
|
} |
|
|
|
|
excelData.push(dataRow) |
|
|
|
|
}) |
|
|
|
|
await setDataExport(excelData); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error('Gagal Export Data!!', 'Failed'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const exportExcel = () => { |
|
|
|
|
const dataExcel = dataExport || []; |
|
|
|
|
const fileName = `Data ${pageName}.xlsx`; |
|
|
|
|
const ws = XLSX.utils.json_to_sheet(dataExcel); |
|
|
|
|
const wb = XLSX.utils.book_new(); |
|
|
|
|
XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`); |
|
|
|
|
XLSX.writeFile(wb, fileName); |
|
|
|
|
setDataExport([]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleEdit = (data) => { |
|
|
|
|
setDataEdit(data) |
|
|
|
|
handleOpenDialog('Edit'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleDelete = async (id) => { |
|
|
|
|
await setAlertDelete(true) |
|
|
|
|
await setIdDelete(id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleCloseDialog = (type, data) => { |
|
|
|
|
if (type === "save") { |
|
|
|
|
saveProjectType(data); |
|
|
|
|
} else if (type === "edit") { |
|
|
|
|
editMaterialR(data); |
|
|
|
|
} |
|
|
|
|
setDataEdit([]) |
|
|
|
|
setOpenDialog(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const saveProjectType = async (data) => { |
|
|
|
|
const formData = data |
|
|
|
|
const result = await axios.post(PROJECT_TYPE_ADD, formData, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
|
getDataProjectType() |
|
|
|
|
NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!'); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error(`${result.data.message}`, 'Failed!!'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const editMaterialR = async (data) => { |
|
|
|
|
let urlEdit = PROJECT_TYPE_EDIT(data.id) |
|
|
|
|
const formData = data |
|
|
|
|
|
|
|
|
|
const result = await axios.put(urlEdit, formData, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
|
getDataProjectType(); |
|
|
|
|
NotificationManager.success(`Data project type berhasil diedit`, 'Success!!'); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error(`Data project type gagal di edit`, `Failed!!`); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const toggleAddDialog = () => { |
|
|
|
|
setOpenDialog(!openDialog) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleDialogIg = (id) => { |
|
|
|
|
setIdTypeProject(id) |
|
|
|
|
setOpenDialogIG(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const closeDialogIG = () => { |
|
|
|
|
setIdTypeProject(0) |
|
|
|
|
setOpenDialogIG(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const toggleDialogIG = () => { |
|
|
|
|
if (openDialogIG) { |
|
|
|
|
setIdTypeProject(0) |
|
|
|
|
} |
|
|
|
|
setOpenDialogIG(!openDialogIG); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onConfirmDelete = async () => { |
|
|
|
|
let url = PROJECT_TYPE_DELETE(idDelete); |
|
|
|
|
|
|
|
|
|
const result = await axios.delete(url, config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
|
getDataProjectType() |
|
|
|
|
setIdDelete(0) |
|
|
|
|
setAlertDelete(false) |
|
|
|
|
NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!'); |
|
|
|
|
} else { |
|
|
|
|
setIdDelete(0) |
|
|
|
|
setAlertDelete(false) |
|
|
|
|
NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const cancelDelete = () => { |
|
|
|
|
setAlertDelete(false) |
|
|
|
|
setIdDelete(0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onShowSizeChange = (current, pageSize) => { |
|
|
|
|
setRowsPerPage(pageSize) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onPagination = (current, pageSize) => { |
|
|
|
|
setCurrentPage(current) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const dataNotAvailable = () => { |
|
|
|
|
if (dataTable.length === 0) { |
|
|
|
|
return ( |
|
|
|
|
<tr> |
|
|
|
|
<td align="center" colSpan="3">Tidak ada data project type</td> |
|
|
|
|
</tr> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const renderTable = useMemo(() => { |
|
|
|
|
const columns = [ |
|
|
|
|
{ |
|
|
|
|
title: 'Action', |
|
|
|
|
dataIndex: '', |
|
|
|
|
key: 'x', |
|
|
|
|
className: 'nowrap', |
|
|
|
|
render: (text, record) => <> |
|
|
|
|
<Tooltip title="Delete"> |
|
|
|
|
<i className="fa fa-trash" style={{ color: 'red', marginRight: '10px', cursor: "pointer" }} onClick={() => handleDelete(text.id)}></i> |
|
|
|
|
</Tooltip> |
|
|
|
|
<Tooltip title="Edit"> |
|
|
|
|
<i className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(text)}></i> |
|
|
|
|
</Tooltip>{" "} |
|
|
|
|
<Tooltip title="Template Gantt"> |
|
|
|
|
<i className="fa fa-gears" style={{ color: 'blue', cursor: "pointer" }} onClick={() => handleDialogIg(text.id)}></i> |
|
|
|
|
</Tooltip> |
|
|
|
|
</>, |
|
|
|
|
}, |
|
|
|
|
{ title: 'Nama Role', dataIndex: 'name', key: 'name', className: "nowrap" }, |
|
|
|
|
{ title: 'Description', dataIndex: 'description', key: 'description' }, |
|
|
|
|
]; |
|
|
|
|
return ( |
|
|
|
|
<Table |
|
|
|
|
rowKey="id" |
|
|
|
|
size="small" |
|
|
|
|
columns={columns} |
|
|
|
|
dataSource={dataTable} |
|
|
|
|
pagination={false} |
|
|
|
|
/> |
|
|
|
|
) |
|
|
|
|
}, [dataTable]) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div> |
|
|
|
|
<NotificationContainer /> |
|
|
|
|
<SweetAlert |
|
|
|
|
show={alertDelete} |
|
|
|
|
warning |
|
|
|
|
showCancel |
|
|
|
|
confirmBtnText="Delete" |
|
|
|
|
confirmBtnBsStyle="danger" |
|
|
|
|
title={`Are you sure?`} |
|
|
|
|
onConfirm={onConfirmDelete} |
|
|
|
|
onCancel={() => cancelDelete()} |
|
|
|
|
focusCancelBtn |
|
|
|
|
> |
|
|
|
|
Delete this data |
|
|
|
|
</SweetAlert> |
|
|
|
|
<DialogForm |
|
|
|
|
openDialog={openDialog} |
|
|
|
|
closeDialog={handleCloseDialog} |
|
|
|
|
toggleDialog={() => toggleAddDialog} |
|
|
|
|
typeDialog={typeDialog} |
|
|
|
|
dataEdit={dataEdit} |
|
|
|
|
clickOpenModal={clickOpenModal} |
|
|
|
|
dataParent={allDataMenu} |
|
|
|
|
/> |
|
|
|
|
<DialogInitialGantt |
|
|
|
|
openDialog={openDialogIG} |
|
|
|
|
closeDialog={closeDialogIG} |
|
|
|
|
toggleDialog={toggleDialogIG} |
|
|
|
|
idTypeProject={idTypeProject} |
|
|
|
|
/> |
|
|
|
|
<Card> |
|
|
|
|
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> |
|
|
|
|
<h4 className="capitalize">{pageName}</h4> |
|
|
|
|
<Row> |
|
|
|
|
<Col> |
|
|
|
|
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search project type...`} /> |
|
|
|
|
</Col> |
|
|
|
|
<Col> |
|
|
|
|
<Tooltip title="Add Material Resource"> |
|
|
|
|
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> |
|
|
|
|
</Tooltip> |
|
|
|
|
<Tooltip title="Export Excel"> |
|
|
|
|
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> |
|
|
|
|
</Tooltip> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
</CardHeader> |
|
|
|
|
<CardBody> |
|
|
|
|
{renderTable} |
|
|
|
|
<Pagination |
|
|
|
|
style={{ marginTop: "25px" }} |
|
|
|
|
showSizeChanger |
|
|
|
|
onShowSizeChange={onShowSizeChange} |
|
|
|
|
onChange={onPagination} |
|
|
|
|
defaultCurrent={currentPage} |
|
|
|
|
pageSize={rowsPerPage} |
|
|
|
|
total={totalPage} |
|
|
|
|
pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]} |
|
|
|
|
/> |
|
|
|
|
</CardBody> |
|
|
|
|
</Card> |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default ProjectType; |
|
|
|
|