Commit 25593e5a authored by faisalhamdi's avatar faisalhamdi

validasi company

parent 32966a92
...@@ -78,184 +78,186 @@ export default class Perusahaan extends Component { ...@@ -78,184 +78,186 @@ export default class Perusahaan extends Component {
} }
console.log(resp.rows[1]) console.log(resp.rows[1])
this.setState({ payload: body, buttonError: false, judul: resp.rows[1][0] }) this.setState({ payload: body, buttonError: false, judul: resp.rows[1][0] })
api.create().checkUploadPerusahaan(body).then(response => { }
console.log(response); });
if (response.data) { }
if (response.ok) {
if (response.data.status === "success") { checkUpload() {
let dataRow = response.data.data.map((item, index) => { api.create().checkUploadPerusahaan(this.state.payload).then(response => {
return [ console.log(response);
index + 1, if (response.data) {
item.company_name, if (response.ok) {
item.company_parent, if (response.data.status === "success") {
item.unit_bisnis, let dataRow = response.data.data.map((item, index) => {
item.start_date, return [
item.end_date, index + 1,
item.error item.company_name,
] item.company_parent,
}) item.unit_bisnis,
let columns = [ item.start_date,
"Data", item.end_date,
{ item.error
name: "Company Name", ]
options: { })
customBodyRender: (val, tableMeta) => { let columns = [
let check = null "Data",
if (tableMeta.rowData[6] != null) { {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('company_name')) name: "Company Name",
if (check > -1) { options: {
this.setState({ buttonError: true }) customBodyRender: (val, tableMeta) => {
} let check = null
} if (tableMeta.rowData[6] != null) {
return ( check = tableMeta.rowData[6].findIndex((val) => val.field.includes('company_name'))
<div style={{ display: 'flex' }}> if (check > -1) {
{tableMeta.rowData[6] != null && check > -1 ? this.setState({ buttonError: true })
<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' }}>
name: "Parent Company", {tableMeta.rowData[6] != null && check > -1 ?
options: { <a data-tip={tableMeta.rowData[6][check].message} data-for="company_name">
customBodyRender: (val, tableMeta) => { <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
let check = null </a> :
if (tableMeta.rowData[6] != null) { <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('company_parent'))
if (check > -1) {
this.setState({ buttonError: true })
}
} }
return ( <ReactTooltip border={true} id="company_name" place="bottom" type="light" effect="solid" />
<div style={{ display: 'flex' }}> </div >
{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",
<ReactTooltip border={true} id="company_parent" place="bottom" type="light" effect="solid" /> options: {
</div > customBodyRender: (val, tableMeta) => {
); 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' }}>
name: "Unit Bisnis", {tableMeta.rowData[6] != null && check > -1 ?
options: { <a data-tip={tableMeta.rowData[6][check].message} data-for="company_parent">
customBodyRender: (val, tableMeta) => { <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
let check = null </a> :
if (tableMeta.rowData[6] != null) { <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('unit_bisnis'))
if (check > -1) {
this.setState({ buttonError: true })
}
} }
return ( <ReactTooltip border={true} id="company_parent" place="bottom" type="light" effect="solid" />
<div style={{ display: 'flex' }}> </div >
{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: "Business Unit",
<ReactTooltip border={true} id="unit_bisnis" place="bottom" type="light" effect="solid" /> options: {
</div > customBodyRender: (val, tableMeta) => {
); 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' }}>
name: "Start Date", {tableMeta.rowData[6] != null && check > -1 ?
options: { <a data-tip={tableMeta.rowData[6][check].message} data-for="unit_bisnis">
customBodyRender: (val, tableMeta) => { <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
let check = null </a> :
if (tableMeta.rowData[6] != null) { <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('start_date'))
if (check > -1) {
this.setState({ buttonError: true })
}
} }
return ( <ReactTooltip border={true} id="unit_bisnis" place="bottom" type="light" effect="solid" />
<div style={{ display: 'flex' }}> </div >
{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: "Valid From",
<ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" /> options: {
</div > customBodyRender: (val, tableMeta) => {
); 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' }}>
name: "End Date", {tableMeta.rowData[6] != null && check > -1 ?
options: { <a data-tip={tableMeta.rowData[6][check].message} data-for="startdate">
customBodyRender: (val, tableMeta) => { <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
let check = null </a> :
if (tableMeta.rowData[6] != null) { <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('end_date'))
if (check > -1) {
this.setState({ buttonError: true })
}
} }
return ( <ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" />
<div style={{ display: 'flex' }}> </div >
{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: "Valid To",
<ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" /> options: {
</div > customBodyRender: (val, tableMeta) => {
); 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' }}>
name: "", {tableMeta.rowData[6] != null && check > -1 ?
options: { <a data-tip={tableMeta.rowData[6][check].message} data-for="enddate">
display: false <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="enddate" place="bottom" type="light" effect="solid" />
console.log(dataRow); </div >
this.setState({ );
dataLoaded: true,
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);
} }
}) }
},
{
name: "",
options: {
display: false
}
} }
} else { ]
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} // console.log(dataRow);
this.setState({
dataLoaded: true,
cols: columns,
rows: dataRow, visibleUpload: false,
visiblePerusahaan: false
});
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) 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);
}
})
} }
console.log(response); } else {
}) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
}); })
} }
componentDidMount() { componentDidMount() {
...@@ -287,7 +289,7 @@ export default class Perusahaan extends Component { ...@@ -287,7 +289,7 @@ export default class Perusahaan extends Component {
getData() { getData() {
api.create().getPerusahaan().then((response) => { api.create().getPerusahaan().then((response) => {
console.log(response) // console.log(response)
if (response.data) { if (response.data) {
if (response.ok) { if (response.ok) {
if (response.data.status == 'success') { if (response.data.status == 'success') {
...@@ -307,10 +309,10 @@ export default class Perusahaan extends Component { ...@@ -307,10 +309,10 @@ export default class Perusahaan extends Component {
}) })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', dataTable: [] }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
} }
} else { } else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', dataTable: [] }) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
}) })
} }
...@@ -789,7 +791,7 @@ export default class Perusahaan extends Component { ...@@ -789,7 +791,7 @@ export default class Perusahaan extends Component {
}} }}
onUpload={() => { onUpload={() => {
this.state.judul === "MASTER DATA - COMPANY" ? this.state.judul === "MASTER DATA - COMPANY" ?
this.setState({ visibleUpload: false, visiblePerusahaan: false }) : this.checkUpload() :
this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning'}) this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning'})
}} }}
/> />
......
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