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 {
}
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({
errorFullname: false,
errorEmail: false,
......@@ -150,6 +177,9 @@ export default class AddUser extends Component {
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
company
}, () => {
console.log(this.state.company)
})
}
......@@ -262,41 +292,58 @@ export default class AddUser extends Component {
handleItemClick(item) {
let indexID = this.state.company.findIndex((val) => val === item.id)
let listCompany = this.state.listCompany
let company = this.state.company
if (indexID === -1) {
const handlePushChild = (item) => {
let indexIDzz = company.findIndex((val) => val === item.id)
if (indexIDzz === -1) {
company.push(item.id)
if (item.parent !== null) {
let indexIDs = this.state.company.findIndex((val) => val === item.parent)
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.length > 0) {
item.children.map((items, indexs) => {
this.handleItemClick(items)
item.children.map((items,indexs) => {
handleSpliceChild(items)
})
}
}
} else {
company.splice(indexID, 1)
if (item.parent !== null) {
let indexIDs = this.state.company.findIndex((val) => val === item.parent)
if (indexIDs !== -1) {
company.splice(indexIDs, 1)
}
if (indexID === -1) {
company.push(item.id)
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items, indexs) => {
this.handleItemClick(items)
item.children.map((items,indexs) => {
handlePushChild(items)
})
}
}
} else {
company.splice(indexID, 1)
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items,indexs) => {
handleSpliceChild(items)
})
}
}
this.setState({ company })
}
// console.log(company)
this.setState({ company})
}
renderChildren = (item, pad) => {
......@@ -570,7 +617,7 @@ export default class AddUser extends Component {
margin="normal"
id="startDate"
label="Valid From"
format="dd MMMM yyyy"
format="dd-MM-yyyy"
value={this.state.startDate}
error={this.state.errorStartDate}
helperText={this.state.msgErrorSD}
......@@ -603,7 +650,7 @@ export default class AddUser extends Component {
margin="normal"
id="endDate"
label="Valid To"
format="dd MMMM yyyy"
format="dd-MM-yyyy"
value={this.state.endDate}
error={this.state.errorEndDate}
helperText={this.state.msgErrorED}
......
......@@ -123,6 +123,33 @@ export default class EditUser extends Component {
}
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({
errorFullname: false,
errorEmail: false,
......@@ -134,6 +161,7 @@ export default class EditUser extends Component {
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
company
})
}
......@@ -251,7 +279,10 @@ export default class EditUser extends Component {
if (response.data) {
if (response.ok) {
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 {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Token")) {
......@@ -279,40 +310,57 @@ export default class EditUser extends Component {
handleItemClick(item) {
let indexID = this.state.company.findIndex((val) => val === item.id)
let company = this.state.company
if (indexID === -1) {
const handlePushChild = (item) => {
let indexIDzz = company.findIndex((val) => val === item.id)
if (indexIDzz === -1) {
company.push(item.id)
if (item.parent !== null) {
let indexIDs = this.state.company.findIndex((val) => val === item.parent)
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.length > 0) {
item.children.map((items,indexs) => {
this.handleItemClick(items)
handleSpliceChild(items)
})
}
}
} else {
company.splice(indexID, 1)
if (item.parent !== null) {
let indexIDs = this.state.company.findIndex((val) => val === item.parent)
if (indexIDs !== -1) {
company.splice(indexIDs, 1)
}
if (indexID === -1) {
company.push(item.id)
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items,indexs) => {
handlePushChild(items)
})
}
}
} else {
company.splice(indexID, 1)
if (item.children !== null) {
if (item.children.length > 0) {
item.children.map((items,indexs) => {
this.handleItemClick(items)
handleSpliceChild(items)
})
}
}
}
this.setState({ company })
// console.log(company)
this.setState({ company})
}
renderChildren = (item, pad) => {
......@@ -583,7 +631,7 @@ export default class EditUser extends Component {
margin="normal"
id="startDate"
label="Valid From"
format="dd MMMM yyyy"
format="dd-MM-yyyy"
value={this.state.tempData === null ? null : this.state.tempData.start_date}
error={this.state.errorStartDate}
helperText={this.state.msgErrorSD}
......@@ -615,7 +663,7 @@ export default class EditUser extends Component {
margin="normal"
id="endDate"
label="Valid To"
format="dd MMMM yyyy"
format="dd-MM-yyyy"
value={this.state.tempData === null ? null : this.state.tempData.end_date}
error={this.state.errorEndDate}
helperText={this.state.msgErrorED}
......
......@@ -161,6 +161,33 @@ class UserRole extends Component {
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() {
const columns = [{
name: "Action",
......@@ -186,7 +213,22 @@ class UserRole extends Component {
null
}
</div >
</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 >
......@@ -317,6 +359,38 @@ class UserRole extends Component {
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>
);
}
......
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