AddUser.js 37.5 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 Autocomplete from '@material-ui/lab/Autocomplete';
import { titleCase } from '../../../library/Utils';
d.arizona's avatar
d.arizona committed
6 7
import localeID from "date-fns/locale/id"
import format from "date-fns/format";
d.arizona's avatar
d.arizona committed
8 9 10
import RemoveIcon from '@material-ui/icons/Remove';
import AddIcon from '@material-ui/icons/Add';
import { DatePicker } from '@material-ui/pickers';
d.arizona's avatar
d.arizona committed
11
import * as R from 'ramda'
d.arizona's avatar
d.arizona committed
12
import Images from '../../../assets/Images';
a.bairuha's avatar
a.bairuha committed
13
import MuiAlert from '@material-ui/lab/Alert';
a.bairuha's avatar
a.bairuha committed
14
import Constant from '../../../library/Constant';
d.arizona's avatar
d.arizona committed
15 16 17 18

const CustomCheckbox = withStyles({
    root: {
        color: '#51c6ea',
Deni Rinaldi's avatar
Deni Rinaldi committed
19 20 21
        '&$checked': {
            color: '#51c6ea',
        },
d.arizona's avatar
d.arizona committed
22 23
    },
    checked: {},
Deni Rinaldi's avatar
Deni Rinaldi committed
24 25 26 27 28 29 30 31 32 33 34
})((props) => <Checkbox color="default" {...props} />);

const CustomCheckboxDisabled = withStyles({
    root: {
        color: '#d5d5d5',
        '&$checked': {
            color: '#d5d5d5',
        },
    },
    checked: {},
})((props) => <Checkbox color="default" {...props} />);
d.arizona's avatar
d.arizona committed
35

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

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

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

    handleChecked() {
Deni Rinaldi's avatar
Deni Rinaldi committed
75
        this.setState({ checked: !this.state.checked })
d.arizona's avatar
d.arizona committed
76
    }
Deni Rinaldi's avatar
Deni Rinaldi committed
77

d.arizona's avatar
d.arizona committed
78
    componentDidMount() {
d.arizona's avatar
d.arizona committed
79
        this.getRole()
d.arizona's avatar
d.arizona committed
80
        this.getPerusahaan()
a.bairuha's avatar
a.bairuha committed
81 82 83 84 85 86 87 88 89 90
        if (this.props.type === 'edit') {
            //
        } else {
            let date = format(new Date, 'yyyy-MM-dd')
            console.log(date);
            this.setState({
                startDate: date,
                endDate: date
            })
        }
d.arizona's avatar
d.arizona committed
91 92
    }

d.arizona's avatar
d.arizona committed
93
    handleChange(e, type) {
d.arizona's avatar
d.arizona committed
94
        let data = this.state
d.arizona's avatar
d.arizona committed
95
        let isDate = type !== '' ? true : false
d.arizona's avatar
d.arizona committed
96
        if (isDate && type === 'start_date') {
Deni Rinaldi's avatar
Deni Rinaldi committed
97 98
            this.setState({
                ...data, startDate: format(e, 'yyyy-MM-dd'), endDate: null,
a.bairuha's avatar
a.bairuha committed
99 100
                errorFullname: false,
                errorEmail: false,
d.arizona's avatar
d.arizona committed
101 102 103
                errorRoleName: false,
                errorStartDate: false,
                errorEndDate: false,
a.bairuha's avatar
a.bairuha committed
104 105
                msgErrorFN: '',
                msgErrorEM: '',
d.arizona's avatar
d.arizona committed
106 107 108 109
                msgErrorRN: '',
                msgErrorSD: '',
                msgErrorED: '',
            })
d.arizona's avatar
d.arizona committed
110
        } else if (isDate && type === 'end_date') {
Deni Rinaldi's avatar
Deni Rinaldi committed
111 112
            this.setState({
                ...data, endDate: format(e, 'yyyy-MM-dd'),
a.bairuha's avatar
a.bairuha committed
113 114
                errorFullname: false,
                errorEmail: false,
d.arizona's avatar
d.arizona committed
115 116 117
                errorRoleName: false,
                errorStartDate: false,
                errorEndDate: false,
a.bairuha's avatar
a.bairuha committed
118 119
                msgErrorFN: '',
                msgErrorEM: '',
d.arizona's avatar
d.arizona committed
120 121 122 123 124
                msgErrorRN: '',
                msgErrorSD: '',
                msgErrorED: '',
            })
        } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
125 126
            this.setState({
                ...data, [e.target.name]: e.target.value,
a.bairuha's avatar
a.bairuha committed
127 128
                errorFullname: false,
                errorEmail: false,
d.arizona's avatar
d.arizona committed
129 130 131
                errorRoleName: false,
                errorStartDate: false,
                errorEndDate: false,
a.bairuha's avatar
a.bairuha committed
132 133
                msgErrorFN: '',
                msgErrorEM: '',
d.arizona's avatar
d.arizona committed
134 135
                msgErrorRN: '',
                msgErrorSD: '',
Deni Rinaldi's avatar
Deni Rinaldi committed
136
                msgErrorED: '',
d.arizona's avatar
d.arizona committed
137 138 139 140
            })
        }
    }

a.bairuha's avatar
a.bairuha committed
141
    clearError() {
d.arizona's avatar
d.arizona committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
        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;  
        });
d.arizona's avatar
d.arizona committed
166
        company = this.state.role == null? [] : this.state.role.role_id === 1? uniqueCompany : []
d.arizona's avatar
d.arizona committed
167 168
        // console.log(uniqueCompany)
        
a.bairuha's avatar
a.bairuha committed
169
        this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
170 171 172 173 174 175 176 177 178 179
            errorFullname: false,
            errorEmail: false,
            errorRoleName: false,
            errorStartDate: false,
            errorEndDate: false,
            msgErrorFN: '',
            msgErrorEM: '',
            msgErrorRN: '',
            msgErrorSD: '',
            msgErrorED: '',
d.arizona's avatar
d.arizona committed
180 181 182
            company
        }, () => {
            console.log(this.state.company)
Deni Rinaldi's avatar
Deni Rinaldi committed
183
        })
a.bairuha's avatar
a.bairuha committed
184 185
    }

a.bairuha's avatar
a.bairuha committed
186 187 188 189 190
    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
191
    validasi() {
a.bairuha's avatar
a.bairuha committed
192 193 194
        var isEmail = this.isEmail(this.state.email)

        if (R.isEmpty(this.state.fullname)) {
d.arizona's avatar
d.arizona committed
195
            this.setState({ errorFullname: true, msgErrorFN: 'Fullname Cannot be Empty' })
a.bairuha's avatar
a.bairuha committed
196
        } else if (R.isEmpty(this.state.email)) {
d.arizona's avatar
d.arizona committed
197
            this.setState({ errorEmail: true, msgErrorEM: 'Email Cannot be Empty' })
a.bairuha's avatar
a.bairuha committed
198
        } else if (!isEmail) {
d.arizona's avatar
d.arizona committed
199
            this.setState({ errorEmail: true, msgErrorEM: 'Please enter a valid email address' })
a.bairuha's avatar
a.bairuha committed
200
        } else if (R.isNil(this.state.role)) {
d.arizona's avatar
d.arizona committed
201
            this.setState({ errorRoleName: true, msgErrorRN: 'Role Cannot be Empty' })
a.bairuha's avatar
a.bairuha committed
202
        } else if (R.isNil(this.state.startDate)) {
d.arizona's avatar
d.arizona committed
203
            this.setState({ errorStartDate: true, msgErrorSD: 'Valid From Cannot be Empty' })
a.bairuha's avatar
a.bairuha committed
204
        } else if (R.isNil(this.state.endDate)) {
d.arizona's avatar
d.arizona committed
205
            this.setState({ errorEndDate: true, msgErrorED: 'Valid To Cannot be Empty' })
Deni Rinaldi's avatar
Deni Rinaldi committed
206 207
        } else if (this.state.company.length < 1) {
            this.setState({ alert: true, messageAlert: 'Authorization company cannot be empty', tipeAlert: 'warning' })
a.bairuha's avatar
a.bairuha committed
208 209 210 211 212
        }
        // else if (this.state.privileges.length < 1) {
        //     alert('Hak Akses belum di pilih !!')
        // } 
        else {
Deni Rinaldi's avatar
Deni Rinaldi committed
213 214 215 216 217 218 219 220
            let payload = {
                "role_id": this.state.role.role_id,
                "email": this.state.email,
                "fullname": this.state.fullname,
                "password": this.state.fullname,
                "company": this.state.company,
                "start_date": this.state.startDate,
                "end_date": this.state.endDate
a.bairuha's avatar
a.bairuha committed
221
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
222 223
            this.props.createUser(payload)
        }
d.arizona's avatar
d.arizona committed
224 225
    }

d.arizona's avatar
d.arizona committed
226
    getRole() {
227
        api.create().getRoleActive().then((response) => {
a.bairuha's avatar
a.bairuha committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
            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),
                        };
                        this.setState({ listRole: defaultProps })
                    } else {
a.bairuha's avatar
a.bairuha committed
244
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
a.bairuha's avatar
a.bairuha committed
245
                            if (response.data.message.includes("Someone Logged In")) {
a.bairuha's avatar
a.bairuha committed
246 247 248 249 250 251
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
d.arizona's avatar
d.arizona committed
252
                    }
a.bairuha's avatar
a.bairuha committed
253 254 255
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
d.arizona's avatar
d.arizona committed
256
            } else {
a.bairuha's avatar
a.bairuha committed
257
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
258 259 260 261
            }
        })
    }

d.arizona's avatar
d.arizona committed
262 263
    getPerusahaan() {
        api.create().getPerusahaanHierarki().then((response) => {
a.bairuha's avatar
a.bairuha committed
264 265 266 267 268 269
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ listCompany: response.data.data })
                        console.log(response.data.data)
                    } else {
a.bairuha's avatar
a.bairuha committed
270
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
a.bairuha's avatar
a.bairuha committed
271
                            if (response.data.message.includes("Someone Logged In")) {
a.bairuha's avatar
a.bairuha committed
272 273 274 275 276 277
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
a.bairuha's avatar
a.bairuha committed
278 279 280 281 282 283
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
284 285 286 287 288
            }
        })
    }

    handleItemChecked(item) {
d.arizona's avatar
d.arizona committed
289
        let indexID = this.state.company.findIndex((val) => val === item.id)
d.arizona's avatar
d.arizona committed
290
        return indexID === -1 ? false : true
d.arizona's avatar
d.arizona committed
291 292 293
    }

    handleItemClick(item) {
d.arizona's avatar
d.arizona committed
294
        let indexID = this.state.company.findIndex((val) => val === item.id)
d.arizona's avatar
d.arizona committed
295
        let company = this.state.company
d.arizona's avatar
d.arizona committed
296 297 298 299 300 301 302 303 304 305
        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)
                    })
d.arizona's avatar
d.arizona committed
306 307
                }
            }
d.arizona's avatar
d.arizona committed
308
        }
d.arizona's avatar
d.arizona committed
309

d.arizona's avatar
d.arizona committed
310 311 312 313 314
        const handleSpliceChild = (item) => {
            let indexIDzz = company.findIndex((val) => val === item.id)
            if (indexIDzz !== -1) {
                company.splice(indexIDzz, 1)
            }
d.arizona's avatar
d.arizona committed
315 316
            if (item.children !== null) {
                if (item.children.length > 0) {
d.arizona's avatar
d.arizona committed
317 318
                    item.children.map((items,indexs) => {
                        handleSpliceChild(items)
d.arizona's avatar
d.arizona committed
319 320 321
                    })
                }
            }
d.arizona's avatar
d.arizona committed
322 323 324 325 326 327 328 329 330 331 332 333
        }

        if (indexID === -1) {
            company.push(item.id)
            if (item.children !== null) {
                if (item.children.length > 0) {
                    item.children.map((items,indexs) => {
                        handlePushChild(items)
                    })
                }
            }

d.arizona's avatar
d.arizona committed
334 335
        } else {
            company.splice(indexID, 1)
d.arizona's avatar
d.arizona committed
336 337 338 339 340
            if (item.children !== null) {
                if (item.children.length > 0) {
                    item.children.map((items,indexs) => {
                        handleSpliceChild(items)
                    })
d.arizona's avatar
d.arizona committed
341 342
                }
            }
d.arizona's avatar
d.arizona committed
343
        }
d.arizona's avatar
d.arizona committed
344 345 346
        
        // console.log(company)
        this.setState({ company})
d.arizona's avatar
d.arizona committed
347
    }
d.arizona's avatar
d.arizona committed
348

d.arizona's avatar
d.arizona committed
349 350 351 352 353
    renderChildren = (item, pad) => {
        let padding = null
        if (pad !== undefined) {
            padding = pad
        } else {
d.arizona's avatar
d.arizona committed
354
            padding = 30
d.arizona's avatar
d.arizona committed
355 356
        }
        return (
a.bairuha's avatar
a.bairuha committed
357 358 359 360 361 362 363
            <div>
                {item.children.length > 0 && (
                    <ul>
                        {item.children.map((data, index) => {
                            return (
                                // <li>
                                <Collapse key={index} timeout="auto" unmountOnExit in={item.collapse}>
Deni Rinaldi's avatar
Deni Rinaldi committed
364
                                    <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
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
                                        {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
391
                                        </span>
a.bairuha's avatar
a.bairuha committed
392 393
                                        <Typography style={{ fontSize: 12 }}>{titleCase(data.company_name)}</Typography>
                                    </div>
d.arizona's avatar
d.arizona committed
394
                                    {!R.isNil(data.children) && this.renderChildren(data, padding + 30)}
a.bairuha's avatar
a.bairuha committed
395 396 397 398 399 400 401
                                </Collapse>
                                // </li>
                            )
                        })}
                    </ul>
                )}
            </div>
d.arizona's avatar
d.arizona committed
402 403 404 405
        )
    }

    handleCollapse(item) {
Deni Rinaldi's avatar
Deni Rinaldi committed
406
        let path = this.searchIt({ children: this.state.listCompany }, item.id)
d.arizona's avatar
d.arizona committed
407 408 409 410 411
        let listCompany = this.state.listCompany
        let arrayPath = []

        if (path.length > 1) {
            arrayPath = path.split('-');
Deni Rinaldi's avatar
Deni Rinaldi committed
412
            arrayPath = arrayPath.map((item) => { return item })
d.arizona's avatar
d.arizona committed
413 414 415 416 417 418
        } else {
            arrayPath.push(path)
        }

        let pathSelect = null
        if (arrayPath.length == 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
419
            pathSelect = listCompany[arrayPath[0]]
d.arizona's avatar
d.arizona committed
420
        } else if (arrayPath.length == 2) {
Deni Rinaldi's avatar
Deni Rinaldi committed
421
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]]
d.arizona's avatar
d.arizona committed
422
        } else if (arrayPath.length == 3) {
Deni Rinaldi's avatar
Deni Rinaldi committed
423
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]]
d.arizona's avatar
d.arizona committed
424
        } else if (arrayPath.length == 4) {
Deni Rinaldi's avatar
Deni Rinaldi committed
425
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]]
d.arizona's avatar
d.arizona committed
426
        } else if (arrayPath.length == 5) {
Deni Rinaldi's avatar
Deni Rinaldi committed
427
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]].children[arrayPath[4]]
d.arizona's avatar
d.arizona committed
428
        } else if (arrayPath.length == 6) {
Deni Rinaldi's avatar
Deni Rinaldi committed
429
            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
430
        } else if (arrayPath.length == 7) {
Deni Rinaldi's avatar
Deni Rinaldi committed
431
            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
432 433 434 435
        }

        pathSelect.collapse = !pathSelect.collapse
        // console.log(pathSelect.collapse)
Deni Rinaldi's avatar
Deni Rinaldi committed
436
        this.setState({ listCompany }, () => console.log(pathSelect))
d.arizona's avatar
d.arizona committed
437 438 439
    }

    searchIt = (node, search, path = '', position = 0) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
440 441
        if (node.id && node.id === search) { return path !== '' ? `${path}-${position}` : position; }
        if (!node.children) { return false }
d.arizona's avatar
d.arizona committed
442
        const index = node.children.findIndex((x) => x.id && x.id === search);
d.arizona's avatar
d.arizona committed
443
        if (index >= 0) {
Deni Rinaldi's avatar
Deni Rinaldi committed
444
            return path !== '' ? `${path}-${index}` : index;
d.arizona's avatar
d.arizona committed
445
        }
d.arizona's avatar
d.arizona committed
446
        for (let i = 0; i < node.children.length; i++) {
Deni Rinaldi's avatar
Deni Rinaldi committed
447 448 449 450
            const result = this.searchIt(node.children[i], search, path !== '' ? `${path}-${i}` : i, i);
            if (result) {
                return result;
            }
d.arizona's avatar
d.arizona committed
451 452 453 454
        }
        return false;
    };

a.bairuha's avatar
a.bairuha committed
455
    closeAlert() {
Deni Rinaldi's avatar
Deni Rinaldi committed
456
        this.setState({ alert: false })
a.bairuha's avatar
a.bairuha committed
457 458
    }

d.arizona's avatar
d.arizona committed
459 460 461
    render() {
        return (
            <div className="test app-popup-show">
a.bairuha's avatar
a.bairuha committed
462 463 464 465 466
                <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
467
                <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
468
                    <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
d.arizona's avatar
d.arizona committed
469 470
                        <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                            <div className="popup-title">
d.arizona's avatar
d.arizona committed
471
                                <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Create Data</span>
d.arizona's avatar
d.arizona committed
472 473 474 475 476 477 478 479
                            </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
480
                                <img src={Images.close} />
d.arizona's avatar
d.arizona committed
481 482 483 484 485 486
                            </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
487
                            <div className="">
d.arizona's avatar
d.arizona committed
488 489 490 491 492 493 494
                                <TextField
                                    style={{ width: '100%' }}
                                    id="id"
                                    label="ID"
                                    disabled
                                    // id="outlined-read-only-input"
                                    variant="filled"
d.arizona's avatar
d.arizona committed
495
                                    value={'-'}
d.arizona's avatar
d.arizona committed
496
                                    onChange={(e) => null}
a.bairuha's avatar
a.bairuha committed
497 498 499 500 501 502 503 504 505 506 507 508 509
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                            color: '#7e8085',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
510 511 512 513 514 515 516 517 518 519 520
                                >
                                    {/* {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
521 522
                            <div className="">
                                <TextField
Deni Rinaldi's avatar
Deni Rinaldi committed
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
                                    style={{ width: '100%', marginTop: 7 }}
                                    id="fullname"
                                    name="fullname"
                                    label="Full Name"
                                    value={this.state.fullname}
                                    error={this.state.errorFullname}
                                    helperText={this.state.msgErrorFN}
                                    onChange={(e) => this.handleChange(e, '')}
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                            color: '#7e8085',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
544 545 546 547 548 549 550 551 552
                                // defaultValue="Default Value"
                                // helperText="Some important text"
                                />
                            </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
553 554
                            <div className="margin-bottom-20px">
                                <TextField
Deni Rinaldi's avatar
Deni Rinaldi committed
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
                                    style={{ width: '100%', marginTop: 7 }}
                                    id="email"
                                    name="email"
                                    label="Email"
                                    value={this.state.email}
                                    error={this.state.errorEmail}
                                    helperText={this.state.msgErrorEM}
                                    onChange={(e) => this.handleChange(e, '')}
                                    inputProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            fontFamily: 'Nunito Sans, sans-serif',
                                            color: '#7e8085',
                                        }
                                    }}
d.arizona's avatar
d.arizona committed
576 577 578 579 580
                                // defaultValue="Default Value"
                                // helperText="Some important text"
                                />
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
581 582 583 584 585 586

                        <div className="column-2">
                            <div className="margin-bottom-20px">
                                <Autocomplete
                                    {...this.state.listRole}
                                    id="role"
Deni Rinaldi's avatar
Deni Rinaldi committed
587
                                    onChange={(event, newInputValue) => this.setState({ role: newInputValue }, () => this.clearError())}
d.arizona's avatar
d.arizona committed
588
                                    debug
Deni Rinaldi's avatar
Deni Rinaldi committed
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
                                    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' } }}
a.bairuha's avatar
a.bairuha committed
606
                                        />}
d.arizona's avatar
d.arizona committed
607 608 609 610
                                    value={this.state.role}
                                />
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
611 612 613
                    </div>

                    <div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
614
                        <div className="column-1">
d.arizona's avatar
d.arizona committed
615
                            <div className="margin-bottom-20px">
d.arizona's avatar
d.arizona committed
616 617 618
                                <DatePicker
                                    margin="normal"
                                    id="startDate"
619
                                    label="Valid From"
d.arizona's avatar
d.arizona committed
620
                                    format="dd-MM-yyyy"
d.arizona's avatar
d.arizona committed
621 622 623 624 625 626 627
                                    value={this.state.startDate}
                                    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
628 629 630 631 632 633 634 635 636 637 638 639 640
                                    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
641 642

                                    style={{ padding: 0, margin: 0, width: '100%' }}
d.arizona's avatar
d.arizona committed
643 644 645 646 647 648
                                />
                            </div>
                        </div>

                        <div className="column-2">
                            <div className="margin-bottom-20px">
d.arizona's avatar
d.arizona committed
649 650 651
                                <DatePicker
                                    margin="normal"
                                    id="endDate"
652
                                    label="Valid To"
d.arizona's avatar
d.arizona committed
653
                                    format="dd-MM-yyyy"
d.arizona's avatar
d.arizona committed
654 655 656 657 658 659 660 661
                                    value={this.state.endDate}
                                    error={this.state.errorEndDate}
                                    helperText={this.state.msgErrorED}
                                    minDate={this.state.startDate}
                                    onChange={(e) => this.handleChange(e, 'end_date')}
                                    KeyboardButtonProps={{
                                        'aria-label': 'change date',
                                    }}
a.bairuha's avatar
a.bairuha committed
662 663 664 665 666 667 668 669 670 671 672 673 674
                                    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
675 676

                                    style={{ padding: 0, margin: 0, width: '100%' }}
d.arizona's avatar
d.arizona committed
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
                                />
                            </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"
d.arizona's avatar
d.arizona committed
692
                                    value={'Active'}
a.bairuha's avatar
a.bairuha committed
693 694 695 696 697 698 699 700 701 702 703 704 705
                                    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
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
                                >
                                    {/* {periode.map((option) => (
                                        <MenuItem key={option.value} value={option.value}>
                                            {option.label}
                                        </MenuItem>
                                    ))} */}
                                </TextField>
                            </div>
                        </div>

                        <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"
d.arizona's avatar
d.arizona committed
726
                                    value={'N'}
a.bairuha's avatar
a.bairuha committed
727 728 729 730 731 732 733 734 735 736 737 738 739
                                    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
740 741 742 743 744 745 746 747 748 749
                                >
                                    {/* {periode.map((option) => (
                                        <MenuItem key={option.value} value={option.value}>
                                            {option.label}
                                        </MenuItem>
                                    ))} */}
                                </TextField>
                            </div>
                        </div>
                    </div>
d.arizona's avatar
d.arizona committed
750
                    {/* <div style={{ flexDirection: 'column', display: 'flex', paddingLeft: 20, paddingRight: 20 }}>
a.bairuha's avatar
a.bairuha committed
751 752
                        <Typography style={{ fontSize: 12 }}>{`Dibuat: `}</Typography>
                        <Typography style={{fontSize: 12}}>{`Diubah: `}</Typography>
d.arizona's avatar
d.arizona committed
753
                    </div> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
754 755
                    <Divider style={{ margin: 20 }} />
                    <div style={{ paddingLeft: 20, paddingRight: 20 }}>
d.arizona's avatar
d.arizona committed
756
                        <h5>Authorization Company</h5>
Deni Rinaldi's avatar
Deni Rinaldi committed
757 758 759
                        <div style={{ paddingLeft: 10, overflow: 'scroll', height: '25vh' }}>
                            {this.state.listCompany.map((item, index) => {
                                return (
d.arizona's avatar
d.arizona committed
760
                                    <div>
d.arizona's avatar
d.arizona committed
761 762
                                        {/* <ul>
                                            <li> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
763
                                        <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start' }}>
764
                                            {item.children && item.children.length > 0 && <span onClick={() => this.handleCollapse(item)} style={{ marginLeft: 7, marginRight: 2 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
                                                {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
788
                                        </ul> */}
d.arizona's avatar
d.arizona committed
789 790 791 792
                                    </div>
                                )
                            })}
                        </div>
d.arizona's avatar
d.arizona committed
793 794 795
                    </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
796 797
                            <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
798
                                    <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
d.arizona's avatar
d.arizona committed
799 800
                                </div>
                            </button>
d.arizona's avatar
d.arizona committed
801
                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
802
                        <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
d.arizona's avatar
d.arizona committed
803 804
                            <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
805
                                    <span style={{ color: '#fff', fontSize: 11 }}>Save</span>
d.arizona's avatar
d.arizona committed
806 807
                                </div>
                            </button>
d.arizona's avatar
d.arizona committed
808 809 810 811 812 813 814
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}