EditUser.js 37.4 KB
Newer Older
d.arizona's avatar
d.arizona committed
1
import React, { Component } from 'react';
a.bairuha's avatar
a.bairuha committed
2
import { TextField, Divider, Typography, Checkbox, withStyles, Collapse, Snackbar } from '@material-ui/core';
d.arizona's avatar
d.arizona committed
3
import api from '../../../api';
d.arizona's avatar
d.arizona committed
4 5
import { titleCase } from '../../../library/Utils';
import Autocomplete from '@material-ui/lab/Autocomplete';
d.arizona's avatar
d.arizona committed
6 7 8 9
import { DatePicker } from '@material-ui/pickers';
import format from "date-fns/format";
import RemoveIcon from '@material-ui/icons/Remove';
import AddIcon from '@material-ui/icons/Add';
d.arizona's avatar
d.arizona committed
10
import * as R from 'ramda'
d.arizona's avatar
d.arizona committed
11
import Images from '../../../assets/Images';
a.bairuha's avatar
a.bairuha committed
12
import MuiAlert from '@material-ui/lab/Alert';
a.bairuha's avatar
a.bairuha committed
13
import Constant from '../../../library/Constant';
d.arizona's avatar
d.arizona committed
14 15 16 17

const CustomCheckbox = withStyles({
    root: {
        color: '#51c6ea',
Deni Rinaldi's avatar
Deni Rinaldi committed
18 19 20
        '&$checked': {
            color: '#51c6ea',
        },
d.arizona's avatar
d.arizona committed
21 22
    },
    checked: {},
Deni Rinaldi's avatar
Deni Rinaldi committed
23
})((props) => <Checkbox color="default" {...props} />);
d.arizona's avatar
d.arizona committed
24

Deni Rinaldi's avatar
Deni Rinaldi committed
25 26 27 28 29 30 31 32 33 34
const CustomCheckboxDisabled = withStyles({
    root: {
        color: '#d5d5d5',
        '&$checked': {
            color: '#d5d5d5',
        },
    },
    checked: {},
})((props) => <Checkbox color="default" {...props} />);

a.bairuha's avatar
a.bairuha committed
35 36 37
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);

d.arizona's avatar
d.arizona committed
38
export default class EditUser extends Component {
Deni Rinaldi's avatar
Deni Rinaldi committed
39

d.arizona's avatar
d.arizona committed
40 41 42 43 44 45
    constructor(props) {
        super(props)
        this.state = {
            paramsId: this.props.data,
            tempData: null,
            menuData: null,
d.arizona's avatar
d.arizona committed
46 47 48 49
            checked: false,
            listRole: null,
            role: null,
            company: [],
d.arizona's avatar
d.arizona committed
50 51 52 53 54 55 56 57 58 59 60 61
            listCompany: [],
            selectedIndex: 0,
            errorFullname: false,
            errorEmail: false,
            errorRoleName: false,
            errorStartDate: false,
            errorEndDate: false,
            msgErrorFN: '',
            msgErrorEM: '',
            msgErrorRN: '',
            msgErrorSD: '',
            msgErrorED: '',
a.bairuha's avatar
a.bairuha committed
62 63 64
            alert: false,
            tipeAlert: '',
            messageAlert: ''
d.arizona's avatar
d.arizona committed
65 66 67 68
        }
    }

    handleChecked() {
Deni Rinaldi's avatar
Deni Rinaldi committed
69
        this.setState({ checked: !this.state.checked })
d.arizona's avatar
d.arizona committed
70
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
71

d.arizona's avatar
d.arizona committed
72
    componentDidMount() {
d.arizona's avatar
d.arizona committed
73
        this.getDetailUser()
d.arizona's avatar
d.arizona committed
74
        this.getPerusahaan()
d.arizona's avatar
d.arizona committed
75 76
    }

d.arizona's avatar
d.arizona committed
77
    handleChange(e, type) {
d.arizona's avatar
d.arizona committed
78
        let data = this.state
d.arizona's avatar
d.arizona committed
79
        let isDate = type !== '' ? true : false
d.arizona's avatar
d.arizona committed
80
        if (isDate && type === 'start_date') {
Deni Rinaldi's avatar
Deni Rinaldi committed
81 82
            this.setState({
                ...data, tempData: { ...this.state.tempData, start_date: format(e, 'yyyy-MM-dd'), end_date: null },
d.arizona's avatar
d.arizona committed
83
                errorFullname: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
84
                errorEmail: false,
d.arizona's avatar
d.arizona committed
85 86 87
                errorRoleName: false,
                errorStartDate: false,
                errorEndDate: false,
d.arizona's avatar
d.arizona committed
88 89
                msgErrorFN: '',
                msgErrorEM: '',
d.arizona's avatar
d.arizona committed
90 91 92 93
                msgErrorRN: '',
                msgErrorSD: '',
                msgErrorED: '',
            })
d.arizona's avatar
d.arizona committed
94
        } else if (isDate && type === 'end_date') {
Deni Rinaldi's avatar
Deni Rinaldi committed
95 96
            this.setState({
                ...data, tempData: { ...this.state.tempData, end_date: format(e, 'yyyy-MM-dd') },
d.arizona's avatar
d.arizona committed
97
                errorFullname: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
98
                errorEmail: false,
d.arizona's avatar
d.arizona committed
99 100 101
                errorRoleName: false,
                errorStartDate: false,
                errorEndDate: false,
d.arizona's avatar
d.arizona committed
102 103
                msgErrorFN: '',
                msgErrorEM: '',
d.arizona's avatar
d.arizona committed
104 105 106 107 108
                msgErrorRN: '',
                msgErrorSD: '',
                msgErrorED: '',
            })
        } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
109 110
            this.setState({
                ...data, tempData: { ...this.state.tempData, [e.target.name]: e.target.value },
d.arizona's avatar
d.arizona committed
111
                errorFullname: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
112
                errorEmail: false,
d.arizona's avatar
d.arizona committed
113 114 115
                errorRoleName: false,
                errorStartDate: false,
                errorEndDate: false,
d.arizona's avatar
d.arizona committed
116 117
                msgErrorFN: '',
                msgErrorEM: '',
d.arizona's avatar
d.arizona committed
118 119
                msgErrorRN: '',
                msgErrorSD: '',
d.arizona's avatar
d.arizona committed
120
                msgErrorED: '',
d.arizona's avatar
d.arizona committed
121 122
            })
        }
d.arizona's avatar
d.arizona committed
123 124
    }

a.bairuha's avatar
a.bairuha committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    clearError() {
        this.setState({
            errorFullname: false,
            errorEmail: false,
            errorRoleName: false,
            errorStartDate: false,
            errorEndDate: false,
            msgErrorFN: '',
            msgErrorEM: '',
            msgErrorRN: '',
            msgErrorSD: '',
            msgErrorED: '',
        })
    }

d.arizona's avatar
d.arizona committed
140 141
    getDetailUser() {
        api.create().getDetailUser(this.state.paramsId).then((response) => {
a.bairuha's avatar
a.bairuha committed
142 143 144
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
145 146
                        this.setState({ tempData: response.data.data, company: response.data.data.company }, ()=> 
                        this.getRole(response.data.data.role_id))
a.bairuha's avatar
a.bairuha committed
147 148
                        console.log(response.data.data)
                    } else {
a.bairuha's avatar
a.bairuha committed
149 150 151 152 153 154 155 156
                        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);
                            }
                        })
a.bairuha's avatar
a.bairuha committed
157 158 159 160
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
d.arizona's avatar
d.arizona committed
161
            } else {
a.bairuha's avatar
a.bairuha committed
162
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
163 164 165 166
            }
        })
    }

a.bairuha's avatar
a.bairuha committed
167 168 169 170 171
    isEmail(email) {
        const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(String(email).toLowerCase());
    }

d.arizona's avatar
d.arizona committed
172
    validasi() {
a.bairuha's avatar
a.bairuha committed
173 174 175
        var isEmail = this.isEmail(this.state.tempData.email)
        // console.log(this.state.tempData)

d.arizona's avatar
d.arizona committed
176
        if (R.isEmpty(this.state.tempData.fullname)) {
177
            this.setState({ errorFullname: true, msgErrorFN: 'Full Name Cannot be Empty.' })
d.arizona's avatar
d.arizona committed
178
        } else if (R.isEmpty(this.state.tempData.email)) {
179
            this.setState({ errorEmail: true, msgErrorEM: 'Email Cannot be Empty.' })
a.bairuha's avatar
a.bairuha committed
180
        } else if (!isEmail) {
Deni Rinaldi's avatar
Deni Rinaldi committed
181
            this.setState({ errorEmail: true, msgErrorEM: 'Please enter a valid email address.' })
a.bairuha's avatar
a.bairuha committed
182
        } else if (R.isNil(this.state.role)) {
Deni Rinaldi's avatar
Deni Rinaldi committed
183
            this.setState({ errorRoleName: true, msgErrorRN: 'Role Cannot be Empty.' })
d.arizona's avatar
d.arizona committed
184
        } else if (R.isNil(this.state.tempData.start_date)) {
185
            this.setState({ errorStartDate: true, msgErrorSD: 'Valid From Cannot be Empty.' })
d.arizona's avatar
d.arizona committed
186
        } else if (R.isNil(this.state.tempData.end_date)) {
187
            this.setState({ errorEndDate: true, msgErrorED: 'Valid To Cannot be Empty.' })
Deni Rinaldi's avatar
Deni Rinaldi committed
188
        }
d.arizona's avatar
d.arizona committed
189 190 191 192 193 194
        // else if (this.state.privileges.length < 1) {
        //     alert('Hak Akses belum di pilih !!')
        // } 
        else {
            this.updateUser()
        }
d.arizona's avatar
d.arizona committed
195
    }
d.arizona's avatar
d.arizona committed
196

Deni Rinaldi's avatar
Deni Rinaldi committed
197
    updateUser(){
d.arizona's avatar
d.arizona committed
198
        let payload = {
d.arizona's avatar
d.arizona committed
199 200 201 202 203 204 205
            "user_id": this.state.tempData.user_id,
            "role_id": this.state.role.role_id,
            "email": this.state.tempData.email,
            "fullname": this.state.tempData.fullname,
            "company": this.state.company,
            "start_date": this.state.tempData.start_date,
            "end_date": this.state.tempData.end_date
d.arizona's avatar
d.arizona committed
206
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
207
        this.props.updateUser(payload)
d.arizona's avatar
d.arizona committed
208 209
    }

210
    getRole(id) {
211
        api.create().getRoleActive().then((response) => {
a.bairuha's avatar
a.bairuha committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        let data = response.data.data
                        let roleData = data.map((item) => {
                            return {
                                role_id: item.role_id,
                                role_name: item.role_name
                            }
                        })
                        let defaultProps = {
                            options: roleData,
                            getOptionLabel: (option) => titleCase(option.role_name),
                        };
d.arizona's avatar
d.arizona committed
226

227 228 229
                        let index = roleData.findIndex((val) => val.role_id === id)
                        console.log(index)
                        this.setState({ listRole: defaultProps, role: index === -1 ? null : roleData[index], msgErrorRN: index === -1 ? 'Role has been inactive' : '', errorRoleName: index === -1 ? true : false })
a.bairuha's avatar
a.bairuha committed
230
                    } else {
a.bairuha's avatar
a.bairuha committed
231 232 233 234 235 236 237 238
                        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);
                            }
                        })
a.bairuha's avatar
a.bairuha committed
239 240 241 242
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
d.arizona's avatar
d.arizona committed
243
            } else {
a.bairuha's avatar
a.bairuha committed
244
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
245
            }
d.arizona's avatar
d.arizona committed
246
        })
d.arizona's avatar
d.arizona committed
247 248
    }

d.arizona's avatar
d.arizona committed
249 250
    getPerusahaan() {
        api.create().getPerusahaanHierarki().then((response) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
251
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
252 253 254 255
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ listCompany: response.data.data })
                    } else {
a.bairuha's avatar
a.bairuha committed
256 257 258 259 260 261 262 263
                        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);
                            }
                        })
a.bairuha's avatar
a.bairuha committed
264 265 266
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
Deni Rinaldi's avatar
Deni Rinaldi committed
267 268
                }
            } else {
a.bairuha's avatar
a.bairuha committed
269
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
270 271 272 273 274
            }
        })
    }

    handleItemChecked(item) {
d.arizona's avatar
d.arizona committed
275
        let indexID = this.state.company.findIndex((val) => val === item.id)
d.arizona's avatar
d.arizona committed
276
        return indexID === -1 ? false : true
d.arizona's avatar
d.arizona committed
277 278 279
    }

    handleItemClick(item) {
d.arizona's avatar
d.arizona committed
280
        let indexID = this.state.company.findIndex((val) => val === item.id)
d.arizona's avatar
d.arizona committed
281
        let company = this.state.company
d.arizona's avatar
d.arizona committed
282
        if (indexID === -1) {
d.arizona's avatar
d.arizona committed
283
            company.push(item.id)
d.arizona's avatar
d.arizona committed
284 285 286 287 288 289 290 291 292 293 294 295 296 297
            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) => {
                        this.handleItemClick(items)
                    })
                }
            }
d.arizona's avatar
d.arizona committed
298 299
        } else {
            company.splice(indexID, 1)
d.arizona's avatar
d.arizona committed
300 301 302 303
            if (item.parent !== null) {
                let indexIDs = this.state.company.findIndex((val) => val === item.parent)
                if (indexIDs !== -1) {
                    company.splice(indexIDs, 1)
d.arizona's avatar
d.arizona committed
304 305 306 307 308 309 310 311
                }
            }

            if (item.children !== null) {
                if (item.children.length > 0) {
                    item.children.map((items,indexs) => {
                        this.handleItemClick(items)
                    })
d.arizona's avatar
d.arizona committed
312 313
                }
            }
d.arizona's avatar
d.arizona committed
314 315 316
        }
        this.setState({ company })
    }
d.arizona's avatar
d.arizona committed
317

Deni Rinaldi's avatar
Deni Rinaldi committed
318 319 320 321 322
    renderChildren = (item, pad) => {
        let padding = null
        if (pad !== undefined) {
            padding = pad
        } else {
d.arizona's avatar
d.arizona committed
323
            padding = 30
Deni Rinaldi's avatar
Deni Rinaldi committed
324
        }
d.arizona's avatar
d.arizona committed
325
        return (
a.bairuha's avatar
a.bairuha committed
326 327 328 329 330 331 332
            <div>
                {item.children.length > 0 && (
                    <ul>
                        {item.children.map((data, index) => {
                            return (
                                // <li>
                                <Collapse key={index} timeout="auto" unmountOnExit in={item.collapse}>
d.arizona's avatar
d.arizona committed
333
                                    <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start', paddingLeft: !R.isNil(data.children)? (data.children.length > 0? padding : padding + 30) : padding + 30}}>
a.bairuha's avatar
a.bairuha committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
                                        {R.isNil(data.children) ?
                                            null
                                            :
                                            data.children.length < 1 ?
                                                null
                                                :
                                                <span onClick={() => this.handleCollapse(data)} style={{ marginLeft: 7, marginRight: 2 }}>
                                                    {data.collapse ? <RemoveIcon color={'action'} fontSize={'small'} /> : <AddIcon color={'action'} fontSize={'small'} />}
                                                </span>
                                        }
                                        <span>
                                            {this.state.role ? this.state.role.role_id === 1 ?
                                                <CustomCheckboxDisabled
                                                    disabled={true}
                                                    checked={true}
                                                // onChange={() => this.handleItemClick(item)}
                                                /> :
                                                <CustomCheckbox
                                                    checked={this.handleItemChecked(data)}
                                                    onChange={() => this.handleItemClick(data)}
                                                /> :
                                                <CustomCheckbox
                                                    checked={this.handleItemChecked(data)}
                                                    onChange={() => this.handleItemClick(data)}
                                                />
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
360
                                        </span>
a.bairuha's avatar
a.bairuha committed
361 362
                                        <Typography style={{ fontSize: 12 }}>{titleCase(data.company_name)}</Typography>
                                    </div>
d.arizona's avatar
d.arizona committed
363
                                    {!R.isNil(data.children) && this.renderChildren(data, padding + 30)}
a.bairuha's avatar
a.bairuha committed
364 365 366 367 368 369 370
                                </Collapse>
                                // </li>
                            )
                        })}
                    </ul>
                )}
            </div>
d.arizona's avatar
d.arizona committed
371 372 373
        )
    }

d.arizona's avatar
d.arizona committed
374
    handleCollapse(item) {
Deni Rinaldi's avatar
Deni Rinaldi committed
375
        let path = this.searchIt({ children: this.state.listCompany }, item.id)
d.arizona's avatar
d.arizona committed
376 377
        let listCompany = this.state.listCompany
        let arrayPath = []
d.arizona's avatar
d.arizona committed
378

d.arizona's avatar
d.arizona committed
379 380
        if (path.length > 1) {
            arrayPath = path.split('-');
Deni Rinaldi's avatar
Deni Rinaldi committed
381
            arrayPath = arrayPath.map((item) => { return item })
d.arizona's avatar
d.arizona committed
382 383 384
        } else {
            arrayPath.push(path)
        }
d.arizona's avatar
d.arizona committed
385

d.arizona's avatar
d.arizona committed
386 387
        let pathSelect = null
        if (arrayPath.length == 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
388
            pathSelect = listCompany[arrayPath[0]]
d.arizona's avatar
d.arizona committed
389
        } else if (arrayPath.length == 2) {
Deni Rinaldi's avatar
Deni Rinaldi committed
390
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]]
d.arizona's avatar
d.arizona committed
391
        } else if (arrayPath.length == 3) {
Deni Rinaldi's avatar
Deni Rinaldi committed
392
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]]
d.arizona's avatar
d.arizona committed
393
        } else if (arrayPath.length == 4) {
Deni Rinaldi's avatar
Deni Rinaldi committed
394
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]]
d.arizona's avatar
d.arizona committed
395
        } else if (arrayPath.length == 5) {
Deni Rinaldi's avatar
Deni Rinaldi committed
396
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]].children[arrayPath[4]]
d.arizona's avatar
d.arizona committed
397
        } else if (arrayPath.length == 6) {
Deni Rinaldi's avatar
Deni Rinaldi committed
398
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]].children[arrayPath[4]].children[arrayPath[5]]
d.arizona's avatar
d.arizona committed
399
        } else if (arrayPath.length == 7) {
Deni Rinaldi's avatar
Deni Rinaldi committed
400
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]].children[arrayPath[4]].children[arrayPath[5]].children[arrayPath[6]]
d.arizona's avatar
d.arizona committed
401
        }
d.arizona's avatar
d.arizona committed
402

d.arizona's avatar
d.arizona committed
403 404
        pathSelect.collapse = !pathSelect.collapse
        // console.log(pathSelect.collapse)
Deni Rinaldi's avatar
Deni Rinaldi committed
405
        this.setState({ listCompany }, () => console.log(pathSelect))
d.arizona's avatar
d.arizona committed
406
    }
d.arizona's avatar
d.arizona committed
407 408

    searchIt = (node, search, path = '', position = 0) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
409 410
        if (node.id && node.id === search) { return path !== '' ? `${path}-${position}` : position; }
        if (!node.children) { return false }
d.arizona's avatar
d.arizona committed
411
        const index = node.children.findIndex((x) => x.id && x.id === search);
d.arizona's avatar
d.arizona committed
412
        if (index >= 0) {
Deni Rinaldi's avatar
Deni Rinaldi committed
413
            return path !== '' ? `${path}-${index}` : index;
d.arizona's avatar
d.arizona committed
414
        }
d.arizona's avatar
d.arizona committed
415
        for (let i = 0; i < node.children.length; i++) {
Deni Rinaldi's avatar
Deni Rinaldi committed
416 417 418 419
            const result = this.searchIt(node.children[i], search, path !== '' ? `${path}-${i}` : i, i);
            if (result) {
                return result;
            }
d.arizona's avatar
d.arizona committed
420 421 422 423
        }
        return false;
    };

a.bairuha's avatar
a.bairuha committed
424 425 426 427
    closeAlert() {
      this.setState({ alert: false })
    }

d.arizona's avatar
d.arizona committed
428 429 430
    render() {
        return (
            <div className="test app-popup-show">
a.bairuha's avatar
a.bairuha committed
431 432 433 434 435
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
d.arizona's avatar
d.arizona committed
436
                <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
437
                    <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
d.arizona's avatar
d.arizona committed
438 439
                        <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                            <div className="popup-title">
d.arizona's avatar
d.arizona committed
440
                                <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Edit Data</span>
d.arizona's avatar
d.arizona committed
441 442 443 444 445 446 447 448
                            </div>
                        </div>
                        <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
                            <button
                                type="button"
                                className="btn btn-circle btn-white"
                                onClick={() => this.props.onClickClose()}
                            >
Deni Rinaldi's avatar
Deni Rinaldi committed
449
                                <img src={Images.close} />
d.arizona's avatar
d.arizona committed
450 451 452 453 454 455
                            </button>
                        </div>
                    </div>

                    <div className="grid grid-2x grid-mobile-none gap-15px" style={{ padding: 20 }}>
                        <div className="column-1">
d.arizona's avatar
d.arizona committed
456
                            <div className="">
d.arizona's avatar
d.arizona committed
457 458 459 460 461 462 463
                                <TextField
                                    style={{ width: '100%' }}
                                    id="id"
                                    label="ID"
                                    disabled
                                    // id="outlined-read-only-input"
                                    variant="filled"
Deni Rinaldi's avatar
Deni Rinaldi committed
464
                                    value={this.state.tempData === null ? '' : this.state.tempData.user_id}
d.arizona's avatar
d.arizona committed
465
                                    onChange={(e) => null}
a.bairuha's avatar
a.bairuha committed
466 467 468 469 470 471 472 473 474 475 476 477 478
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085',
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
479 480 481 482 483 484 485 486 487 488 489
                                >
                                    {/* {periode.map((option) => (
                                        <MenuItem key={option.value} value={option.value}>
                                            {option.label}
                                        </MenuItem>
                                    ))} */}
                                </TextField>
                            </div>
                        </div>

                        <div className="column-2">
d.arizona's avatar
d.arizona committed
490 491
                            <div className="">
                                <TextField
Deni Rinaldi's avatar
Deni Rinaldi committed
492 493 494
                                    style={{ width: '100%', marginTop: 7 }}
                                    id="fullname"
                                    name="fullname"
d.arizona's avatar
d.arizona committed
495
                                    label="Full Name"
Deni Rinaldi's avatar
Deni Rinaldi committed
496 497 498 499 500
                                    value={this.state.tempData === null ? '' : this.state.tempData.fullname}
                                    onChange={(e) => this.handleChange(e, '')}
                                    // defaultValue="Default Value"
                                    error={this.state.errorFullname}
                                    helperText={this.state.msgErrorFN}
a.bairuha's avatar
a.bairuha committed
501 502 503 504 505 506 507 508 509 510 511 512 513
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085',
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
514 515 516 517 518 519 520
                                />
                            </div>
                        </div>
                    </div>

                    <div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
                        <div className="column-1">
d.arizona's avatar
d.arizona committed
521 522
                            <div className="margin-bottom-20px">
                                <TextField
Deni Rinaldi's avatar
Deni Rinaldi committed
523 524 525 526 527 528 529 530
                                    style={{ width: '100%', marginTop: 7 }}
                                    id="email"
                                    name="email"
                                    label="Email"
                                    value={this.state.tempData === null ? '' : this.state.tempData.email}
                                    onChange={(e) => this.handleChange(e, '')}
                                    error={this.state.errorEmail}
                                    helperText={this.state.msgErrorEM}
a.bairuha's avatar
a.bairuha committed
531 532 533 534 535 536 537 538 539 540 541 542 543
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085',
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
544 545 546
                                />
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
547 548 549 550 551 552

                        <div className="column-2">
                            <div className="margin-bottom-20px">
                                <Autocomplete
                                    {...this.state.listRole}
                                    id="role"
a.bairuha's avatar
a.bairuha committed
553
                                    onChange={(event, newInputValue) => this.setState({ role: newInputValue }, ()=> this.clearError())}
d.arizona's avatar
d.arizona committed
554
                                    debug
Deni Rinaldi's avatar
Deni Rinaldi committed
555

a.bairuha's avatar
a.bairuha committed
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
                                    renderInput={(params) => <TextField 
                                        {...params} 
                                        label="Role" 
                                        margin="normal" 
                                        style={{ marginTop: 7 }} 
                                        onChange={(e) => this.handleChange(e, '')}
                                        error={this.state.errorRoleName}
                                        helperText={this.state.msgErrorRN}
                                        InputLabelProps={{
                                            style: {
                                                fontSize: 11,
                                                fontFamily: 'Nunito Sans, sans-serif',
                                                color: '#7e8085'
                                            }
                                        }}
                                        InputProps={{ ...params.InputProps, style: { fontSize: 11, fontFamily: 'Nunito Sans, sans-serif' } }}
                                        />}
d.arizona's avatar
d.arizona committed
573 574 575 576
                                    value={this.state.role}
                                />
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
577 578 579 580 581
                    </div>

                    <div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
                        <div className="column-1">
                            <div className="margin-bottom-20px">
d.arizona's avatar
d.arizona committed
582 583 584
                                <DatePicker
                                    margin="normal"
                                    id="startDate"
585
                                    label="Valid From"
d.arizona's avatar
d.arizona committed
586
                                    format="dd MMMM yyyy"
d.arizona's avatar
d.arizona committed
587
                                    value={this.state.tempData === null ? null : this.state.tempData.start_date}
d.arizona's avatar
d.arizona committed
588 589 590 591 592 593
                                    error={this.state.errorStartDate}
                                    helperText={this.state.msgErrorSD}
                                    onChange={(e) => this.handleChange(e, 'start_date')}
                                    KeyboardButtonProps={{
                                        'aria-label': 'change date',
                                    }}
a.bairuha's avatar
a.bairuha committed
594 595 596 597 598 599 600 601 602 603 604 605 606
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085',
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
607
                                    style={{ padding: 0, margin: 0, width: '100%' }}
d.arizona's avatar
d.arizona committed
608 609 610
                                />
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
611

d.arizona's avatar
d.arizona committed
612 613
                        <div className="column-2">
                            <div className="margin-bottom-20px">
d.arizona's avatar
d.arizona committed
614 615 616
                                <DatePicker
                                    margin="normal"
                                    id="endDate"
617
                                    label="Valid To"
d.arizona's avatar
d.arizona committed
618
                                    format="dd MMMM yyyy"
d.arizona's avatar
d.arizona committed
619
                                    value={this.state.tempData === null ? null : this.state.tempData.end_date}
d.arizona's avatar
d.arizona committed
620 621
                                    error={this.state.errorEndDate}
                                    helperText={this.state.msgErrorED}
d.arizona's avatar
d.arizona committed
622
                                    minDate={this.state.tempData === null ? null : this.state.tempData.start_date}
d.arizona's avatar
d.arizona committed
623 624 625 626
                                    onChange={(e) => this.handleChange(e, 'end_date')}
                                    KeyboardButtonProps={{
                                        'aria-label': 'change date',
                                    }}
a.bairuha's avatar
a.bairuha committed
627 628 629 630 631 632 633 634 635 636 637 638 639
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085',
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
640
                                    style={{ padding: 0, margin: 0, width: '100%' }}
d.arizona's avatar
d.arizona committed
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
                                />
                            </div>
                        </div>
                    </div>

                    <div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
                        <div className="column-1">
                            <div className="margin-bottom-20px">
                                <TextField
                                    style={{ width: '100%' }}
                                    id="status"
                                    label="Status"
                                    disabled
                                    // id="outlined-read-only-input"
                                    variant="filled"
Deni Rinaldi's avatar
Deni Rinaldi committed
656
                                    value={this.state.tempData === null ? '' : this.state.tempData.status}
a.bairuha's avatar
a.bairuha committed
657 658 659 660 661 662 663 664 665 666 667 668 669
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085',
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
670 671 672 673 674 675 676 677 678
                                >
                                    {/* {periode.map((option) => (
                                        <MenuItem key={option.value} value={option.value}>
                                            {option.label}
                                        </MenuItem>
                                    ))} */}
                                </TextField>
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
679 680 681 682 683 684 685 686 687 688 689

                        <div className="column-2">
                            <div className="margin-bottom-20px">
                                <TextField
                                    style={{ width: '100%' }}
                                    id="is_expired"
                                    name="is_expired"
                                    label="Expired"
                                    disabled
                                    // id="outlined-read-only-input"
                                    variant="filled"
Deni Rinaldi's avatar
Deni Rinaldi committed
690
                                    value={this.state.tempData === null ? '' : this.state.tempData.is_expired}
a.bairuha's avatar
a.bairuha committed
691 692 693 694 695 696 697 698 699 700 701 702 703
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085',
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
704 705 706 707 708 709 710 711 712
                                >
                                    {/* {periode.map((option) => (
                                        <MenuItem key={option.value} value={option.value}>
                                            {option.label}
                                        </MenuItem>
                                    ))} */}
                                </TextField>
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
713
                    </div>
a.bairuha's avatar
a.bairuha committed
714
                    <div style={{ flexDirection: 'column', display: 'flex', paddingLeft: 30, paddingRight: 30 }}>
a.bairuha's avatar
a.bairuha committed
715 716
                        <Typography style={{ fontSize: 11 }}>{`Created By  : ${this.state.tempData === null ? '' : this.state.tempData.created}`}</Typography>
                        <Typography style={{ fontSize: 11 }}>{`Updated By  : ${this.state.tempData === null ? '' : this.state.tempData.updated}`}</Typography>
d.arizona's avatar
d.arizona committed
717
                    </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
718 719
                    <Divider style={{ margin: 20 }} />
                    <div style={{ paddingLeft: 20, paddingRight: 20 }}>
d.arizona's avatar
d.arizona committed
720
                        <h5>Authorization Company</h5>
Deni Rinaldi's avatar
Deni Rinaldi committed
721 722 723
                        <div style={{ paddingLeft: 10, overflow: 'scroll', height: '25vh' }}>
                            {this.state.listCompany.map((item, index) => {
                                return (
d.arizona's avatar
d.arizona committed
724
                                    <div>
d.arizona's avatar
d.arizona committed
725 726
                                        {/* <ul>
                                            <li> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
                                        <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start' }}>
                                            {item.children.length > 0 && <span onClick={() => this.handleCollapse(item)} style={{ marginLeft: 7, marginRight: 2 }}>
                                                {item.collapse ? <RemoveIcon color={'action'} fontSize={'small'} /> : <AddIcon color={'action'} fontSize={'small'} />}
                                            </span>}
                                            <span>
                                                {this.state.role ? this.state.role.role_id === 1 ?
                                                    <CustomCheckboxDisabled
                                                        disabled={true}
                                                        checked={true}
                                                    // onChange={() => this.handleItemClick(item)}
                                                    /> :
                                                    <CustomCheckbox
                                                        checked={this.handleItemChecked(item)}
                                                        onChange={() => this.handleItemClick(item)}
                                                    /> :
                                                    <CustomCheckbox
                                                        checked={this.handleItemChecked(item)}
                                                        onChange={() => this.handleItemClick(item)}
                                                    />
                                                }
                                            </span>
                                            <Typography style={{ fontSize: 12 }}>{titleCase(item.company_name)}</Typography>
                                        </div>
                                        {!R.isNil(item.children) && this.renderChildren(item)}
                                        {/* </li>
d.arizona's avatar
d.arizona committed
752
                                        </ul> */}
d.arizona's avatar
d.arizona committed
753 754 755 756
                                    </div>
                                )
                            })}
                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
757

d.arizona's avatar
d.arizona committed
758 759 760
                    </div>
                    <div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
                        <div className="column-1" style={{ alignSelf: 'center' }}>
d.arizona's avatar
d.arizona committed
761 762
                            <button onClick={() => this.props.onClickClose()}>
                                <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
d.arizona's avatar
d.arizona committed
763
                                    <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
d.arizona's avatar
d.arizona committed
764 765
                                </div>
                            </button>
d.arizona's avatar
d.arizona committed
766
                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
767
                        <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
d.arizona's avatar
d.arizona committed
768 769
                            <button onClick={() => this.validasi()}>
                                <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
d.arizona's avatar
d.arizona committed
770
                                    <span style={{ color: '#fff', fontSize: 11 }}>Save</span>
d.arizona's avatar
d.arizona committed
771 772
                                </div>
                            </button>
d.arizona's avatar
d.arizona committed
773 774 775 776 777 778 779
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}