Commit 2a53aaeb authored by d.arizona's avatar d.arizona

ketinggalan

parent 558b9471
This diff is collapsed.
...@@ -139,6 +139,33 @@ export default class AddUser extends Component { ...@@ -139,6 +139,33 @@ export default class AddUser extends Component {
} }
clearError() { clearError() {
let listCompany = this.state.listCompany
let company = this.state.company
const handlePushChild = (item) => {
let indexIDzz = company.findIndex((val) => val === item.id)
if (indexIDzz === -1) {
company.push(item.id)
}
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items,indexs) => {
handlePushChild(items)
})
}
}
}
listCompany.map((item, index) => {
company.push(item.id)
handlePushChild(item)
})
let uniqueCompany = company.filter((val, id, array) => {
return array.indexOf(val) == id;
});
company = this.state.role.role_id === 1? uniqueCompany : []
// console.log(uniqueCompany)
this.setState({ this.setState({
errorFullname: false, errorFullname: false,
errorEmail: false, errorEmail: false,
...@@ -150,6 +177,9 @@ export default class AddUser extends Component { ...@@ -150,6 +177,9 @@ export default class AddUser extends Component {
msgErrorRN: '', msgErrorRN: '',
msgErrorSD: '', msgErrorSD: '',
msgErrorED: '', msgErrorED: '',
company
}, () => {
console.log(this.state.company)
}) })
} }
...@@ -262,41 +292,58 @@ export default class AddUser extends Component { ...@@ -262,41 +292,58 @@ export default class AddUser extends Component {
handleItemClick(item) { handleItemClick(item) {
let indexID = this.state.company.findIndex((val) => val === item.id) let indexID = this.state.company.findIndex((val) => val === item.id)
let listCompany = this.state.listCompany
let company = this.state.company let company = this.state.company
if (indexID === -1) { const handlePushChild = (item) => {
company.push(item.id) let indexIDzz = company.findIndex((val) => val === item.id)
if (item.parent !== null) { if (indexIDzz === -1) {
let indexIDs = this.state.company.findIndex((val) => val === item.parent) company.push(item.id)
if (indexIDs === -1) { }
company.push(item.parent) if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items,indexs) => {
handlePushChild(items)
})
} }
} }
}
const handleSpliceChild = (item) => {
let indexIDzz = company.findIndex((val) => val === item.id)
if (indexIDzz !== -1) {
company.splice(indexIDzz, 1)
}
if (item.children !== null) { if (item.children !== null) {
if (item.children.length > 0) { if (item.children.length > 0) {
item.children.map((items, indexs) => { item.children.map((items,indexs) => {
this.handleItemClick(items) handleSpliceChild(items)
}) })
} }
} }
}
if (indexID === -1) {
company.push(item.id)
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items,indexs) => {
handlePushChild(items)
})
}
}
} else { } else {
company.splice(indexID, 1) company.splice(indexID, 1)
if (item.parent !== null) { if (item.children !== null) {
let indexIDs = this.state.company.findIndex((val) => val === item.parent) if (item.children.length > 0) {
if (indexIDs !== -1) { item.children.map((items,indexs) => {
company.splice(indexIDs, 1) handleSpliceChild(items)
} })
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items, indexs) => {
this.handleItemClick(items)
})
}
} }
} }
} }
this.setState({ company })
// console.log(company)
this.setState({ company})
} }
renderChildren = (item, pad) => { renderChildren = (item, pad) => {
...@@ -570,7 +617,7 @@ export default class AddUser extends Component { ...@@ -570,7 +617,7 @@ export default class AddUser extends Component {
margin="normal" margin="normal"
id="startDate" id="startDate"
label="Valid From" label="Valid From"
format="dd MMMM yyyy" format="dd-MM-yyyy"
value={this.state.startDate} value={this.state.startDate}
error={this.state.errorStartDate} error={this.state.errorStartDate}
helperText={this.state.msgErrorSD} helperText={this.state.msgErrorSD}
...@@ -603,7 +650,7 @@ export default class AddUser extends Component { ...@@ -603,7 +650,7 @@ export default class AddUser extends Component {
margin="normal" margin="normal"
id="endDate" id="endDate"
label="Valid To" label="Valid To"
format="dd MMMM yyyy" format="dd-MM-yyyy"
value={this.state.endDate} value={this.state.endDate}
error={this.state.errorEndDate} error={this.state.errorEndDate}
helperText={this.state.msgErrorED} helperText={this.state.msgErrorED}
......
...@@ -123,6 +123,33 @@ export default class EditUser extends Component { ...@@ -123,6 +123,33 @@ export default class EditUser extends Component {
} }
clearError() { clearError() {
let listCompany = this.state.listCompany
let company = this.state.company
const handlePushChild = (item) => {
let indexIDzz = company.findIndex((val) => val === item.id)
if (indexIDzz === -1) {
company.push(item.id)
}
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items,indexs) => {
handlePushChild(items)
})
}
}
}
listCompany.map((item, index) => {
company.push(item.id)
handlePushChild(item)
})
let uniqueCompany = company.filter((val, id, array) => {
return array.indexOf(val) == id;
});
company = this.state.role.role_id === 1? uniqueCompany : []
// console.log(uniqueCompany)
this.setState({ this.setState({
errorFullname: false, errorFullname: false,
errorEmail: false, errorEmail: false,
...@@ -134,6 +161,7 @@ export default class EditUser extends Component { ...@@ -134,6 +161,7 @@ export default class EditUser extends Component {
msgErrorRN: '', msgErrorRN: '',
msgErrorSD: '', msgErrorSD: '',
msgErrorED: '', msgErrorED: '',
company
}) })
} }
...@@ -251,7 +279,10 @@ export default class EditUser extends Component { ...@@ -251,7 +279,10 @@ export default class EditUser extends Component {
if (response.data) { if (response.data) {
if (response.ok) { if (response.ok) {
if (response.data.status === 'success') { if (response.data.status === 'success') {
this.setState({ listCompany: response.data.data }) let dataBaru = response.data.data.map((item,index) => {
return {...item, check: false}
})
this.setState({ listCompany: dataBaru })
} else { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Token")) { if (response.data.message.includes("Token")) {
...@@ -279,40 +310,57 @@ export default class EditUser extends Component { ...@@ -279,40 +310,57 @@ export default class EditUser extends Component {
handleItemClick(item) { handleItemClick(item) {
let indexID = this.state.company.findIndex((val) => val === item.id) let indexID = this.state.company.findIndex((val) => val === item.id)
let company = this.state.company let company = this.state.company
if (indexID === -1) { const handlePushChild = (item) => {
company.push(item.id) let indexIDzz = company.findIndex((val) => val === item.id)
if (item.parent !== null) { if (indexIDzz === -1) {
let indexIDs = this.state.company.findIndex((val) => val === item.parent) company.push(item.id)
if (indexIDs === -1) { }
company.push(item.parent) if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items,indexs) => {
handlePushChild(items)
})
} }
} }
}
const handleSpliceChild = (item) => {
let indexIDzz = company.findIndex((val) => val === item.id)
if (indexIDzz !== -1) {
company.splice(indexIDzz, 1)
}
if (item.children !== null) { if (item.children !== null) {
if (item.children.length > 0) { if (item.children.length > 0) {
item.children.map((items,indexs) => { item.children.map((items,indexs) => {
this.handleItemClick(items) handleSpliceChild(items)
}) })
} }
} }
} else { }
company.splice(indexID, 1)
if (item.parent !== null) { if (indexID === -1) {
let indexIDs = this.state.company.findIndex((val) => val === item.parent) company.push(item.id)
if (indexIDs !== -1) { if (item.children !== null) {
company.splice(indexIDs, 1) if (item.children.length > 0) {
item.children.map((items,indexs) => {
handlePushChild(items)
})
} }
} }
} else {
company.splice(indexID, 1)
if (item.children !== null) { if (item.children !== null) {
if (item.children.length > 0) { if (item.children.length > 0) {
item.children.map((items,indexs) => { item.children.map((items,indexs) => {
this.handleItemClick(items) handleSpliceChild(items)
}) })
} }
} }
} }
this.setState({ company })
// console.log(company)
this.setState({ company})
} }
renderChildren = (item, pad) => { renderChildren = (item, pad) => {
...@@ -583,7 +631,7 @@ export default class EditUser extends Component { ...@@ -583,7 +631,7 @@ export default class EditUser extends Component {
margin="normal" margin="normal"
id="startDate" id="startDate"
label="Valid From" label="Valid From"
format="dd MMMM yyyy" format="dd-MM-yyyy"
value={this.state.tempData === null ? null : this.state.tempData.start_date} value={this.state.tempData === null ? null : this.state.tempData.start_date}
error={this.state.errorStartDate} error={this.state.errorStartDate}
helperText={this.state.msgErrorSD} helperText={this.state.msgErrorSD}
...@@ -615,7 +663,7 @@ export default class EditUser extends Component { ...@@ -615,7 +663,7 @@ export default class EditUser extends Component {
margin="normal" margin="normal"
id="endDate" id="endDate"
label="Valid To" label="Valid To"
format="dd MMMM yyyy" format="dd-MM-yyyy"
value={this.state.tempData === null ? null : this.state.tempData.end_date} value={this.state.tempData === null ? null : this.state.tempData.end_date}
error={this.state.errorEndDate} error={this.state.errorEndDate}
helperText={this.state.msgErrorED} helperText={this.state.msgErrorED}
......
...@@ -161,6 +161,33 @@ class UserRole extends Component { ...@@ -161,6 +161,33 @@ class UserRole extends Component {
this.setState({ alert: false }) this.setState({ alert: false })
} }
deleteRole() {
let data = this.state.rowData
api.create().deleteRole(data[1]).then((response) => {
if (response.data) {
if (response.ok) {
if (response.data.status === 'success') {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success', popupDel: false })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', popupDel: false }, () => {
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', popupDel: false })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', popupDel: false })
}
this.getRole()
})
}
render() { render() {
const columns = [{ const columns = [{
name: "Action", name: "Action",
...@@ -186,9 +213,24 @@ class UserRole extends Component { ...@@ -186,9 +213,24 @@ class UserRole extends Component {
null null
} }
</div > </div >
</button> </button>
)} )}
{this.state.buttonEdit && (
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
marginLeft: 10
}}
onClick={() => this.setState({popupDel: true, rowData: tableMeta.rowData})}
>
{tableMeta.rowData[2] !== "superadmin" ?
<img src={Images.delete} /> :
null
}
</button>
)}
</div > </div >
); );
} }
...@@ -317,6 +359,38 @@ class UserRole extends Component { ...@@ -317,6 +359,38 @@ class UserRole extends Component {
data={this.state.indexData} data={this.state.indexData}
/> />
)} )}
{this.state.popupDel && (
<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.rowData[2]} ?
</span>
{/* <span style={{ textAlign: 'center', fontSize: 14, fontWeight: 'bold' }}>
{`Please try again later.`}
</span> */}
</div>
<div style={{ display: 'flex', justifyContent: 'center', marginTop: 24 }}>
<button
className={"btn-save"}
onClick={()=> this.setState({popupDel: false})}
>
<span style={{ color: 'white' }}>Cancel</span>
</button>
<button
className={"btn-save"}
style={{ marginLeft: 50}}
onClick={()=> this.deleteRole()}
>
<span style={{ color: 'white' }}>Delete</span>
</button>
</div>
</div>
</div>
)}
</div> </div>
); );
} }
......
This diff is collapsed.
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