AddUser.js 36.1 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 142
    clearError() {
        this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
143 144 145 146 147 148 149 150 151 152 153
            errorFullname: false,
            errorEmail: false,
            errorRoleName: false,
            errorStartDate: false,
            errorEndDate: false,
            msgErrorFN: '',
            msgErrorEM: '',
            msgErrorRN: '',
            msgErrorSD: '',
            msgErrorED: '',
        })
a.bairuha's avatar
a.bairuha committed
154 155
    }

a.bairuha's avatar
a.bairuha committed
156 157 158 159 160
    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
161
    validasi() {
a.bairuha's avatar
a.bairuha committed
162 163 164
        var isEmail = this.isEmail(this.state.email)

        if (R.isEmpty(this.state.fullname)) {
165
            this.setState({ errorFullname: true, msgErrorFN: 'Fullname Cannot be Empty.' })
a.bairuha's avatar
a.bairuha committed
166
        } else if (R.isEmpty(this.state.email)) {
167
            this.setState({ errorEmail: true, msgErrorEM: 'Email Cannot be Empty.' })
a.bairuha's avatar
a.bairuha committed
168
        } else if (!isEmail) {
Deni Rinaldi's avatar
Deni Rinaldi committed
169
            this.setState({ errorEmail: true, msgErrorEM: 'Please enter a valid email address.' })
a.bairuha's avatar
a.bairuha committed
170
        } else if (R.isNil(this.state.role)) {
Deni Rinaldi's avatar
Deni Rinaldi committed
171
            this.setState({ errorRoleName: true, msgErrorRN: 'Role Cannot be Empty.' })
a.bairuha's avatar
a.bairuha committed
172
        } else if (R.isNil(this.state.startDate)) {
173
            this.setState({ errorStartDate: true, msgErrorSD: 'Valid From Cannot be Empty.' })
a.bairuha's avatar
a.bairuha committed
174
        } else if (R.isNil(this.state.endDate)) {
175
            this.setState({ errorEndDate: true, msgErrorED: 'Valid To Cannot be Empty.' })
Deni Rinaldi's avatar
Deni Rinaldi committed
176 177
        } 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
178 179 180 181 182
        }
        // else if (this.state.privileges.length < 1) {
        //     alert('Hak Akses belum di pilih !!')
        // } 
        else {
Deni Rinaldi's avatar
Deni Rinaldi committed
183 184 185 186 187 188 189 190
            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
191
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
192 193
            this.props.createUser(payload)
        }
d.arizona's avatar
d.arizona committed
194 195
    }

d.arizona's avatar
d.arizona committed
196
    getRole() {
197
        api.create().getRoleActive().then((response) => {
a.bairuha's avatar
a.bairuha committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
            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
214 215 216 217 218 219 220 221
                        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);
                            }
                        })
d.arizona's avatar
d.arizona committed
222
                    }
a.bairuha's avatar
a.bairuha committed
223 224 225
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
d.arizona's avatar
d.arizona committed
226
            } else {
a.bairuha's avatar
a.bairuha committed
227
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
228 229 230 231
            }
        })
    }

d.arizona's avatar
d.arizona committed
232 233
    getPerusahaan() {
        api.create().getPerusahaanHierarki().then((response) => {
a.bairuha's avatar
a.bairuha committed
234 235 236 237 238 239
            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
240 241 242 243 244 245 246 247
                        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
248 249 250 251 252 253
                    }
                } 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
254 255 256 257 258
            }
        })
    }

    handleItemChecked(item) {
d.arizona's avatar
d.arizona committed
259
        let indexID = this.state.company.findIndex((val) => val === item.id)
d.arizona's avatar
d.arizona committed
260
        return indexID === -1 ? false : true
d.arizona's avatar
d.arizona committed
261 262 263
    }

    handleItemClick(item) {
d.arizona's avatar
d.arizona committed
264
        let indexID = this.state.company.findIndex((val) => val === item.id)
d.arizona's avatar
d.arizona committed
265
        let listCompany = this.state.listCompany
d.arizona's avatar
d.arizona committed
266
        let company = this.state.company
d.arizona's avatar
d.arizona committed
267
        if (indexID === -1) {
d.arizona's avatar
d.arizona committed
268
            company.push(item.id)
d.arizona's avatar
d.arizona committed
269 270 271 272 273 274 275 276 277
            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) {
Deni Rinaldi's avatar
Deni Rinaldi committed
278
                    item.children.map((items, indexs) => {
d.arizona's avatar
d.arizona committed
279 280 281 282
                        this.handleItemClick(items)
                    })
                }
            }
d.arizona's avatar
d.arizona committed
283 284
        } else {
            company.splice(indexID, 1)
d.arizona's avatar
d.arizona committed
285 286 287 288
            if (item.parent !== null) {
                let indexIDs = this.state.company.findIndex((val) => val === item.parent)
                if (indexIDs !== -1) {
                    company.splice(indexIDs, 1)
Deni Rinaldi's avatar
Deni Rinaldi committed
289
                }
d.arizona's avatar
d.arizona committed
290 291
                if (item.children !== null) {
                    if (item.children.length > 0) {
Deni Rinaldi's avatar
Deni Rinaldi committed
292
                        item.children.map((items, indexs) => {
d.arizona's avatar
d.arizona committed
293 294 295 296 297
                            this.handleItemClick(items)
                        })
                    }
                }
            }
d.arizona's avatar
d.arizona committed
298 299 300
        }
        this.setState({ company })
    }
d.arizona's avatar
d.arizona committed
301

d.arizona's avatar
d.arizona committed
302 303 304 305 306
    renderChildren = (item, pad) => {
        let padding = null
        if (pad !== undefined) {
            padding = pad
        } else {
d.arizona's avatar
d.arizona committed
307
            padding = 30
d.arizona's avatar
d.arizona committed
308 309
        }
        return (
a.bairuha's avatar
a.bairuha committed
310 311 312 313 314 315 316
            <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
317
                                    <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
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
                                        {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
344
                                        </span>
a.bairuha's avatar
a.bairuha committed
345 346
                                        <Typography style={{ fontSize: 12 }}>{titleCase(data.company_name)}</Typography>
                                    </div>
d.arizona's avatar
d.arizona committed
347
                                    {!R.isNil(data.children) && this.renderChildren(data, padding + 30)}
a.bairuha's avatar
a.bairuha committed
348 349 350 351 352 353 354
                                </Collapse>
                                // </li>
                            )
                        })}
                    </ul>
                )}
            </div>
d.arizona's avatar
d.arizona committed
355 356 357 358
        )
    }

    handleCollapse(item) {
Deni Rinaldi's avatar
Deni Rinaldi committed
359
        let path = this.searchIt({ children: this.state.listCompany }, item.id)
d.arizona's avatar
d.arizona committed
360 361 362 363 364
        let listCompany = this.state.listCompany
        let arrayPath = []

        if (path.length > 1) {
            arrayPath = path.split('-');
Deni Rinaldi's avatar
Deni Rinaldi committed
365
            arrayPath = arrayPath.map((item) => { return item })
d.arizona's avatar
d.arizona committed
366 367 368 369 370 371
        } else {
            arrayPath.push(path)
        }

        let pathSelect = null
        if (arrayPath.length == 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
372
            pathSelect = listCompany[arrayPath[0]]
d.arizona's avatar
d.arizona committed
373
        } else if (arrayPath.length == 2) {
Deni Rinaldi's avatar
Deni Rinaldi committed
374
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]]
d.arizona's avatar
d.arizona committed
375
        } else if (arrayPath.length == 3) {
Deni Rinaldi's avatar
Deni Rinaldi committed
376
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]]
d.arizona's avatar
d.arizona committed
377
        } else if (arrayPath.length == 4) {
Deni Rinaldi's avatar
Deni Rinaldi committed
378
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]]
d.arizona's avatar
d.arizona committed
379
        } else if (arrayPath.length == 5) {
Deni Rinaldi's avatar
Deni Rinaldi committed
380
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]].children[arrayPath[4]]
d.arizona's avatar
d.arizona committed
381
        } else if (arrayPath.length == 6) {
Deni Rinaldi's avatar
Deni Rinaldi committed
382
            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
383
        } else if (arrayPath.length == 7) {
Deni Rinaldi's avatar
Deni Rinaldi committed
384
            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
385 386 387 388
        }

        pathSelect.collapse = !pathSelect.collapse
        // console.log(pathSelect.collapse)
Deni Rinaldi's avatar
Deni Rinaldi committed
389
        this.setState({ listCompany }, () => console.log(pathSelect))
d.arizona's avatar
d.arizona committed
390 391 392
    }

    searchIt = (node, search, path = '', position = 0) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
393 394
        if (node.id && node.id === search) { return path !== '' ? `${path}-${position}` : position; }
        if (!node.children) { return false }
d.arizona's avatar
d.arizona committed
395
        const index = node.children.findIndex((x) => x.id && x.id === search);
d.arizona's avatar
d.arizona committed
396
        if (index >= 0) {
Deni Rinaldi's avatar
Deni Rinaldi committed
397
            return path !== '' ? `${path}-${index}` : index;
d.arizona's avatar
d.arizona committed
398
        }
d.arizona's avatar
d.arizona committed
399
        for (let i = 0; i < node.children.length; i++) {
Deni Rinaldi's avatar
Deni Rinaldi committed
400 401 402 403
            const result = this.searchIt(node.children[i], search, path !== '' ? `${path}-${i}` : i, i);
            if (result) {
                return result;
            }
d.arizona's avatar
d.arizona committed
404 405 406 407
        }
        return false;
    };

a.bairuha's avatar
a.bairuha committed
408
    closeAlert() {
Deni Rinaldi's avatar
Deni Rinaldi committed
409
        this.setState({ alert: false })
a.bairuha's avatar
a.bairuha committed
410 411
    }

d.arizona's avatar
d.arizona committed
412 413 414
    render() {
        return (
            <div className="test app-popup-show">
a.bairuha's avatar
a.bairuha committed
415 416 417 418 419
                <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
420
                <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
421
                    <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
d.arizona's avatar
d.arizona committed
422 423
                        <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                            <div className="popup-title">
d.arizona's avatar
d.arizona committed
424
                                <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Create Data</span>
d.arizona's avatar
d.arizona committed
425 426 427 428 429 430 431 432
                            </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
433
                                <img src={Images.close} />
d.arizona's avatar
d.arizona committed
434 435 436 437 438 439
                            </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
440
                            <div className="">
d.arizona's avatar
d.arizona committed
441 442 443 444 445 446 447
                                <TextField
                                    style={{ width: '100%' }}
                                    id="id"
                                    label="ID"
                                    disabled
                                    // id="outlined-read-only-input"
                                    variant="filled"
d.arizona's avatar
d.arizona committed
448
                                    value={'-'}
d.arizona's avatar
d.arizona committed
449
                                    onChange={(e) => null}
a.bairuha's avatar
a.bairuha committed
450 451 452 453 454 455 456 457 458 459 460 461 462
                                    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
463 464 465 466 467 468 469 470 471 472 473
                                >
                                    {/* {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
474 475
                            <div className="">
                                <TextField
Deni Rinaldi's avatar
Deni Rinaldi committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
                                    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
497 498 499 500 501 502 503 504 505
                                // 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
506 507
                            <div className="margin-bottom-20px">
                                <TextField
Deni Rinaldi's avatar
Deni Rinaldi committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
                                    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
529 530 531 532 533
                                // defaultValue="Default Value"
                                // helperText="Some important text"
                                />
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
534 535 536 537 538 539

                        <div className="column-2">
                            <div className="margin-bottom-20px">
                                <Autocomplete
                                    {...this.state.listRole}
                                    id="role"
Deni Rinaldi's avatar
Deni Rinaldi committed
540
                                    onChange={(event, newInputValue) => this.setState({ role: newInputValue }, () => this.clearError())}
d.arizona's avatar
d.arizona committed
541
                                    debug
Deni Rinaldi's avatar
Deni Rinaldi committed
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
                                    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
559
                                        />}
d.arizona's avatar
d.arizona committed
560 561 562 563
                                    value={this.state.role}
                                />
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
564 565 566
                    </div>

                    <div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
567
                        <div className="column-1">
d.arizona's avatar
d.arizona committed
568
                            <div className="margin-bottom-20px">
d.arizona's avatar
d.arizona committed
569 570 571
                                <DatePicker
                                    margin="normal"
                                    id="startDate"
572
                                    label="Valid From"
d.arizona's avatar
d.arizona committed
573 574 575 576 577 578 579 580
                                    format="dd MMMM yyyy"
                                    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
581 582 583 584 585 586 587 588 589 590 591 592 593
                                    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
594 595

                                    style={{ padding: 0, margin: 0, width: '100%' }}
d.arizona's avatar
d.arizona committed
596 597 598 599 600 601
                                />
                            </div>
                        </div>

                        <div className="column-2">
                            <div className="margin-bottom-20px">
d.arizona's avatar
d.arizona committed
602 603 604
                                <DatePicker
                                    margin="normal"
                                    id="endDate"
605
                                    label="Valid To"
d.arizona's avatar
d.arizona committed
606 607 608 609 610 611 612 613 614
                                    format="dd MMMM yyyy"
                                    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
615 616 617 618 619 620 621 622 623 624 625 626 627
                                    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
628 629

                                    style={{ padding: 0, margin: 0, width: '100%' }}
d.arizona's avatar
d.arizona committed
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
                                />
                            </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
645
                                    value={'Active'}
a.bairuha's avatar
a.bairuha committed
646 647 648 649 650 651 652 653 654 655 656 657 658
                                    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
659 660 661 662 663 664 665 666 667 668 669 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>

                        <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
679
                                    value={'N'}
a.bairuha's avatar
a.bairuha committed
680 681 682 683 684 685 686 687 688 689 690 691 692
                                    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
693 694 695 696 697 698 699 700 701 702
                                >
                                    {/* {periode.map((option) => (
                                        <MenuItem key={option.value} value={option.value}>
                                            {option.label}
                                        </MenuItem>
                                    ))} */}
                                </TextField>
                            </div>
                        </div>
                    </div>
d.arizona's avatar
d.arizona committed
703
                    {/* <div style={{ flexDirection: 'column', display: 'flex', paddingLeft: 20, paddingRight: 20 }}>
a.bairuha's avatar
a.bairuha committed
704 705
                        <Typography style={{ fontSize: 12 }}>{`Dibuat: `}</Typography>
                        <Typography style={{fontSize: 12}}>{`Diubah: `}</Typography>
d.arizona's avatar
d.arizona committed
706
                    </div> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
707 708
                    <Divider style={{ margin: 20 }} />
                    <div style={{ paddingLeft: 20, paddingRight: 20 }}>
d.arizona's avatar
d.arizona committed
709
                        <h5>Authorization Company</h5>
Deni Rinaldi's avatar
Deni Rinaldi committed
710 711 712
                        <div style={{ paddingLeft: 10, overflow: 'scroll', height: '25vh' }}>
                            {this.state.listCompany.map((item, index) => {
                                return (
d.arizona's avatar
d.arizona committed
713
                                    <div>
d.arizona's avatar
d.arizona committed
714 715
                                        {/* <ul>
                                            <li> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
716
                                        <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start' }}>
717
                                            {item.children && item.children.length > 0 && <span onClick={() => this.handleCollapse(item)} style={{ marginLeft: 7, marginRight: 2 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
                                                {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
741
                                        </ul> */}
d.arizona's avatar
d.arizona committed
742 743 744 745
                                    </div>
                                )
                            })}
                        </div>
d.arizona's avatar
d.arizona committed
746 747 748
                    </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
749 750
                            <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
751
                                    <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
d.arizona's avatar
d.arizona committed
752 753
                                </div>
                            </button>
d.arizona's avatar
d.arizona committed
754
                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
755
                        <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
d.arizona's avatar
d.arizona committed
756 757
                            <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
758
                                    <span style={{ color: '#fff', fontSize: 11 }}>Save</span>
d.arizona's avatar
d.arizona committed
759 760
                                </div>
                            </button>
d.arizona's avatar
d.arizona committed
761 762 763 764 765 766 767
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}