Commit 72957447 authored by Deni Rinaldi's avatar Deni Rinaldi

Merge branch 'syadziy' into 'master'

Syadziy

See merge request !216
parents 375bc669 652fb493
...@@ -7,6 +7,7 @@ import Autocomplete from '@material-ui/lab/Autocomplete'; ...@@ -7,6 +7,7 @@ import Autocomplete from '@material-ui/lab/Autocomplete';
import MuiAlert from '@material-ui/lab/Alert'; import MuiAlert from '@material-ui/lab/Alert';
import api from '../../../api'; import api from '../../../api';
import Images from '../../../assets/Images'; import Images from '../../../assets/Images';
import Constant from '../../../library/Constant';
const Alert = withStyles({ const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />); })((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
...@@ -71,23 +72,34 @@ export default class CreatePerusahaan extends Component { ...@@ -71,23 +72,34 @@ export default class CreatePerusahaan extends Component {
api.create().getDetailPerusahaan(this.props.data[1]).then(response => { api.create().getDetailPerusahaan(this.props.data[1]).then(response => {
console.log(response) console.log(response)
if (response.data) { if (response.data) {
if (response.data.status === "success") { if (response.ok) {
this.setState({ if (response.data.status === "success") {
businessID: response.data.data.business_unit_id, this.setState({
companyID: response.data.data.company_id, businessID: response.data.data.business_unit_id,
status: response.data.data.status, companyID: response.data.data.company_id,
company: response.data.data.company_name, status: response.data.data.status,
parentID: response.data.data.parent, company: response.data.data.company_name,
parent: response.data.data.parent_name, parentID: response.data.data.parent,
startDate: response.data.data.start_date, parent: response.data.data.parent_name,
endDate: response.data.data.end_date, startDate: response.data.data.start_date,
totalReport: response.data.data.total_report, endDate: response.data.data.end_date,
created: response.data.data.created, totalReport: response.data.data.total_report,
updated: response.data.data.updated === null ? "" : response.data.data.updated created: response.data.data.created,
}, () => this.getAllUnitBisnis(), this.getCompanyActive()) updated: response.data.data.updated === null ? "" : response.data.data.updated
}, () => this.getAllUnitBisnis(), this.getCompanyActive())
} 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 { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
...@@ -103,23 +115,34 @@ export default class CreatePerusahaan extends Component { ...@@ -103,23 +115,34 @@ export default class CreatePerusahaan extends Component {
api.create().getPerusahaanActive(payload).then(response => { api.create().getPerusahaanActive(payload).then(response => {
console.log(response) console.log(response)
if (response.data) { if (response.data) {
if (response.data.status == 'success') { if (response.ok) {
let data = response.data.data if (response.data.status == 'success') {
let perusahaanData = data.map((item) => { let data = response.data.data
return { let perusahaanData = data.map((item) => {
company_id: item.company_id, return {
company_name: item.company_name company_id: item.company_id,
} company_name: item.company_name
}) }
let index = perusahaanData.sort((a, b) => a.company_id - b.company_id).findIndex((val) => val.company_id == this.state.parentID) })
let typeProps = { let index = perusahaanData.sort((a, b) => a.company_id - b.company_id).findIndex((val) => val.company_id == this.state.parentID)
options: perusahaanData, let typeProps = {
getOptionLabel: (option) => option.company_name, options: perusahaanData,
}; getOptionLabel: (option) => option.company_name,
this.setState({ perusahaan: typeProps, perusahaanData: response.data.data, getPerusahaan: index == -1 ? null : perusahaanData[index] }) };
this.setState({ perusahaan: typeProps, perusahaanData: response.data.data, getPerusahaan: index == -1 ? null : perusahaanData[index] })
} 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 { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
...@@ -130,25 +153,36 @@ export default class CreatePerusahaan extends Component { ...@@ -130,25 +153,36 @@ export default class CreatePerusahaan extends Component {
getAllUnitBisnis() { getAllUnitBisnis() {
api.create().getUnitBisnisActive().then(response => { api.create().getUnitBisnisActive().then(response => {
if (response.data) { if (response.data) {
if (response.data.status === 'success') { if (response.ok) {
let data = response.data.data if (response.data.status === 'success') {
let typeData = data.map((item) => { let data = response.data.data
return { let typeData = data.map((item) => {
business_unit_id: item.business_unit_id, return {
business_unit_name: item.business_unit_name business_unit_id: item.business_unit_id,
} business_unit_name: item.business_unit_name
}) }
// console.log(typeData) })
let index = typeData.findIndex((val) => val.business_unit_id == this.state.businessID) // console.log(typeData)
console.log(index) let index = typeData.findIndex((val) => val.business_unit_id == this.state.businessID)
let typeProps = { console.log(index)
options: typeData, let typeProps = {
getOptionLabel: (option) => option.business_unit_name, options: typeData,
}; getOptionLabel: (option) => option.business_unit_name,
this.setState({ types: typeProps, typeData: response.data.data, getTypes: index == -1 ? null : typeData[index] }) };
this.setState({ types: typeProps, typeData: response.data.data, getTypes: index == -1 ? null : typeData[index] })
} 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 { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
......
...@@ -15,6 +15,7 @@ import ReactTooltip from 'react-tooltip'; ...@@ -15,6 +15,7 @@ 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 PopUpFailedSave from '../../../library/PopUpFailedSave'; import PopUpFailedSave from '../../../library/PopUpFailedSave';
import Constant from '../../../library/Constant';
var ct = require("../../../library/CustomTable"); var ct = require("../../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable()); const getMuiTheme = () => createMuiTheme(ct.customTable());
...@@ -78,159 +79,176 @@ export default class Perusahaan extends Component { ...@@ -78,159 +79,176 @@ export default class Perusahaan extends Component {
this.setState({ payload: body, buttonError: false }) this.setState({ payload: body, buttonError: false })
api.create().checkUploadPerusahaan(body).then(response => { api.create().checkUploadPerusahaan(body).then(response => {
console.log(response); console.log(response);
if (response.data.status === "success") { if (response.data) {
let dataRow = response.data.data.map((item, index) => { if (response.ok) {
return [ if (response.data.status === "success") {
index + 1, let dataRow = response.data.data.map((item, index) => {
item.company_name, return [
item.company_parent, index + 1,
item.unit_bisnis, item.company_name,
item.start_date, item.company_parent,
item.end_date, item.unit_bisnis,
item.error item.start_date,
] item.end_date,
}) item.error
let columns = [ ]
"Data", })
{ let columns = [
name: "Company Name", "Data",
options: { {
customBodyRender: (val, tableMeta) => { name: "Company Name",
let check = null options: {
if (tableMeta.rowData[6] != null) { customBodyRender: (val, tableMeta) => {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('company_name')) let check = null
if (check > -1) { if (tableMeta.rowData[6] != null) {
this.setState({ buttonError: true }) check = tableMeta.rowData[6].findIndex((val) => val.field.includes('company_name'))
if (check > -1) {
this.setState({ buttonError: true })
}
}
return (
<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>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="company_name" place="bottom" type="light" effect="solid" />
</div >
);
} }
} }
return ( },
<div style={{ display: 'flex' }}> {
{tableMeta.rowData[6] != null && check > -1 ? name: "Parent Company",
<a data-tip={tableMeta.rowData[6][check].message} data-for="company_name"> options: {
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> customBodyRender: (val, tableMeta) => {
</a> : let check = null
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> if (tableMeta.rowData[6] != null) {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('company_parent'))
if (check > -1) {
this.setState({ buttonError: true })
}
} }
<ReactTooltip border={true} id="company_name" place="bottom" type="light" effect="solid" /> return (
</div > <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>
}, </a> :
{ <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
name: "Parent Company", }
options: { <ReactTooltip border={true} id="company_parent" place="bottom" type="light" effect="solid" />
customBodyRender: (val, tableMeta) => { </div >
let check = null );
if (tableMeta.rowData[6] != null) {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('company_parent'))
if (check > -1) {
this.setState({ buttonError: true })
} }
} }
return ( },
<div style={{ display: 'flex' }}> {
{tableMeta.rowData[6] != null && check > -1 ? name: "Unit Bisnis",
<a data-tip={tableMeta.rowData[6][check].message} data-for="company_parent"> options: {
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> customBodyRender: (val, tableMeta) => {
</a> : let check = null
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> if (tableMeta.rowData[6] != null) {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('unit_bisnis'))
if (check > -1) {
this.setState({ buttonError: true })
}
} }
<ReactTooltip border={true} id="company_parent" place="bottom" type="light" effect="solid" /> return (
</div > <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>
}, </a> :
{ <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
name: "Unit Bisnis", }
options: { <ReactTooltip border={true} id="unit_bisnis" place="bottom" type="light" effect="solid" />
customBodyRender: (val, tableMeta) => { </div >
let check = null );
if (tableMeta.rowData[6] != null) {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('unit_bisnis'))
if (check > -1) {
this.setState({ buttonError: true })
} }
} }
return ( },
<div style={{ display: 'flex' }}> {
{tableMeta.rowData[6] != null && check > -1 ? name: "Start Date",
<a data-tip={tableMeta.rowData[6][check].message} data-for="unit_bisnis"> options: {
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> customBodyRender: (val, tableMeta) => {
</a> : let check = null
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> if (tableMeta.rowData[6] != null) {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('start_date'))
if (check > -1) {
this.setState({ buttonError: true })
}
} }
<ReactTooltip border={true} id="unit_bisnis" place="bottom" type="light" effect="solid" /> return (
</div > <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>
}, </a> :
{ <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
name: "Start Date", }
options: { <ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" />
customBodyRender: (val, tableMeta) => { </div >
let check = null );
if (tableMeta.rowData[6] != null) {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('start_date'))
if (check > -1) {
this.setState({ buttonError: true })
} }
} }
return ( },
<div style={{ display: 'flex' }}> {
{tableMeta.rowData[6] != null && check > -1 ? name: "End Date",
<a data-tip={tableMeta.rowData[6][check].message} data-for="startdate"> options: {
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> customBodyRender: (val, tableMeta) => {
</a> : let check = null
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> if (tableMeta.rowData[6] != null) {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('end_date'))
if (check > -1) {
this.setState({ buttonError: true })
}
} }
<ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" /> return (
</div > <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>
}, </a> :
{ <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
name: "End Date", }
options: { <ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
customBodyRender: (val, tableMeta) => { </div >
let check = null );
if (tableMeta.rowData[6] != null) {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('end_date'))
if (check > -1) {
this.setState({ buttonError: true })
} }
} }
return ( },
<div style={{ display: 'flex' }}> {
{tableMeta.rowData[6] != null && check > -1 ? name: "",
<a data-tip={tableMeta.rowData[6][check].message} data-for="enddate"> options: {
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span> display: false
</a> : }
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
}
<ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
</div >
);
} }
} ]
},
{ console.log(dataRow);
name: "", this.setState({
options: { dataLoaded: true,
display: false cols: columns,
} rows: dataRow
});
} 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' })
console.log(dataRow); }
this.setState({ } else {
dataLoaded: true, this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
cols: columns,
rows: dataRow
});
} }
console.log(response); console.log(response);
}) })
...@@ -270,14 +288,25 @@ export default class Perusahaan extends Component { ...@@ -270,14 +288,25 @@ export default class Perusahaan extends Component {
api.create().getPerusahaan().then((response) => { api.create().getPerusahaan().then((response) => {
console.log(response) console.log(response)
if (response.data) { if (response.data) {
if (response.data.status == 'success') { if (response.ok) {
let data = response.data.data if (response.data.status == 'success') {
let listData = data.sort((a, b) => a.company_id - b.company_id).map((item, index) => { let data = response.data.data
return [index, item.company_id, item.company_name, item.parent_name, item.business_unit_name, item.status] let listData = data.sort((a, b) => a.company_id - b.company_id).map((item, index) => {
}) return [index, item.company_id, item.company_name, item.parent_name, item.business_unit_name, item.status]
this.setState({ dataTable: listData, listData: response.data.data }) })
this.setState({ dataTable: listData, listData: response.data.data })
} 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 { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', dataTable: [] })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', dataTable: [] }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', dataTable: [] })
...@@ -306,14 +335,25 @@ export default class Perusahaan extends Component { ...@@ -306,14 +335,25 @@ export default class Perusahaan extends Component {
} }
api.create().searchPerusahaan(body).then(response => { api.create().searchPerusahaan(body).then(response => {
if (response.data) { if (response.data) {
if (response.data.status == 'success') { if (response.ok) {
let data = response.data.data if (response.data.status == 'success') {
let listData = data.map((item, index) => { let data = response.data.data
return [index, item.company_id, item.company_name, item.parent_name, item.business_unit_name, item.status] let listData = data.map((item, index) => {
}) return [index, item.company_id, item.company_name, item.parent_name, item.business_unit_name, item.status]
this.setState({ dataTable: listData, listData: response.data.data }) })
this.setState({ dataTable: listData, listData: response.data.data })
} 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 { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
...@@ -325,11 +365,22 @@ export default class Perusahaan extends Component { ...@@ -325,11 +365,22 @@ export default class Perusahaan extends Component {
this.setState({ visibleEdit: false }) this.setState({ visibleEdit: false })
api.create().updatePerusahaan(payload).then(response => { api.create().updatePerusahaan(payload).then(response => {
if (response.data) { if (response.data) {
if (response.data.status == 'success') { if (response.ok) {
this.getData() if (response.data.status == 'success') {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' }) this.getData()
this.setState({ 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 { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
...@@ -341,11 +392,22 @@ export default class Perusahaan extends Component { ...@@ -341,11 +392,22 @@ export default class Perusahaan extends Component {
this.setState({ visibleCreate: false }) this.setState({ visibleCreate: false })
api.create().createPerusahaan(payload).then(response => { api.create().createPerusahaan(payload).then(response => {
if (response.data) { if (response.data) {
if (response.data.status == 'success') { if (response.ok) {
this.getData() if (response.data.status == 'success') {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' }) this.getData()
this.setState({ 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 { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
...@@ -387,11 +449,22 @@ export default class Perusahaan extends Component { ...@@ -387,11 +449,22 @@ export default class Perusahaan extends Component {
api.create().uploadPerusahaan(this.state.payload).then(response => { api.create().uploadPerusahaan(this.state.payload).then(response => {
console.log(response) console.log(response)
if (response.data) { if (response.data) {
if (response.data.status == "success") { if (response.ok) {
this.getData() if (response.data.status == "success") {
this.setState({ visiblePerusahaan: true, alert: true, messageAlert: response.data.message, tipeAlert: 'success' }) this.getData()
this.setState({ visiblePerusahaan: true, 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 { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
......
...@@ -7,6 +7,7 @@ import Nestable from 'react-nestable/dist/Nestable'; ...@@ -7,6 +7,7 @@ import Nestable from 'react-nestable/dist/Nestable';
import AddIcon from '@material-ui/icons/Add'; import AddIcon from '@material-ui/icons/Add';
import RemoveIcon from '@material-ui/icons/Remove'; import RemoveIcon from '@material-ui/icons/Remove';
import api from '../../../api'; import api from '../../../api';
import Constant from '../../../library/Constant';
const Alert = withStyles({ const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />); })((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
...@@ -55,11 +56,22 @@ export default class VisualPerusahaan extends Component { ...@@ -55,11 +56,22 @@ export default class VisualPerusahaan extends Component {
api.create().getPerusahaanHierarki().then((response) => { api.create().getPerusahaanHierarki().then((response) => {
console.log(response) console.log(response)
if (response.data) { if (response.data) {
if (response.data.status == 'success') { if (response.ok) {
this.setState({ items: response.data.data }) if (response.data.status == 'success') {
console.log(response.data.data) this.setState({ items: response.data.data })
console.log(response.data.data)
} 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 { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
...@@ -89,8 +101,26 @@ export default class VisualPerusahaan extends Component { ...@@ -89,8 +101,26 @@ export default class VisualPerusahaan extends Component {
"company": this.state.items "company": this.state.items
} }
api.create().saveVisualisasiPerusahaan(payload).then((response) => { api.create().saveVisualisasiPerusahaan(payload).then((response) => {
// if (response.data.status == 'ucces') { if (response.data) {
this.props.onClickClose() if (response.ok) {
if (response.data.status == 'success') {
this.props.onClickClose()
} 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' })
}
// } else { // } else {
// alert(response.data.message) // alert(response.data.message)
// } // }
......
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