From 01e2b480bef3bfe2b832a17c17637d82e663d686 Mon Sep 17 00:00:00 2001 From: nurkomalasari Date: Thu, 5 Jan 2023 17:17:11 +0700 Subject: [PATCH] bug fixing edit,delete role project --- src/views/Master/RoleProject/index.js | 763 +++++++++++++------------- 1 file changed, 384 insertions(+), 379 deletions(-) diff --git a/src/views/Master/RoleProject/index.js b/src/views/Master/RoleProject/index.js index de57669..f30ccdb 100644 --- a/src/views/Master/RoleProject/index.js +++ b/src/views/Master/RoleProject/index.js @@ -1,379 +1,384 @@ -import * as XLSX from 'xlsx'; -import DialogForm from './DialogForm'; -import React, { Component } from 'react'; -import SweetAlert from 'react-bootstrap-sweetalert'; -import axios from 'axios'; -import { Button } from 'reactstrap'; -import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; -import { NotificationContainer, NotificationManager } from 'react-notifications'; -import { PROJECT_ROLE_ADD, PROJECT_ROLE_SEARCH, PROJECT_ROLE_EDIT, PROJECT_ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; -import { Pagination, Tooltip, Table } from 'antd'; - -const token = window.localStorage.getItem('token'); - -const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; - -const config = { - headers: - { - Authorization : `Bearer ${token}`, - "Content-type" : `application/json` - } -}; - -const columns = [ - { - title: 'Action', - dataIndex: '', - key: 'x', - className:'nowrap', - render: (text, record) => <> - - this.handleDelete(text.id)}> - - - - this.handleEdit(text)}> - - , - }, - { title: 'Nama Role', dataIndex: 'name', key: 'name', className:"nowrap" }, - { title: 'Description', dataIndex: 'description', key: 'description' }, -]; - -const momentFormat = 'HH:mm'; - -const column = [ - { name: "Nama" }, - { name: "Deskripsi" }, -] - -const LENGTH_DATA = 10 - -export default class index extends Component { - constructor(props) { - super(props) - this.state = { - alertDelete: false, - alertNotDelete: false, - currentPage: 1, - dataEdit: null, - dataExport:[], - dataGs: [], - dataIdHo: [], - dataTable: [], - dialogMenuForm: false, - idDelete: 0, - idRoles:0, - menuRoles:[], - openDialog: false, - page: 0, - rowsPerPage: LENGTH_DATA, - search: "", - tooltipDelete: false, - tooltipEdit: false, - tooltipExport:false, - tooltipImport:false, - tooltipMenu: false, - tooltipTambah:false, - totalPage: 0, - typeDialog: 'Save', - } - } - - async componentDidMount() { - this.getDataRoles(); - } - - async componentDidUpdate(prevProps, prevState) { - const { search } = this.state - if (search !== prevState.search) this.getDataRoles() - } - - handleSearch = e => { - const value = e.target.value - this.setState({ search: value, currentPage: 1 }) - }; - - getDataRoles = async () => { - let start = 0; - if (this.state.currentPage !== 1 && this.state.currentPage > 1) { - start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage - } - - const formData = { - "paging": {"start": start, "length": this.state.rowsPerPage}, - "columns": [ - {"name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - - const result = await axios - .post(PROJECT_ROLE_SEARCH, formData, config) - .then(res => res) - .catch((error) => error.response); - - if(result && result.data && result.data.code == 200){ - this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord }); - }else{ - NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); - } - } - - handleOpenDialog = (type) => { - this.setState({ openDialog: true, typeDialog: type }) - this.showChildDialog(); - } - - handleCloseDialog = (type, data) => { - if (type === "save") { - this.saveRole(data); - } else if (type === "edit") { - this.editRole(data); - } - this.setState({ openDialog: false }) - } - - - handleOpenDialogMr = () => { - this.setState({ dialogMenuForm: true }) - this.showMenuRolesDialog(); - } - handleCloseDialogMr = (type, data) => { - if(type==="save"){ - this.saveMenuRoles(data) - } - this.setState({ dialogMenuForm: false }) - } - - toggleAddDialog = () => { - this.setState({ openDialog: !this.state.openDialog }) - } - - onConfirmDelete = async () => { - const { idDelete } = this.state - const url = PROJECT_ROLE_DELETE(idDelete) - - const result = await axios.delete(url, config) - .then(res => res) - .catch((error) => error.response); - - if (result && result.data && result.data.code === 200) { - this.getDataRoles() - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.success(`Data project role berhasil dihapus`, 'Success!!'); - } else { - this.setState({ idDelete: 0, alertDelete: false }) - NotificationManager.error(`Data project role gagal dihapus`, 'Failed!!'); - } - } - - saveRole = async (data) => { - - const formData = { - name:data.name, - description:data.description - } - - const result = await axios.post(PROJECT_ROLE_ADD, formData, config) - .then(res => res) - .catch((error) => error.response); - - if(result && result.data && result.data.code===200){ - this.getDataRoles(); - NotificationManager.success(`Data project role berhasil ditambah`, 'Success!!'); - } else { - NotificationManager.error(`${result.data.message}`, 'Failed!!'); - } - - } - - editRole = async (data) => { - - const formData = { - name:data.name, - description:data.description - } - const url = PROJECT_ROLE_EDIT(data.id) - const result = await axios.put(url, formData, config) - .then(res => res) - .catch((error) => error.response); - - if(result && result.data && result.data.code===200){ - this.getDataRoles(); - NotificationManager.success(`Data project role berhasil diedit`, 'Success!!'); - } else { - NotificationManager.error(`Data project role gagal di edit`, `Failed!!`); - } - - } - - - handleEdit = (data) => { - this.setState({ dataEdit: data }); - this.handleOpenDialog('Edit'); - } - - handleDelete = (id) => { - this.setState({ alertDelete: true, idDelete: id }); - } - - onShowSizeChange = (current, pageSize) => { - this.setState({ rowsPerPage: pageSize }, () => { - this.getDataRoles(); - }) - } - - onPagination = (current, pageSize) => { - this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { - this.getDataRoles(); - }) - } - - toggle = (param) => { - if (param === "edit") { - this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) - } else if (param === "delete") { - this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) - } else if(param === "menu"){ - this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu })) - } else if (param === "tambah") { - this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) - } else if (param === "export") { - this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) - } - } - - dataNotAvailable = () => { - if(this.state.dataTable.length===0){ - return ( - - Tidak ada data project role - - ) - } - } - - handleExportExcel = async () => { - const payload = { - "paging": {"start": 0, "length": -1}, - "columns": [ - {"name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND"} - ], - "joins": [], - "orders": {"columns": ["id"], "ascending": false} - } - const result = await axios - .post(PROJECT_ROLE_SEARCH, payload) - .then(res => res) - .catch((error) => error.response); - if (result && result.data && result.statusText == "OK") { - const dataRes = result.data.data|| []; - console.log("data result", dataRes); - const dataExport = []; - dataRes.map((val,index)=> { - let row = { - Nama:val.name, - Deskripsi:val.description - } - dataExport.push(row); - }) - this.setState({ dataExport:dataExport },()=> { - this.exportExcel(); - }); - } else { - NotificationManager.error('Failed retreiving data!!', 'Failed'); - } - } - - exportExcel = () => { - const dataExcel = this.state.dataExport || []; - const fileName = "Data Project Role.xlsx"; - const ws = XLSX.utils.json_to_sheet(dataExcel); - const wb = XLSX.utils.book_new(); - XLSX.utils.book_append_sheet(wb, ws, 'Data Project Role'); - XLSX.writeFile(wb, fileName); - } - - render() { - const { tooltipTambah,tooltipExport,dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete,tooltipMenu } = this.state - let noSeq = 0; - return ( -
- - this.setState({ alertDelete: false, idDelete: 0 })} - focusCancelBtn - > - Data project role akan terhapus!! - - this.setState({ alertNotDelete: false})} - > - Data project role tidak dapat di hapus!! - - this.toggleAddDialog} - typeDialog={this.state.typeDialog} - dataEdit={this.state.dataEdit} - showDialog={showDialog => this.showChildDialog = showDialog} - dataHs={this.state.dataIdHo} - /> - - -

{this.props.params.name}

- - - - - - - - - - - - - -
- - - - - - - ) - } -} +import * as XLSX from 'xlsx'; +import DialogForm from './DialogForm'; +import React, { Component } from 'react'; +import SweetAlert from 'react-bootstrap-sweetalert'; +import axios from 'axios'; +import { Button } from 'reactstrap'; +import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; +import { NotificationContainer, NotificationManager } from 'react-notifications'; +import { PROJECT_ROLE_ADD, PROJECT_ROLE_SEARCH, PROJECT_ROLE_EDIT, PROJECT_ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; +import { Pagination, Tooltip, Table } from 'antd'; + +const token = window.localStorage.getItem('token'); + +const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; + +const config = { + headers: + { + Authorization: `Bearer ${token}`, + "Content-type": `application/json` + } +}; + + + +const momentFormat = 'HH:mm'; + +const column = [ + { name: "Nama" }, + { name: "Deskripsi" }, +] + +const LENGTH_DATA = 10 + +export default class index extends Component { + constructor(props) { + super(props) + this.state = { + alertDelete: false, + alertNotDelete: false, + currentPage: 1, + dataEdit: null, + dataExport: [], + dataGs: [], + dataIdHo: [], + dataTable: [], + dialogMenuForm: false, + idDelete: 0, + idRoles: 0, + menuRoles: [], + openDialog: false, + page: 0, + rowsPerPage: LENGTH_DATA, + search: "", + tooltipDelete: false, + tooltipEdit: false, + tooltipExport: false, + tooltipImport: false, + tooltipMenu: false, + tooltipTambah: false, + totalPage: 0, + typeDialog: 'Save', + } + this.columns = [ + { + title: 'Action', + dataIndex: '', + key: 'x', + className: 'nowrap', + render: (text, record) => <> + + this.handleDelete(text.id)}> + + + + + this.handleEdit(text)}> + + , + }, + { title: 'Nama Role', dataIndex: 'name', key: 'name', className: "nowrap" }, + { title: 'Description', dataIndex: 'description', key: 'description' }, + ]; + } + + + + async componentDidMount() { + this.getDataRoles(); + } + + async componentDidUpdate(prevProps, prevState) { + const { search } = this.state + if (search !== prevState.search) this.getDataRoles() + } + + handleSearch = e => { + const value = e.target.value + this.setState({ search: value, currentPage: 1 }) + }; + + getDataRoles = async () => { + let start = 0; + if (this.state.currentPage !== 1 && this.state.currentPage > 1) { + start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage + } + + const formData = { + "paging": { "start": start, "length": this.state.rowsPerPage }, + "columns": [ + { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND" } + ], + "joins": [], + "orders": { "columns": ["id"], "ascending": false } + } + + const result = await axios + .post(PROJECT_ROLE_SEARCH, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code == 200) { + this.setState({ dataTable: result.data.data, totalPage: result.data.totalRecord }); + } else { + NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); + } + } + + handleOpenDialog = (type) => { + this.setState({ openDialog: true, typeDialog: type }) + this.showChildDialog(); + } + + handleCloseDialog = (type, data) => { + if (type === "save") { + this.saveRole(data); + } else if (type === "edit") { + this.editRole(data); + } + this.setState({ openDialog: false }) + } + + + handleOpenDialogMr = () => { + this.setState({ dialogMenuForm: true }) + this.showMenuRolesDialog(); + } + handleCloseDialogMr = (type, data) => { + if (type === "save") { + this.saveMenuRoles(data) + } + this.setState({ dialogMenuForm: false }) + } + + toggleAddDialog = () => { + this.setState({ openDialog: !this.state.openDialog }) + } + + onConfirmDelete = async () => { + const { idDelete } = this.state + const url = PROJECT_ROLE_DELETE(idDelete) + + const result = await axios.delete(url, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + this.getDataRoles() + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.success(`Data project role berhasil dihapus`, 'Success!!'); + } else { + this.setState({ idDelete: 0, alertDelete: false }) + NotificationManager.error(`Data project role gagal dihapus`, 'Failed!!'); + } + } + + saveRole = async (data) => { + + const formData = { + name: data.name, + description: data.description + } + + const result = await axios.post(PROJECT_ROLE_ADD, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + this.getDataRoles(); + NotificationManager.success(`Data project role berhasil ditambah`, 'Success!!'); + } else { + NotificationManager.error(`${result.data.message}`, 'Failed!!'); + } + + } + + editRole = async (data) => { + + const formData = { + name: data.name, + description: data.description + } + const url = PROJECT_ROLE_EDIT(data.id) + const result = await axios.put(url, formData, config) + .then(res => res) + .catch((error) => error.response); + + if (result && result.data && result.data.code === 200) { + this.getDataRoles(); + NotificationManager.success(`Data project role berhasil diedit`, 'Success!!'); + } else { + NotificationManager.error(`Data project role gagal di edit`, `Failed!!`); + } + + } + + + handleEdit = (data) => { + this.setState({ dataEdit: data }); + this.handleOpenDialog('Edit'); + } + + handleDelete = (id) => { + id == '1' ? this.setState({ alertNotDelete: true }) : + this.setState({ alertDelete: true, idDelete: id }); + } + + onShowSizeChange = (current, pageSize) => { + this.setState({ rowsPerPage: pageSize }, () => { + this.getDataRoles(); + }) + } + + onPagination = (current, pageSize) => { + this.setState({ currentPage: current, page: (current - 1) * pageSize }, () => { + this.getDataRoles(); + }) + } + + toggle = (param) => { + if (param === "edit") { + this.setState(prevState => ({ tooltipEdit: !prevState.tooltipEdit })) + } else if (param === "delete") { + this.setState(prevState => ({ tooltipDelete: !prevState.tooltipDelete })) + } else if (param === "menu") { + this.setState(prevState => ({ tooltipMenu: !prevState.tooltipMenu })) + } else if (param === "tambah") { + this.setState(prevState => ({ tooltipTambah: !prevState.tooltipTambah })) + } else if (param === "export") { + this.setState(prevState => ({ tooltipExport: !prevState.tooltipExport })) + } + } + + dataNotAvailable = () => { + if (this.state.dataTable.length === 0) { + return ( + + + + ) + } + } + + handleExportExcel = async () => { + const payload = { + "paging": { "start": 0, "length": -1 }, + "columns": [ + { "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND" } + ], + "joins": [], + "orders": { "columns": ["id"], "ascending": false } + } + const result = await axios + .post(PROJECT_ROLE_SEARCH, payload) + .then(res => res) + .catch((error) => error.response); + if (result && result.data && result.statusText == "OK") { + const dataRes = result.data.data || []; + console.log("data result", dataRes); + const dataExport = []; + dataRes.map((val, index) => { + let row = { + Nama: val.name, + Deskripsi: val.description + } + dataExport.push(row); + }) + this.setState({ dataExport: dataExport }, () => { + this.exportExcel(); + }); + } else { + NotificationManager.error('Failed retreiving data!!', 'Failed'); + } + } + + exportExcel = () => { + const dataExcel = this.state.dataExport || []; + const fileName = "Data Project Role.xlsx"; + const ws = XLSX.utils.json_to_sheet(dataExcel); + const wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, 'Data Project Role'); + XLSX.writeFile(wb, fileName); + } + + render() { + const { tooltipTambah, tooltipExport, dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete, tooltipMenu } = this.state + let noSeq = 0; + return ( +
+ + this.setState({ alertDelete: false, idDelete: 0 })} + focusCancelBtn + > + Data project role akan terhapus!! + + this.setState({ alertNotDelete: false })} + > + Data project role tidak dapat di hapus!! + + this.toggleAddDialog} + typeDialog={this.state.typeDialog} + dataEdit={this.state.dataEdit} + showDialog={showDialog => this.showChildDialog = showDialog} + dataHs={this.state.dataIdHo} + /> + + +

{this.props.params.name}

+ +
+ + + + + + + + + + + + + +
Tidak ada data project role
+ + + + + ) + } +}