|
|
|
@ -54,14 +54,23 @@ const ProjectType = ({ params }) => {
|
|
|
|
|
const [typeDialog, setTypeDialog] = useState('Save') |
|
|
|
|
const [dataDivisions, setDataDivisions] = useState([]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getListDivision() |
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getDataProjectType() |
|
|
|
|
}, [currentPage, rowsPerPage, search]) |
|
|
|
|
|
|
|
|
|
const getDataProjectType = async () => { |
|
|
|
|
|
|
|
|
|
let start = 0; |
|
|
|
|
useEffect(() => { |
|
|
|
|
const cekData = dataExport || [] |
|
|
|
|
if (cekData.length > 0) { |
|
|
|
|
exportExcel() |
|
|
|
|
} |
|
|
|
|
}, [dataExport]) |
|
|
|
|
|
|
|
|
|
const getListDivision = async () => { |
|
|
|
|
const listDivions = await axios |
|
|
|
|
.get(DIVISI_LIST, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
@ -76,11 +85,12 @@ const ProjectType = ({ params }) => {
|
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
const getDataProjectType = async () => { |
|
|
|
|
let start = 0; |
|
|
|
|
if (currentPage !== 1 && currentPage > 1) { |
|
|
|
|
start = (currentPage * rowsPerPage) - rowsPerPage |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
"columns": [ |
|
|
|
|
{ |
|
|
|
@ -101,19 +111,78 @@ const ProjectType = ({ params }) => {
|
|
|
|
|
"start": start |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
.post(DIVISI_SEARCH, payload, config) |
|
|
|
|
.post(DIVISI_SEARCH, payload, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
result.data.data.map((res) => { |
|
|
|
|
res.key = res.id.toString() |
|
|
|
|
}); |
|
|
|
|
setDatatable(result.data.data); |
|
|
|
|
setTotalPage(result.data.totalRecord); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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(DIVISI_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 Divisi": 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 handleSearch = e => { |
|
|
|
|
const value = e.target.value |
|
|
|
@ -248,10 +317,16 @@ const ProjectType = ({ params }) => {
|
|
|
|
|
<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={`Cari Divisi`} /> |
|
|
|
|
</Col> |
|
|
|
|
<Col> |
|
|
|
|
<Tooltip title="Add Data"> |
|
|
|
|
<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> |
|
|
|
@ -280,7 +355,7 @@ const ProjectType = ({ params }) => {
|
|
|
|
|
<i id="TooltipEdit" className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i> |
|
|
|
|
</Tooltip> |
|
|
|
|
</td> |
|
|
|
|
<td>{n.displayName}</td> |
|
|
|
|
<td>{n.name}</td> |
|
|
|
|
<td>{n.description}</td> |
|
|
|
|
</tr> |
|
|
|
|
) |
|
|
|
|