Browse Source

implement hierarchy

pull/2/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
772edd1016
  1. 2
      src/views/SimproV2/Divisi/DialogForm.js
  2. 83
      src/views/SimproV2/Divisi/index.js

2
src/views/SimproV2/Divisi/DialogForm.js

@ -79,7 +79,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
filterOption={(input, option) => option.children.toLowerCase().includes(input.toLowerCase())}
>
{dataDivisions.map((res, idx) => (
<Option key={idx} value={idx}>{res}</Option>
<Option key={res['id']} value={res['id']}>{res['displayName']}</Option>
))}
</Select>
</FormGroup>

83
src/views/SimproV2/Divisi/index.js

@ -58,13 +58,6 @@ const ProjectType = ({ params }) => {
getDataProjectType()
}, [currentPage, rowsPerPage, search])
useEffect(() => {
const cekData = dataExport || []
if (cekData.length > 0) {
exportExcel()
}
}, [dataExport])
const getDataProjectType = async () => {
let start = 0;
@ -79,7 +72,6 @@ const ProjectType = ({ params }) => {
for (const v in listDivions.data.data) {
arr.push(listDivions.data.data[v])
}
console.log(arr);
setDataDivisions(arr);
} else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
@ -134,48 +126,6 @@ const ProjectType = ({ params }) => {
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(DIVISI_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');
@ -203,7 +153,7 @@ const ProjectType = ({ params }) => {
.catch((error) => error.response);
if (result && result.data && result.data.code === 200) {
getDataProjectType()
NotificationManager.success(`Data project type berhasil ditambah`, 'Success!!');
NotificationManager.success(`Data berhasil ditambah`, 'Success!!');
} else {
NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
@ -217,9 +167,9 @@ const ProjectType = ({ params }) => {
.catch((error) => error.response);
if (result && result.data && result.data.code === 200) {
getDataProjectType();
NotificationManager.success(`Data project type berhasil diedit`, 'Success!!');
NotificationManager.success(`Data berhasil diedit`, 'Success!!');
} else {
NotificationManager.error(`Data project type gagal di edit`, `Failed!!`);
NotificationManager.error(`Data gagal di edit`, `Failed!!`);
}
}
@ -237,11 +187,11 @@ const ProjectType = ({ params }) => {
getDataProjectType()
setIdDelete(0)
setAlertDelete(false)
NotificationManager.success(`Data project type berhasil dihapus!`, 'Success!!');
NotificationManager.success(`Data berhasil dihapus!`, 'Success!!');
} else {
setIdDelete(0)
setAlertDelete(false)
NotificationManager.error(`Data project type gagal dihapus!}`, 'Failed!!');
NotificationManager.error(`Data gagal dihapus!}`, 'Failed!!');
}
}
@ -262,7 +212,7 @@ const ProjectType = ({ params }) => {
if (dataTable.length === 0) {
return (
<tr>
<td align="center" colSpan="3">Tidak ada data project type</td>
<td align="center" colSpan="3">Belum ada data.</td>
</tr>
)
}
@ -299,15 +249,9 @@ const ProjectType = ({ params }) => {
<h4 className="capitalize">{pageName}</h4>
<Row>
<Col>
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Search`} />
</Col>
<Col>
<Tooltip title="Add Material Resource">
<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>
@ -329,31 +273,20 @@ const ProjectType = ({ params }) => {
return (
<tr key={n.id}>
<td className='nowrap'>
<Tooltip title="Hapus">
<i id="TooltipDelete" className="cil-trash fa-lg" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => handleDelete(n.id)}></i>
</Tooltip>
<Tooltip title="Edit">
<i id="TooltipEdit" className="cil-pencil fa-lg" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i>
</Tooltip>
</td>
<td>{n.name}</td>
<td>{n.displayName}</td>
<td>{n.description}</td>
</tr>
)
})}
</tbody>
</Table>
<Pagination
showSizeChanger
onShowSizeChange={onShowSizeChange}
onChange={onPagination}
defaultCurrent={currentPage}
pageSize={rowsPerPage}
total={totalPage}
pageSizeOptions={["10", "15", "20", "25", "30", "35", "40"]}
/>
</CardBody>
</Card>
</div>

Loading…
Cancel
Save