Commit 06bbe176 authored by faisalhamdi's avatar faisalhamdi

delete company

parent 03d79925
......@@ -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 uploadPerusahaan = (body) => api.post('company/import_company', body)
const searchPerusahaan = (body) => api.post('company/search_company', body)
const deletePerusahaan = (id) => api.post(`company/delete_company/${id}`)
// APPROVAL MATRIX
const getAM = () => api.get('approval_matrix/get_all_approval_matrix')
......@@ -271,7 +272,8 @@ const create = (baseURL = 'https://tia.eksad.com/tia-reporting-dev/public/') =>
deleteAttachment,
getDetailReportMB,
deleteUnitBisnis,
deleteParameter
deleteParameter,
deletePerusahaan
}
}
......
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";
import ReactTooltip from 'react-tooltip';
import MuiAlert from '@material-ui/lab/Alert';
import { TextField, InputBase, Snackbar, withStyles } from "@material-ui/core";
// import DeletePerusahaan from "./DeletePerusahaan";
import PopUpFailedSave from '../../../library/PopUpFailedSave';
import PopUpDelete from "../../../library/PopUpDelete";
import Constant from '../../../library/Constant';
var ct = require("../../../library/CustomTable");
......@@ -32,6 +34,7 @@ export default class Perusahaan extends Component {
visibleCreate: false,
visibleEdit: false,
visibleVisual: false,
visibleDelete: false,
dataTable: [],
listData: [],
data: [],
......@@ -47,7 +50,10 @@ export default class Perusahaan extends Component {
create: false,
edit: false,
load: false,
judul: ''
judul: '',
rowData: [],
companyName: ''
}
this.fileHandler = this.fileHandler.bind(this);
}
......@@ -85,12 +91,12 @@ export default class Perusahaan extends Component {
checkUpload() {
api.create().checkUploadPerusahaan(this.state.payload).then(response => {
console.log(response);
let dataRow = []
if (response.data) {
if (response.ok) {
if (response.data.status === "success") {
let dataRow = response.data.data.map((item, index) => {
dataRow = response.data.data.map((item, index) => {
return [
index + 1,
item.company_name,
item.company_parent,
item.unit_bisnis,
......@@ -100,7 +106,6 @@ export default class Perusahaan extends Component {
]
})
let columns = [
"Data",
{
name: "Company Name",
options: {
......@@ -116,9 +121,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ?
<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> :
<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" />
</div >
......@@ -141,9 +146,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ?
<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> :
<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" />
</div >
......@@ -166,9 +171,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ?
<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> :
<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" />
</div >
......@@ -191,9 +196,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ?
<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> :
<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" />
</div >
......@@ -216,9 +221,9 @@ export default class Perusahaan extends Component {
<div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ?
<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> :
<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" />
</div >
......@@ -323,6 +328,12 @@ export default class Perusahaan extends Component {
rowData: rowData,
visibleEdit: true
})
} else if (type === 'delete') {
this.setState({
rowData: rowData,
companyName: String(rowData[2]),
visibleDelete: true
})
} else {
this.setState({
rowData: rowData,
......@@ -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() {
this.setState({ alert: false })
}
......@@ -501,6 +539,20 @@ export default class Perusahaan extends Component {
<img src={Images.editCopy} />
</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 >
);
}
......@@ -759,6 +811,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 && (
<PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
)}
......@@ -800,6 +861,16 @@ export default class Perusahaan extends Component {
</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>
);
}
......
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