Commit e1a0b932 authored by Dida Adams Arizona's avatar Dida Adams Arizona

Merge branch 'faisal' into 'master'

delete company

See merge request !253
parents 7506ecd9 699162e3
...@@ -104,6 +104,7 @@ const create = (baseURL = 'https://tia.eksad.com/tia-reporting-dev/public/') => ...@@ -104,6 +104,7 @@ const create = (baseURL = 'https://tia.eksad.com/tia-reporting-dev/public/') =>
const getDetailPerusahaan = (id) => api.get(`company/get_company_by_id/${id}`) const getDetailPerusahaan = (id) => api.get(`company/get_company_by_id/${id}`)
const uploadPerusahaan = (body) => api.post('company/import_company', body) const uploadPerusahaan = (body) => api.post('company/import_company', body)
const searchPerusahaan = (body) => api.post('company/search_company', body) const searchPerusahaan = (body) => api.post('company/search_company', body)
const deletePerusahaan = (id) => api.post(`company/delete_company/${id}`)
// APPROVAL MATRIX // APPROVAL MATRIX
const getAM = () => api.get('approval_matrix/get_all_approval_matrix') const getAM = () => api.get('approval_matrix/get_all_approval_matrix')
...@@ -273,6 +274,7 @@ const create = (baseURL = 'https://tia.eksad.com/tia-reporting-dev/public/') => ...@@ -273,6 +274,7 @@ const create = (baseURL = 'https://tia.eksad.com/tia-reporting-dev/public/') =>
getDetailReportMB, getDetailReportMB,
deleteUnitBisnis, deleteUnitBisnis,
deleteParameter, deleteParameter,
deletePerusahaan,
deleteReportItems deleteReportItems
} }
} }
......
import React, { Component } from 'react';
import Images from '../../../assets/Images';
import { Typography } from '@material-ui/core';
import api from "../../../api";
import Constant from '../../../library/Constant';
export default class DeletePerusahaan extends Component {
constructor(props) {
super(props)
this.state = {
companyID: '',
company: null,
}
}
componentDidMount() {
if (this.props.type === 'delete') {
this.getDetailPerusahaan()
}
}
getDetailPerusahaan() {
api.create().getDetailPerusahaan(this.props.data[1]).then(response => {
console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.status === "success") {
let data = response.data.data
this.setState({
companyID: data.company_id,
company: data.company_name,
})
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Token")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
delete() {
if (this.props.type == 'delete') {
let payload = this.state.id
this.props.deleteCompany(payload)
}
}
render() {
return (
<div className="test app-popup-show">
<div className="popup-content background-white border-radius" style={{ borderRadius: 8, padding: 50 }}>
<div style={{ display: 'flex', justifyContent: 'center' }}>
<img src={Images.failedCopy} />
</div>
<div style={{ display: 'grid', justifyContent: 'center', marginTop: 20 }}>
<span style={{ textAlign: 'center', fontSize: 14, fontWeight: 'bold' }}>
Delete {this.state.company} ?
</span>
</div>
<div style={{ display: 'flex', justifyContent: 'center', marginTop: 24 }}>
<button
className={"btn-save"}
onClick={()=> this.props.onClickClose()}
>
<span style={{ color: 'white' }}>Cancel</span>
</button>
<button
className={"btn-save"}
style={{ marginLeft: 50}}
onClick={()=> this.delete()}
>
<span style={{ color: 'white' }}>Delete</span>
</button>
</div>
</div>
</div>
);
}
}
...@@ -14,7 +14,9 @@ import api from "../../../api"; ...@@ -14,7 +14,9 @@ import api from "../../../api";
import ReactTooltip from 'react-tooltip'; import ReactTooltip from 'react-tooltip';
import MuiAlert from '@material-ui/lab/Alert'; import MuiAlert from '@material-ui/lab/Alert';
import { TextField, InputBase, Snackbar, withStyles } from "@material-ui/core"; import { TextField, InputBase, Snackbar, withStyles } from "@material-ui/core";
// import DeletePerusahaan from "./DeletePerusahaan";
import PopUpFailedSave from '../../../library/PopUpFailedSave'; import PopUpFailedSave from '../../../library/PopUpFailedSave';
import PopUpDelete from "../../../library/PopUpDelete";
import Constant from '../../../library/Constant'; import Constant from '../../../library/Constant';
var ct = require("../../../library/CustomTable"); var ct = require("../../../library/CustomTable");
...@@ -32,6 +34,7 @@ export default class Perusahaan extends Component { ...@@ -32,6 +34,7 @@ export default class Perusahaan extends Component {
visibleCreate: false, visibleCreate: false,
visibleEdit: false, visibleEdit: false,
visibleVisual: false, visibleVisual: false,
visibleDelete: false,
dataTable: [], dataTable: [],
listData: [], listData: [],
data: [], data: [],
...@@ -47,7 +50,10 @@ export default class Perusahaan extends Component { ...@@ -47,7 +50,10 @@ export default class Perusahaan extends Component {
create: false, create: false,
edit: false, edit: false,
load: false, load: false,
judul: '' judul: '',
rowData: [],
companyName: ''
} }
this.fileHandler = this.fileHandler.bind(this); this.fileHandler = this.fileHandler.bind(this);
} }
...@@ -85,12 +91,12 @@ export default class Perusahaan extends Component { ...@@ -85,12 +91,12 @@ export default class Perusahaan extends Component {
checkUpload() { checkUpload() {
api.create().checkUploadPerusahaan(this.state.payload).then(response => { api.create().checkUploadPerusahaan(this.state.payload).then(response => {
console.log(response); console.log(response);
let dataRow = []
if (response.data) { if (response.data) {
if (response.ok) { if (response.ok) {
if (response.data.status === "success") { if (response.data.status === "success") {
let dataRow = response.data.data.map((item, index) => { dataRow = response.data.data.map((item, index) => {
return [ return [
index + 1,
item.company_name, item.company_name,
item.company_parent, item.company_parent,
item.unit_bisnis, item.unit_bisnis,
...@@ -100,7 +106,6 @@ export default class Perusahaan extends Component { ...@@ -100,7 +106,6 @@ export default class Perusahaan extends Component {
] ]
}) })
let columns = [ let columns = [
"Data",
{ {
name: "Company Name", name: "Company Name",
options: { options: {
...@@ -116,9 +121,9 @@ export default class Perusahaan extends Component { ...@@ -116,9 +121,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ? {tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="company_name"> <a data-tip={tableMeta.rowData[6][check].message} data-for="company_name">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
</a> : </a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
} }
<ReactTooltip border={true} id="company_name" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="company_name" place="bottom" type="light" effect="solid" />
</div > </div >
...@@ -141,9 +146,9 @@ export default class Perusahaan extends Component { ...@@ -141,9 +146,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ? {tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="company_parent"> <a data-tip={tableMeta.rowData[6][check].message} data-for="company_parent">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
</a> : </a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
} }
<ReactTooltip border={true} id="company_parent" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="company_parent" place="bottom" type="light" effect="solid" />
</div > </div >
...@@ -166,9 +171,9 @@ export default class Perusahaan extends Component { ...@@ -166,9 +171,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ? {tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="unit_bisnis"> <a data-tip={tableMeta.rowData[6][check].message} data-for="unit_bisnis">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
</a> : </a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
} }
<ReactTooltip border={true} id="unit_bisnis" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="unit_bisnis" place="bottom" type="light" effect="solid" />
</div > </div >
...@@ -191,9 +196,9 @@ export default class Perusahaan extends Component { ...@@ -191,9 +196,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ? {tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="startdate"> <a data-tip={tableMeta.rowData[6][check].message} data-for="startdate">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
</a> : </a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
} }
<ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" />
</div > </div >
...@@ -216,9 +221,9 @@ export default class Perusahaan extends Component { ...@@ -216,9 +221,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ? {tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="enddate"> <a data-tip={tableMeta.rowData[6][check].message} data-for="enddate">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
</a> : </a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
} }
<ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
</div > </div >
...@@ -323,6 +328,12 @@ export default class Perusahaan extends Component { ...@@ -323,6 +328,12 @@ export default class Perusahaan extends Component {
rowData: rowData, rowData: rowData,
visibleEdit: true visibleEdit: true
}) })
} else if (type === 'delete') {
this.setState({
rowData: rowData,
companyName: String(rowData[2]),
visibleDelete: true
})
} else { } else {
this.setState({ this.setState({
rowData: rowData, rowData: rowData,
...@@ -475,6 +486,33 @@ export default class Perusahaan extends Component { ...@@ -475,6 +486,33 @@ export default class Perusahaan extends Component {
}) })
} }
deleteCompany = (payload) => {
let id = String(payload[1])
api.create().deletePerusahaan(id).then(response => {
if (response.data) {
if (response.ok) {
if (response.data.status == 'success') {
this.getData()
this.setState({ visibleDelete: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Token")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
closeAlert() { closeAlert() {
this.setState({ alert: false }) this.setState({ alert: false })
} }
...@@ -506,6 +544,20 @@ export default class Perusahaan extends Component { ...@@ -506,6 +544,20 @@ export default class Perusahaan extends Component {
</div > </div >
</button> </button>
)} )}
{this.state.edit && (
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
marginLeft: 10
}}
// onClick={() => this.setState({ visibleEdit: true, data: tableMeta.rowData })}
onClick={() => this.openPopUp(tableMeta.rowData, 'delete')}
>
<img src={Images.delete} />
</button>
)}
</div > </div >
); );
} }
...@@ -764,6 +816,15 @@ export default class Perusahaan extends Component { ...@@ -764,6 +816,15 @@ export default class Perusahaan extends Component {
/> />
)} */} )} */}
{/* {this.state.visibleDelete && (
<DeletePerusahaan
type={"delete"}
onClickClose={() => this.setState({ visibleDelete: false })}
data={this.state.rowData}
deleteCompany={this.deleteCompany.bind(this)}
/>
)} */}
{this.state.popupError && ( {this.state.popupError && (
<PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} /> <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
)} )}
...@@ -805,6 +866,16 @@ export default class Perusahaan extends Component { ...@@ -805,6 +866,16 @@ export default class Perusahaan extends Component {
</div> </div>
</div> </div>
)} )}
{this.state.visibleDelete && (
<PopUpDelete
rowData={this.state.rowData}
name={this.state.companyName}
onClickClose={() => this.setState({ visibleDelete: false })}
onClickDelete={this.deleteCompany.bind(this)}
/>
)}
</div> </div>
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment