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

ketinggalan

parent 558b9471
...@@ -15,6 +15,7 @@ import { ExcelRenderer } from 'react-excel-renderer'; ...@@ -15,6 +15,7 @@ import { ExcelRenderer } from 'react-excel-renderer';
import ReactTooltip from "react-tooltip"; import ReactTooltip from "react-tooltip";
import PopUpFailedSave from "../../library/PopUpFailedSave"; import PopUpFailedSave from "../../library/PopUpFailedSave";
import Constant from "../../library/Constant"; import Constant from "../../library/Constant";
import PopUpDelete from "../ApprovalMatrix/PopUpDelete";
var ct = require("../../library/CustomTable"); var ct = require("../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable()); const getMuiTheme = () => createMuiTheme(ct.customTable());
...@@ -31,6 +32,7 @@ export default class UserRole extends Component { ...@@ -31,6 +32,7 @@ export default class UserRole extends Component {
indexData: {}, indexData: {},
add: false, add: false,
edit: false, edit: false,
popupDel: false,
visibleUser: true, visibleUser: true,
buttonError: false, buttonError: false,
alert: false, alert: false,
...@@ -153,11 +155,11 @@ export default class UserRole extends Component { ...@@ -153,11 +155,11 @@ export default class UserRole extends Component {
if (item.length > 0) { if (item.length > 0) {
payload.push({ payload.push({
id: index + 1, id: index + 1,
fullname: item[0], fullname: item[0] == undefined? '' : item[0],
email: item[1], email: item[1] == undefined? '' : item[1],
role: item[2], role: item[2] == undefined? '' : item[2],
start_date: item[3], start_date: item[3] == undefined? '' : item[3],
end_date: item[4], end_date: item[4] == undefined? '' : item[4],
}) })
} }
}) })
...@@ -170,6 +172,14 @@ export default class UserRole extends Component { ...@@ -170,6 +172,14 @@ export default class UserRole extends Component {
}); });
} }
deleteUser() {
let data = this.state.rowData
api.create().deleteUser(data[1]).then((response) => {
this.setState({popupDel: false})
this.getUser()
})
}
checkUpload(){ checkUpload(){
api.create().checkUploadUser(this.state.payload).then(response => { api.create().checkUploadUser(this.state.payload).then(response => {
console.log(response); console.log(response);
...@@ -190,7 +200,31 @@ export default class UserRole extends Component { ...@@ -190,7 +200,31 @@ export default class UserRole extends Component {
let columns = [ let columns = [
"Data", "Data",
"Full Name", {
name: "Full Name",
options: {
customBodyRender: (val, tableMeta) => {
let check = null
if (tableMeta.rowData[6] != null) {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('fullname'))
if (check > -1) {
this.setState({ buttonError: true })
console.log('masuk')
}
}
return (
<div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="fullname">
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val == ''? 'Empty' : val}</span>
</a> :
<span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val == ''? 'Empty' : val}</span>
}
<ReactTooltip border={true} id="fullname" place="bottom" type="light" effect="solid" />
</div >
);
}
}},
{ {
name: "Email", name: "Email",
options: { options: {
...@@ -207,9 +241,9 @@ export default class UserRole extends Component { ...@@ -207,9 +241,9 @@ export default class UserRole extends Component {
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ? {tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="email"> <a data-tip={tableMeta.rowData[6][check].message} data-for="email">
<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> : </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="email" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="email" place="bottom" type="light" effect="solid" />
</div > </div >
...@@ -226,16 +260,16 @@ export default class UserRole extends Component { ...@@ -226,16 +260,16 @@ export default class UserRole extends Component {
check = tableMeta.rowData[6].findIndex((val) => val.field.includes('role')) check = tableMeta.rowData[6].findIndex((val) => val.field.includes('role'))
if (check > -1) { if (check > -1) {
this.setState({ buttonError: true }) this.setState({ buttonError: true })
console.log('masuk') console.log(tableMeta.rowData[6])
} }
} }
return ( return (
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ? {tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="role"> <a data-tip={tableMeta.rowData[6][check].message} data-for="role">
<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> : </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="role" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="role" place="bottom" type="light" effect="solid" />
</div > </div >
...@@ -259,9 +293,9 @@ export default class UserRole extends Component { ...@@ -259,9 +293,9 @@ export default class UserRole extends Component {
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ? {tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="startdate"> <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> : </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" /> <ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" />
</div > </div >
...@@ -285,9 +319,9 @@ export default class UserRole extends Component { ...@@ -285,9 +319,9 @@ export default class UserRole extends Component {
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{tableMeta.rowData[6] != null && check > -1 ? {tableMeta.rowData[6] != null && check > -1 ?
<a data-tip={tableMeta.rowData[6][check].message} data-for="enddate"> <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> : </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" /> <ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
</div > </div >
...@@ -387,13 +421,14 @@ export default class UserRole extends Component { ...@@ -387,13 +421,14 @@ export default class UserRole extends Component {
} }
createUser(payload) { createUser(payload) {
console.log('Mode Create')
api.create().createUser(payload).then((response) => { api.create().createUser(payload).then((response) => {
// console.log(response) console.log(response.data)
// if (String(response.data.status).toLocaleUpperCase === 'Success' || String(response.data.status).toLocaleUpperCase === 'success') { // if (String(response.data.status).toLocaleUpperCase === 'Success' || String(response.data.status).toLocaleUpperCase === 'success') {
if (response.data) { if (response.data) {
if (response.ok) { if (response.ok) {
if (response.data.status === 'success') { if (response.data.status === 'Success') {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success', create: false }) this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success', add: false })
this.getUser() this.getUser()
} else { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
...@@ -483,6 +518,19 @@ export default class UserRole extends Component { ...@@ -483,6 +518,19 @@ export default class UserRole extends Component {
<img src={Images.editCopy} /> <img src={Images.editCopy} />
</button> </button>
)} )}
{this.state.buttonEdit && (
<button
style={{
backgroundColor: 'transparent',
cursor: 'pointer',
borderColor: 'transparent',
marginLeft: 10
}}
onClick={() => this.setState({popupDel: true, rowData: tableMeta.rowData})}
>
<img src={Images.delete} />
</button>
)}
{/* : {/* :
null null
} */} } */}
...@@ -665,7 +713,7 @@ export default class UserRole extends Component { ...@@ -665,7 +713,7 @@ export default class UserRole extends Component {
</a> </a>
<ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
{this.state.buttonCreate && ( {this.state.buttonCreate && (
<a data-tip={'Add New'} data-for="create"> <a data-tip={'Add New'} data-for="add">
<button <button
style={{ style={{
backgroundColor: 'transparent', backgroundColor: 'transparent',
...@@ -680,7 +728,7 @@ export default class UserRole extends Component { ...@@ -680,7 +728,7 @@ export default class UserRole extends Component {
</button> </button>
</a> </a>
)} )}
<ReactTooltip border={true} id="create" place="bottom" type="light" effect="solid" /> <ReactTooltip border={true} id="add" place="bottom" type="light" effect="solid" />
</div> </div>
</div> </div>
)} )}
...@@ -749,6 +797,38 @@ export default class UserRole extends Component { ...@@ -749,6 +797,38 @@ export default 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.deleteUser()}
>
<span style={{ color: 'white' }}>Delete</span>
</button>
</div>
</div>
</div>
)}
{this.state.popupError && ( {this.state.popupError && (
<PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} /> <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
)} )}
......
...@@ -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) => {
let indexIDzz = company.findIndex((val) => val === item.id)
if (indexIDzz === -1) {
company.push(item.id) company.push(item.id)
if (item.parent !== null) { }
let indexIDs = this.state.company.findIndex((val) => val === item.parent) if (item.children !== null) {
if (indexIDs === -1) { if (item.children.length > 0) {
company.push(item.parent) 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) {
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 !== null) {
if (item.children.length > 0) { if (item.children.length > 0) {
item.children.map((items, indexs) => { item.children.map((items,indexs) => {
this.handleItemClick(items) 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) => { 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) => {
let indexIDzz = company.findIndex((val) => val === item.id)
if (indexIDzz === -1) {
company.push(item.id) company.push(item.id)
if (item.parent !== null) { }
let indexIDs = this.state.company.findIndex((val) => val === item.parent) if (item.children !== null) {
if (indexIDs === -1) { if (item.children.length > 0) {
company.push(item.parent) 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,7 +213,22 @@ class UserRole extends Component { ...@@ -186,7 +213,22 @@ class UserRole extends Component {
null null
} }
</div > </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> </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>
); );
} }
......
...@@ -111,7 +111,7 @@ export default class AddRole extends Component { ...@@ -111,7 +111,7 @@ export default class AddRole extends Component {
validasi() { validasi() {
if (R.isEmpty(this.state.roleName)) { if (R.isEmpty(this.state.roleName)) {
this.setState({ errorRoleName: true, msgErrorRN: 'User Role Cannot be Empty.' }) this.setState({ errorRoleName: true, msgErrorRN: 'Role Cannot be Empty.' })
} else if (R.isNil(this.state.startDate)) { } else if (R.isNil(this.state.startDate)) {
this.setState({ errorStartDate: true, msgErrorSD: 'Valid From Cannot be Empty.' }) this.setState({ errorStartDate: true, msgErrorSD: 'Valid From Cannot be Empty.' })
} else if (R.isNil(this.state.endDate)) { } else if (R.isNil(this.state.endDate)) {
...@@ -225,7 +225,7 @@ export default class AddRole extends Component { ...@@ -225,7 +225,7 @@ export default class AddRole extends Component {
if (indexID === -1) { if (indexID === -1) {
privileges.push({ privileges.push({
menu_id: item.menu_id, menu_id: item.menu_id,
button_id: [1, 2, 3] button_id: [1, 2, 3, 4]
}) })
if (item.sub_menu.length > 0) { if (item.sub_menu.length > 0) {
item.sub_menu.map((items,indexs) => { item.sub_menu.map((items,indexs) => {
...@@ -233,7 +233,7 @@ export default class AddRole extends Component { ...@@ -233,7 +233,7 @@ export default class AddRole extends Component {
if (indexIDs === -1) { if (indexIDs === -1) {
privileges.push({ privileges.push({
menu_id: items.menu_id, menu_id: items.menu_id,
button_id: [1,2,3] button_id: [1,2,3,4]
}) })
} }
}) })
...@@ -255,7 +255,7 @@ export default class AddRole extends Component { ...@@ -255,7 +255,7 @@ export default class AddRole extends Component {
if (indexIDref == -1) { if (indexIDref == -1) {
privileges.push({ privileges.push({
menu_id: item.reference, menu_id: item.reference,
button_id: [1,2,3] button_id: [1,2,3,4]
}) })
} else { } else {
if (total < 1) { if (total < 1) {
...@@ -289,7 +289,7 @@ export default class AddRole extends Component { ...@@ -289,7 +289,7 @@ export default class AddRole extends Component {
if (indexIDref == -1) { if (indexIDref == -1) {
privileges.push({ privileges.push({
menu_id: item.reference, menu_id: item.reference,
button_id: [1,2,3] button_id: [1,2,3,4]
}) })
} else { } else {
if (total < 1) { if (total < 1) {
...@@ -298,7 +298,9 @@ export default class AddRole extends Component { ...@@ -298,7 +298,9 @@ export default class AddRole extends Component {
} }
} }
} }
this.setState({ privileges }) this.setState({ privileges }, () => {
console.log(this.state.privileges)
})
} }
handleSubItemChecked(item, index) { handleSubItemChecked(item, index) {
...@@ -322,16 +324,60 @@ export default class AddRole extends Component { ...@@ -322,16 +324,60 @@ export default class AddRole extends Component {
let indexButtonID = this.state.privileges[indexID].button_id.findIndex((val) => val === index) let indexButtonID = this.state.privileges[indexID].button_id.findIndex((val) => val === index)
let privileges = this.state.privileges let privileges = this.state.privileges
let button_id = privileges[indexID].button_id let button_id = privileges[indexID].button_id
// 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)
// })
// }
// }
// }
if (indexButtonID === -1) { if (indexButtonID === -1) {
button_id.push(index) button_id.push(index)
console.log(item)
if (item.sub_menu.length > 0) {
item.sub_menu.map((items,indexs) => {
let subIndexID = privileges.findIndex((val) => val.menu_id === items.menu_id)
if (subIndexID === -1) {
console.log('masuk pa eko', subIndexID)
privileges.push({
menu_id: items.menu_id,
button_id: [index]
})
} else {
let subIndexButtonID = privileges[subIndexID].button_id.findIndex((val) => val === index)
let subButton_id = []
console.log(subIndexButtonID, subButton_id)
if (subIndexButtonID === -1) {
subButton_id.push(index)
privileges[subIndexID].button_id = subButton_id
} else {
subButton_id = privileges[subIndexID].button_id
console.log(subButton_id)
subButton_id.splice(subIndexButtonID, 1)
privileges[subIndexID].button_id = subButton_id.sort((a,b) => a-b)
}
}
// let subIndexButtonID = privileges[subIndexID].button_id.findIndex((val) => val === indexs)
// let subButton_id = privileges[indexID].button_id
})
}
} else { } else {
button_id.splice(indexButtonID, 1) button_id.splice(indexButtonID, 1)
} }
privileges[indexID].button_id = button_id privileges[indexID].button_id = button_id.sort((a,b) => a-b)
if (button_id.length === 0) { if (button_id.length === 0) {
privileges.splice(indexID, 1) privileges.splice(indexID, 1)
} }
this.setState({ privileges }) this.setState({ privileges: privileges.sort((a,b) => a.menu_id-b.menu_id) }, () => {
console.log(this.state.privileges)
})
} }
handleDate(item) { handleDate(item) {
...@@ -456,7 +502,7 @@ export default class AddRole extends Component { ...@@ -456,7 +502,7 @@ export default class AddRole 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}
...@@ -489,7 +535,7 @@ export default class AddRole extends Component { ...@@ -489,7 +535,7 @@ export default class AddRole 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}
...@@ -564,7 +610,7 @@ export default class AddRole extends Component { ...@@ -564,7 +610,7 @@ export default class AddRole extends Component {
<div className="column-1"> <div className="column-1">
<Typography style={{ fontSize: 12, color: 'white' }}>Authorization Module</Typography> <Typography style={{ fontSize: 12, color: 'white' }}>Authorization Module</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px">
<div className="column-1"> <div className="column-1">
<Typography style={{ fontSize: 12, color: 'white' }}>View</Typography> <Typography style={{ fontSize: 12, color: 'white' }}>View</Typography>
</div> </div>
...@@ -574,6 +620,9 @@ export default class AddRole extends Component { ...@@ -574,6 +620,9 @@ export default class AddRole extends Component {
<div className="column 3"> <div className="column 3">
<Typography style={{ fontSize: 12, color: 'white' }}>Edit</Typography> <Typography style={{ fontSize: 12, color: 'white' }}>Edit</Typography>
</div> </div>
<div className="column 4">
<Typography style={{ fontSize: 12, color: 'white' }}>Delete</Typography>
</div>
</div> </div>
</div> </div>
...@@ -594,7 +643,7 @@ export default class AddRole extends Component { ...@@ -594,7 +643,7 @@ export default class AddRole extends Component {
</span> </span>
<Typography style={{ fontSize: 12, marginLeft: 5 }}>{item.label}</Typography> <Typography style={{ fontSize: 12, marginLeft: 5 }}>{item.label}</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px margin-left-10px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px margin-left-10px">
<div className="column-1"> <div className="column-1">
<CustomCheckbox <CustomCheckbox
disabled={!this.handleItemChecked(item)} disabled={!this.handleItemChecked(item)}
...@@ -618,6 +667,14 @@ export default class AddRole extends Component { ...@@ -618,6 +667,14 @@ export default class AddRole extends Component {
onChange={() => this.handleSubItemClick(item, 3)} onChange={() => this.handleSubItemClick(item, 3)}
/> />
</div> </div>
<div className="column 4">
<CustomCheckbox
// disabled
disabled={!this.handleItemChecked(item)}
checked={this.handleSubItemChecked(item, 4)}
onChange={() => this.handleSubItemClick(item, 4)}
/>
</div>
</div> </div>
</div> </div>
{item.sub_menu.length > 0 && item.sub_menu.map((items, indexs) => { {item.sub_menu.length > 0 && item.sub_menu.map((items, indexs) => {
...@@ -631,7 +688,7 @@ export default class AddRole extends Component { ...@@ -631,7 +688,7 @@ export default class AddRole extends Component {
/> />
<Typography style={{ fontSize: 12, maxWidth: '100%', marginLeft: 5 }}>{items.label}</Typography> <Typography style={{ fontSize: 12, maxWidth: '100%', marginLeft: 5 }}>{items.label}</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px margin-left-10px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px margin-left-10px">
<div className="column-1"> <div className="column-1">
<CustomCheckbox <CustomCheckbox
disabled={!this.handleItemChecked(items)} disabled={!this.handleItemChecked(items)}
...@@ -653,6 +710,13 @@ export default class AddRole extends Component { ...@@ -653,6 +710,13 @@ export default class AddRole extends Component {
onChange={() => this.handleSubItemClick(items, 3)} onChange={() => this.handleSubItemClick(items, 3)}
/> />
</div> </div>
<div className="column 4">
<CustomCheckbox
disabled={!this.handleItemChecked(items)}
checked={this.handleSubItemChecked(items, 4)}
onChange={() => this.handleSubItemClick(items, 4)}
/>
</div>
</div> </div>
</div> </div>
</Collapse> </Collapse>
...@@ -677,7 +741,7 @@ export default class AddRole extends Component { ...@@ -677,7 +741,7 @@ export default class AddRole extends Component {
</span> </span>
<Typography style={{ fontSize: 12, marginLeft: 5 }}>{item.label}</Typography> <Typography style={{ fontSize: 12, marginLeft: 5 }}>{item.label}</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px margin-left-10px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px margin-left-10px">
<div className="column-1"> <div className="column-1">
<CustomCheckbox <CustomCheckbox
disabled={!this.handleItemChecked(item)} disabled={!this.handleItemChecked(item)}
...@@ -701,6 +765,14 @@ export default class AddRole extends Component { ...@@ -701,6 +765,14 @@ export default class AddRole extends Component {
onChange={() => this.handleSubItemClick(item, 3)} onChange={() => this.handleSubItemClick(item, 3)}
/> />
</div> </div>
<div className="column 4">
<CustomCheckbox
// disabled
disabled={!this.handleItemChecked(item)}
checked={this.handleSubItemChecked(item, 4)}
onChange={() => this.handleSubItemClick(item, 4)}
/>
</div>
</div> </div>
</div>} </div>}
{item.sub_menu.length > 0 && item.sub_menu.map((items, indexs) => { {item.sub_menu.length > 0 && item.sub_menu.map((items, indexs) => {
...@@ -714,7 +786,7 @@ export default class AddRole extends Component { ...@@ -714,7 +786,7 @@ export default class AddRole extends Component {
/> />
<Typography style={{ fontSize: 12, maxWidth: '100%', marginLeft: 5 }}>{items.label}</Typography> <Typography style={{ fontSize: 12, maxWidth: '100%', marginLeft: 5 }}>{items.label}</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px margin-left-10px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px margin-left-10px">
<div className="column-1"> <div className="column-1">
<CustomCheckbox <CustomCheckbox
disabled={!this.handleItemChecked(items)} disabled={!this.handleItemChecked(items)}
...@@ -736,6 +808,13 @@ export default class AddRole extends Component { ...@@ -736,6 +808,13 @@ export default class AddRole extends Component {
onChange={() => this.handleSubItemClick(items, 3)} onChange={() => this.handleSubItemClick(items, 3)}
/> />
</div> </div>
<div className="column 4">
<CustomCheckbox
disabled={!this.handleItemChecked(items)}
checked={this.handleSubItemChecked(items, 4)}
onChange={() => this.handleSubItemClick(items, 4)}
/>
</div>
</div> </div>
</div> </div>
</Collapse> </Collapse>
......
...@@ -124,7 +124,7 @@ export default class EditRole extends Component { ...@@ -124,7 +124,7 @@ export default class EditRole extends Component {
validasi() { validasi() {
if (R.isEmpty(this.state.tempData.role_name)) { if (R.isEmpty(this.state.tempData.role_name)) {
this.setState({ errorRoleName: true, msgErrorRN: 'User Role Cannot be Empty.' }) this.setState({ errorRoleName: true, msgErrorRN: 'Role Cannot be Empty.' })
} else if (R.isNil(this.state.tempData.start_date)) { } else if (R.isNil(this.state.tempData.start_date)) {
this.setState({ errorStartDate: true, msgErrorSD: 'Valid From Cannot be Empty.' }) this.setState({ errorStartDate: true, msgErrorSD: 'Valid From Cannot be Empty.' })
} else if (R.isNil(this.state.tempData.end_date)) { } else if (R.isNil(this.state.tempData.end_date)) {
...@@ -142,15 +142,15 @@ export default class EditRole extends Component { ...@@ -142,15 +142,15 @@ export default class EditRole extends Component {
let privileges = this.state.privileges let privileges = this.state.privileges
privileges.push({ privileges.push({
menu_id: 23, menu_id: 23,
button_id: [1,2,3] button_id: [1,2,3,4]
}) })
privileges.push({ privileges.push({
menu_id: 24, menu_id: 24,
button_id: [1,2,3] button_id: [1,2,3,4]
}) })
privileges.push({ privileges.push({
menu_id: 25, menu_id: 25,
button_id: [1,2,3] button_id: [1,2,3,4]
}) })
let payload = { let payload = {
"role_id": this.state.tempData.role_id, "role_id": this.state.tempData.role_id,
...@@ -253,7 +253,7 @@ export default class EditRole extends Component { ...@@ -253,7 +253,7 @@ export default class EditRole extends Component {
if (indexID === -1) { if (indexID === -1) {
privileges.push({ privileges.push({
menu_id: item.menu_id, menu_id: item.menu_id,
button_id: [1, 2, 3] button_id: [1, 2, 3, 4]
}) })
if (item.sub_menu.length > 0) { if (item.sub_menu.length > 0) {
item.sub_menu.map((items,indexs) => { item.sub_menu.map((items,indexs) => {
...@@ -261,7 +261,7 @@ export default class EditRole extends Component { ...@@ -261,7 +261,7 @@ export default class EditRole extends Component {
if (indexIDs === -1) { if (indexIDs === -1) {
privileges.push({ privileges.push({
menu_id: items.menu_id, menu_id: items.menu_id,
button_id: [1,2,3] button_id: [1,2,3,4]
}) })
} }
}) })
...@@ -433,7 +433,7 @@ export default class EditRole extends Component { ...@@ -433,7 +433,7 @@ export default class EditRole 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}
...@@ -466,7 +466,7 @@ export default class EditRole extends Component { ...@@ -466,7 +466,7 @@ export default class EditRole 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}
...@@ -540,7 +540,7 @@ export default class EditRole extends Component { ...@@ -540,7 +540,7 @@ export default class EditRole extends Component {
<div className="column-1"> <div className="column-1">
<Typography style={{ fontSize: 12, color: 'white' }}>Authorization Module</Typography> <Typography style={{ fontSize: 12, color: 'white' }}>Authorization Module</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px">
<div className="column-1"> <div className="column-1">
<Typography style={{ fontSize: 12, color: 'white' }}>View</Typography> <Typography style={{ fontSize: 12, color: 'white' }}>View</Typography>
</div> </div>
...@@ -570,7 +570,7 @@ export default class EditRole extends Component { ...@@ -570,7 +570,7 @@ export default class EditRole extends Component {
</span> </span>
<Typography style={{ fontSize: 12, marginLeft: 5 }}>{item.label}</Typography> <Typography style={{ fontSize: 12, marginLeft: 5 }}>{item.label}</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px margin-left-10px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px margin-left-10px">
<div className="column-1"> <div className="column-1">
<CustomCheckbox <CustomCheckbox
disabled={!this.handleItemChecked(item)} disabled={!this.handleItemChecked(item)}
...@@ -594,6 +594,13 @@ export default class EditRole extends Component { ...@@ -594,6 +594,13 @@ export default class EditRole extends Component {
onChange={() => this.handleSubItemClick(item, 3)} onChange={() => this.handleSubItemClick(item, 3)}
/> />
</div> </div>
<div className="column 4">
<CustomCheckbox
disabled={!this.handleItemChecked(item)}
checked={this.handleSubItemChecked(item, 4)}
onChange={() => this.handleSubItemClick(item, 4)}
/>
</div>
</div> </div>
</div> </div>
{item.sub_menu.length > 0 && item.sub_menu.map((items, indexs) => { {item.sub_menu.length > 0 && item.sub_menu.map((items, indexs) => {
...@@ -607,7 +614,7 @@ export default class EditRole extends Component { ...@@ -607,7 +614,7 @@ export default class EditRole extends Component {
/> />
<Typography style={{ fontSize: 12, maxWidth: '100%', marginLeft: 5 }}>{items.label}</Typography> <Typography style={{ fontSize: 12, maxWidth: '100%', marginLeft: 5 }}>{items.label}</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px margin-left-10px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px margin-left-10px">
<div className="column-1"> <div className="column-1">
<CustomCheckbox <CustomCheckbox
disabled={!this.handleItemChecked(items)} disabled={!this.handleItemChecked(items)}
...@@ -629,6 +636,13 @@ export default class EditRole extends Component { ...@@ -629,6 +636,13 @@ export default class EditRole extends Component {
onChange={() => this.handleSubItemClick(items, 3)} onChange={() => this.handleSubItemClick(items, 3)}
/> />
</div> </div>
<div className="column 4">
<CustomCheckbox
disabled={!this.handleItemChecked(items)}
checked={this.handleSubItemChecked(items, 4)}
onChange={() => this.handleSubItemClick(items, 4)}
/>
</div>
</div> </div>
</div> </div>
</Collapse> </Collapse>
...@@ -653,7 +667,7 @@ export default class EditRole extends Component { ...@@ -653,7 +667,7 @@ export default class EditRole extends Component {
</span> </span>
<Typography style={{ fontSize: 12, marginLeft: 5 }}>{item.label}</Typography> <Typography style={{ fontSize: 12, marginLeft: 5 }}>{item.label}</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px margin-left-10px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px margin-left-10px">
<div className="column-1"> <div className="column-1">
<CustomCheckbox <CustomCheckbox
disabled={!this.handleItemChecked(item)} disabled={!this.handleItemChecked(item)}
...@@ -677,6 +691,13 @@ export default class EditRole extends Component { ...@@ -677,6 +691,13 @@ export default class EditRole extends Component {
onChange={() => this.handleSubItemClick(item, 3)} onChange={() => this.handleSubItemClick(item, 3)}
/> />
</div> </div>
<div className="column 4">
<CustomCheckbox
disabled={!this.handleItemChecked(item)}
checked={this.handleSubItemChecked(item, 4)}
onChange={() => this.handleSubItemClick(item, 4)}
/>
</div>
</div> </div>
</div>} </div>}
{item.sub_menu.length > 0 && item.sub_menu.map((items, indexs) => { {item.sub_menu.length > 0 && item.sub_menu.map((items, indexs) => {
...@@ -690,7 +711,7 @@ export default class EditRole extends Component { ...@@ -690,7 +711,7 @@ export default class EditRole extends Component {
/> />
<Typography style={{ fontSize: 12, maxWidth: '100%', marginLeft: 5 }}>{items.label}</Typography> <Typography style={{ fontSize: 12, maxWidth: '100%', marginLeft: 5 }}>{items.label}</Typography>
</div> </div>
<div className="column-2 grid grid-3x content-center grid-mobile-none gap-15px margin-left-10px"> <div className="column-2 grid grid-4x content-center grid-mobile-none gap-15px margin-left-10px">
<div className="column-1"> <div className="column-1">
<CustomCheckbox <CustomCheckbox
disabled={!this.handleItemChecked(items)} disabled={!this.handleItemChecked(items)}
...@@ -712,6 +733,13 @@ export default class EditRole extends Component { ...@@ -712,6 +733,13 @@ export default class EditRole extends Component {
onChange={() => this.handleSubItemClick(items, 3)} onChange={() => this.handleSubItemClick(items, 3)}
/> />
</div> </div>
<div className="column 4">
<CustomCheckbox
disabled={!this.handleItemChecked(items)}
checked={this.handleSubItemChecked(items, 4)}
onChange={() => this.handleSubItemClick(items, 4)}
/>
</div>
</div> </div>
</div> </div>
</Collapse> </Collapse>
......
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