AddUser.js 34.3 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';
d.arizona's avatar
d.arizona committed
14 15 16 17

const CustomCheckbox = withStyles({
    root: {
        color: '#51c6ea',
Deni Rinaldi's avatar
Deni Rinaldi committed
18 19 20
        '&$checked': {
            color: '#51c6ea',
        },
d.arizona's avatar
d.arizona committed
21 22
    },
    checked: {},
Deni Rinaldi's avatar
Deni Rinaldi committed
23 24 25 26 27 28 29 30 31 32 33
})((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
34

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

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

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

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

d.arizona's avatar
d.arizona committed
77
    componentDidMount() {
d.arizona's avatar
d.arizona committed
78
        this.getRole()
d.arizona's avatar
d.arizona committed
79
        this.getPerusahaan()
a.bairuha's avatar
a.bairuha committed
80 81 82 83 84 85 86 87 88 89
        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
90 91
    }

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

a.bairuha's avatar
a.bairuha committed
137 138 139 140 141
    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
142
    validasi() {
a.bairuha's avatar
a.bairuha committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
        var isEmail = this.isEmail(this.state.email)

        if (R.isEmpty(this.state.fullname)) {
            this.setState({ errorFullname: true, msgErrorFN: 'Nama Lengkap tidak boleh kosong' })
        } else if (R.isEmpty(this.state.email)) {
            this.setState({ errorEmail: true, msgErrorEM: 'Email tidak boleh kosong' })
        } else if (!isEmail) {
            this.setState({ errorEmail: true, msgErrorEM: 'Format email tidak sesuai!' })
        } else if (R.isNil(this.state.role)) {
            this.setState({ errorRoleName: true, msgErrorRN: 'Role Name tidak boleh kosong' })
        } else if (R.isNil(this.state.startDate)) {
            this.setState({ errorStartDate: true, msgErrorSD: 'Start Date tidak boleh kosong' })
        } else if (R.isNil(this.state.endDate)) {
            this.setState({ errorEndDate: true, msgErrorED: 'End Date tidak boleh kosong' })
        }
        // else if (this.state.privileges.length < 1) {
        //     alert('Hak Akses belum di pilih !!')
        // } 
        else {
d.arizona's avatar
d.arizona committed
162
        this.createUser()
a.bairuha's avatar
a.bairuha committed
163
        }
d.arizona's avatar
d.arizona committed
164 165
    }

d.arizona's avatar
d.arizona committed
166
    createUser() {
d.arizona's avatar
d.arizona committed
167
        let payload = {
d.arizona's avatar
d.arizona committed
168 169 170 171 172 173 174
            "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
d.arizona's avatar
d.arizona committed
175
        }
d.arizona's avatar
d.arizona committed
176
        api.create().createUser(payload).then((response) => {
d.arizona's avatar
d.arizona committed
177 178
            // console.log(response)
            // if (String(response.data.status).toLocaleUpperCase === 'Success' || String(response.data.status).toLocaleUpperCase === 'success') {
a.bairuha's avatar
a.bairuha committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                        this.props.onClickClose()
                        this.props.refresh()
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
                    }
                } 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
195
            // } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
196
            // alert(response.data.message)
d.arizona's avatar
d.arizona committed
197 198 199
            //     this.props.onClickClose()
            //     this.props.refresh()
            // }
d.arizona's avatar
d.arizona committed
200
        })
d.arizona's avatar
d.arizona committed
201 202
    }

d.arizona's avatar
d.arizona committed
203
    getRole() {
204
        api.create().getRoleActive().then((response) => {
a.bairuha's avatar
a.bairuha committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
            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 {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
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 240 241 242 243 244 245 246
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === 'success') {
                        this.setState({ listCompany: response.data.data })
                        console.log(response.data.data)
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
                    }
                } 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
247 248 249 250 251
            }
        })
    }

    handleItemChecked(item) {
d.arizona's avatar
d.arizona committed
252
        let indexID = this.state.company.findIndex((val) => val === item.id)
d.arizona's avatar
d.arizona committed
253
        return indexID === -1 ? false : true
d.arizona's avatar
d.arizona committed
254 255 256
    }

    handleItemClick(item) {
d.arizona's avatar
d.arizona committed
257
        let indexID = this.state.company.findIndex((val) => val === item.id)
d.arizona's avatar
d.arizona committed
258
        let company = this.state.company
d.arizona's avatar
d.arizona committed
259
        if (indexID === -1) {
d.arizona's avatar
d.arizona committed
260
            company.push(item.id)
d.arizona's avatar
d.arizona committed
261 262 263 264 265
        } else {
            company.splice(indexID, 1)
        }
        this.setState({ company })
    }
d.arizona's avatar
d.arizona committed
266

d.arizona's avatar
d.arizona committed
267 268 269 270 271 272 273 274 275
    renderChildren = (item, pad) => {
        let padding = null
        if (pad !== undefined) {
            padding = pad
        } else {
            padding = 20
        }
        return (
            <ul>
d.arizona's avatar
d.arizona committed
276
                {item.children.map((data, index) => {
d.arizona's avatar
d.arizona committed
277
                    return (
d.arizona's avatar
d.arizona committed
278
                        // <li>
Deni Rinaldi's avatar
Deni Rinaldi committed
279 280 281 282 283 284
                        <Collapse key={index} timeout="auto" unmountOnExit in={item.collapse}>
                            <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start', paddingLeft: R.isNil(data.children) ? (padding + 20) : padding }}>
                                {R.isNil(data.children) ?
                                    null
                                    :
                                    data.children.length < 1 ?
d.arizona's avatar
d.arizona committed
285 286 287
                                        null
                                        :
                                        <span onClick={() => this.handleCollapse(data)} style={{ marginLeft: 7, marginRight: 2 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
288 289 290 291 292 293 294 295 296 297 298 299 300 301
                                            {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)}
                                        /> :
d.arizona's avatar
d.arizona committed
302 303 304 305
                                        <CustomCheckbox
                                            checked={this.handleItemChecked(data)}
                                            onChange={() => this.handleItemClick(data)}
                                        />
Deni Rinaldi's avatar
Deni Rinaldi committed
306 307 308 309 310 311
                                    }
                                </span>
                                <Typography style={{ fontSize: 12 }}>{titleCase(data.company_name)}</Typography>
                            </div>
                            {!R.isNil(data.children) && this.renderChildren(data, padding + 20)}
                        </Collapse>
d.arizona's avatar
d.arizona committed
312
                        // </li>
d.arizona's avatar
d.arizona committed
313 314 315 316 317 318 319
                    )
                })}
            </ul>
        )
    }

    handleCollapse(item) {
Deni Rinaldi's avatar
Deni Rinaldi committed
320
        let path = this.searchIt({ children: this.state.listCompany }, item.id)
d.arizona's avatar
d.arizona committed
321 322 323 324 325
        let listCompany = this.state.listCompany
        let arrayPath = []

        if (path.length > 1) {
            arrayPath = path.split('-');
Deni Rinaldi's avatar
Deni Rinaldi committed
326
            arrayPath = arrayPath.map((item) => { return item })
d.arizona's avatar
d.arizona committed
327 328 329 330 331 332
        } else {
            arrayPath.push(path)
        }

        let pathSelect = null
        if (arrayPath.length == 1) {
Deni Rinaldi's avatar
Deni Rinaldi committed
333
            pathSelect = listCompany[arrayPath[0]]
d.arizona's avatar
d.arizona committed
334
        } else if (arrayPath.length == 2) {
Deni Rinaldi's avatar
Deni Rinaldi committed
335
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]]
d.arizona's avatar
d.arizona committed
336
        } else if (arrayPath.length == 3) {
Deni Rinaldi's avatar
Deni Rinaldi committed
337
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]]
d.arizona's avatar
d.arizona committed
338
        } else if (arrayPath.length == 4) {
Deni Rinaldi's avatar
Deni Rinaldi committed
339
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]]
d.arizona's avatar
d.arizona committed
340
        } else if (arrayPath.length == 5) {
Deni Rinaldi's avatar
Deni Rinaldi committed
341
            pathSelect = listCompany[arrayPath[0]].children[arrayPath[1]].children[arrayPath[2]].children[arrayPath[3]].children[arrayPath[4]]
d.arizona's avatar
d.arizona committed
342
        } else if (arrayPath.length == 6) {
Deni Rinaldi's avatar
Deni Rinaldi committed
343
            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
344
        } else if (arrayPath.length == 7) {
Deni Rinaldi's avatar
Deni Rinaldi committed
345
            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
346 347 348 349
        }

        pathSelect.collapse = !pathSelect.collapse
        // console.log(pathSelect.collapse)
Deni Rinaldi's avatar
Deni Rinaldi committed
350
        this.setState({ listCompany }, () => console.log(pathSelect))
d.arizona's avatar
d.arizona committed
351 352 353
    }

    searchIt = (node, search, path = '', position = 0) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
354 355
        if (node.id && node.id === search) { return path !== '' ? `${path}-${position}` : position; }
        if (!node.children) { return false }
d.arizona's avatar
d.arizona committed
356
        const index = node.children.findIndex((x) => x.id && x.id === search);
d.arizona's avatar
d.arizona committed
357
        if (index >= 0) {
Deni Rinaldi's avatar
Deni Rinaldi committed
358
            return path !== '' ? `${path}-${index}` : index;
d.arizona's avatar
d.arizona committed
359
        }
d.arizona's avatar
d.arizona committed
360
        for (let i = 0; i < node.children.length; i++) {
Deni Rinaldi's avatar
Deni Rinaldi committed
361 362 363 364
            const result = this.searchIt(node.children[i], search, path !== '' ? `${path}-${i}` : i, i);
            if (result) {
                return result;
            }
d.arizona's avatar
d.arizona committed
365 366 367 368
        }
        return false;
    };

a.bairuha's avatar
a.bairuha committed
369 370 371 372
    closeAlert() {
      this.setState({ alert: false })
    }

d.arizona's avatar
d.arizona committed
373 374 375
    render() {
        return (
            <div className="test app-popup-show">
a.bairuha's avatar
a.bairuha committed
376 377 378 379 380
                <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
381
                <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
382
                    <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
d.arizona's avatar
d.arizona committed
383 384 385 386 387 388 389 390 391 392 393
                        <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                            <div className="popup-title">
                                <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Ubah Data</span>
                            </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
394
                                <img src={Images.close} />
d.arizona's avatar
d.arizona committed
395 396 397 398 399 400
                            </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
401
                            <div className="">
d.arizona's avatar
d.arizona committed
402 403 404 405 406 407 408
                                <TextField
                                    style={{ width: '100%' }}
                                    id="id"
                                    label="ID"
                                    disabled
                                    // id="outlined-read-only-input"
                                    variant="filled"
d.arizona's avatar
d.arizona committed
409
                                    value={'-'}
d.arizona's avatar
d.arizona committed
410
                                    onChange={(e) => null}
a.bairuha's avatar
a.bairuha committed
411 412 413 414 415 416 417 418 419 420 421 422 423
                                    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
424 425 426 427 428 429 430 431 432 433 434
                                >
                                    {/* {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
435 436 437 438 439 440
                            <div className="">
                                <TextField
                                style={{ width: '100%' , marginTop: 7}}
                                id="fullname"
                                name="fullname"
                                label="Nama Lengkap"
d.arizona's avatar
d.arizona committed
441
                                value={this.state.fullname}
a.bairuha's avatar
a.bairuha committed
442 443
                                error={this.state.errorFullname}
                                helperText={this.state.msgErrorFN}
d.arizona's avatar
d.arizona committed
444
                                onChange={(e) => this.handleChange(e, '')}
a.bairuha's avatar
a.bairuha committed
445 446 447 448 449 450 451 452 453 454 455 456 457
                                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
458 459 460 461 462 463 464 465 466
                                // 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
467 468 469
                            <div className="margin-bottom-20px">
                                <TextField
                                style={{ width: '100%' , marginTop: 7}}
d.arizona's avatar
d.arizona committed
470 471 472
                                id="email"
                                name="email"
                                label="Email"
d.arizona's avatar
d.arizona committed
473
                                value={this.state.email}
a.bairuha's avatar
a.bairuha committed
474 475
                                error={this.state.errorEmail}
                                helperText={this.state.msgErrorEM}
d.arizona's avatar
d.arizona committed
476
                                onChange={(e) => this.handleChange(e, '')}
a.bairuha's avatar
a.bairuha committed
477 478 479 480 481 482 483 484 485 486 487 488 489
                                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
490 491 492 493 494
                                // defaultValue="Default Value"
                                // helperText="Some important text"
                                />
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
495 496 497 498 499 500

                        <div className="column-2">
                            <div className="margin-bottom-20px">
                                <Autocomplete
                                    {...this.state.listRole}
                                    id="role"
Deni Rinaldi's avatar
Deni Rinaldi committed
501
                                    onChange={(event, newInputValue) => this.setState({ role: newInputValue })}
d.arizona's avatar
d.arizona committed
502
                                    debug
a.bairuha's avatar
a.bairuha committed
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
                                    renderInput={(params) => 
                                    <TextField 
                                        {...params} 
                                        label="Role" 
                                        margin="normal" 
                                        style={{marginTop: 7}}
                                        onChange={(e) => this.handleChange(e, '')}
                                        error={this.state.errorRoleName}
                                        helperText={this.state.msgErrorRN}
                                        InputLabelProps={{
                                            style: {
                                                fontSize: 11,
                                                fontFamily: 'Nunito Sans, sans-serif',
                                                color: '#7e8085'
                                            }
                                        }}
                                        InputProps={{ ...params.InputProps, style: { fontSize: 11, fontFamily: 'Nunito Sans, sans-serif' } }}
                                        />}
d.arizona's avatar
d.arizona committed
521 522 523 524
                                    value={this.state.role}
                                />
                            </div>
                        </div>
d.arizona's avatar
d.arizona committed
525 526 527
                    </div>

                    <div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
528
                        <div className="column-1">
d.arizona's avatar
d.arizona committed
529
                            <div className="margin-bottom-20px">
d.arizona's avatar
d.arizona committed
530 531 532 533 534 535 536 537 538 539 540 541
                                <DatePicker
                                    margin="normal"
                                    id="startDate"
                                    label="Berlaku Mulai"
                                    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
542 543 544 545 546 547 548 549 550 551 552 553 554
                                    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
555 556

                                    style={{ padding: 0, margin: 0, width: '100%' }}
d.arizona's avatar
d.arizona committed
557 558 559 560 561 562
                                />
                            </div>
                        </div>

                        <div className="column-2">
                            <div className="margin-bottom-20px">
d.arizona's avatar
d.arizona committed
563 564 565 566 567 568 569 570 571 572 573 574 575
                                <DatePicker
                                    margin="normal"
                                    id="endDate"
                                    label="Berlaku Hingga"
                                    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
576 577 578 579 580 581 582 583 584 585 586 587 588
                                    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
589 590

                                    style={{ padding: 0, margin: 0, width: '100%' }}
d.arizona's avatar
d.arizona committed
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
                                />
                            </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
606
                                    value={'Aktif'}
a.bairuha's avatar
a.bairuha committed
607 608 609 610 611 612 613 614 615 616 617 618 619
                                    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
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
                                >
                                    {/* {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"
                                    value={'T'}
a.bairuha's avatar
a.bairuha committed
641 642 643 644 645 646 647 648 649 650 651 652 653
                                    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
654 655 656 657 658 659 660 661 662 663
                                >
                                    {/* {periode.map((option) => (
                                        <MenuItem key={option.value} value={option.value}>
                                            {option.label}
                                        </MenuItem>
                                    ))} */}
                                </TextField>
                            </div>
                        </div>
                    </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
664 665
                    <div style={{ flexDirection: 'column', display: 'flex', paddingLeft: 20, paddingRight: 20 }}>
                        <Typography style={{ fontSize: 12 }}>{`Dibuat  : ${format(this.state.date, 'dd MMMM yyyy', { locale: localeID })}`}</Typography>
d.arizona's avatar
d.arizona committed
666
                        {/* <Typography style={{fontSize: 12}}>{`Diubah: ${this.state.tempData === null? '' : this.state.tempData.updated}`}</Typography> */}
d.arizona's avatar
d.arizona committed
667
                    </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
668 669
                    <Divider style={{ margin: 20 }} />
                    <div style={{ paddingLeft: 20, paddingRight: 20 }}>
d.arizona's avatar
d.arizona committed
670
                        <h5>Otorisasi Perusahaan</h5>
Deni Rinaldi's avatar
Deni Rinaldi committed
671 672 673
                        <div style={{ paddingLeft: 10, overflow: 'scroll', height: '25vh' }}>
                            {this.state.listCompany.map((item, index) => {
                                return (
d.arizona's avatar
d.arizona committed
674
                                    <div>
d.arizona's avatar
d.arizona committed
675 676
                                        {/* <ul>
                                            <li> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
                                        <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start' }}>
                                            {item.children.length > 0 && <span onClick={() => this.handleCollapse(item)} style={{ marginLeft: 7, marginRight: 2 }}>
                                                {item.collapse ? <RemoveIcon color={'action'} fontSize={'small'} /> : <AddIcon color={'action'} fontSize={'small'} />}
                                            </span>}
                                            <span>
                                                {this.state.role ? this.state.role.role_id === 1 ?
                                                    <CustomCheckboxDisabled
                                                        disabled={true}
                                                        checked={true}
                                                    // onChange={() => this.handleItemClick(item)}
                                                    /> :
                                                    <CustomCheckbox
                                                        checked={this.handleItemChecked(item)}
                                                        onChange={() => this.handleItemClick(item)}
                                                    /> :
                                                    <CustomCheckbox
                                                        checked={this.handleItemChecked(item)}
                                                        onChange={() => this.handleItemClick(item)}
                                                    />
                                                }
                                            </span>
                                            <Typography style={{ fontSize: 12 }}>{titleCase(item.company_name)}</Typography>
                                        </div>
                                        {!R.isNil(item.children) && this.renderChildren(item)}
                                        {/* </li>
d.arizona's avatar
d.arizona committed
702
                                        </ul> */}
d.arizona's avatar
d.arizona committed
703 704 705 706
                                    </div>
                                )
                            })}
                        </div>
d.arizona's avatar
d.arizona committed
707 708 709
                    </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
710 711 712 713 714
                            <button onClick={() => this.props.onClickClose()}>
                                <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                    <span style={{ color: '#354960', fontSize: 11 }}>Batal</span>
                                </div>
                            </button>
d.arizona's avatar
d.arizona committed
715
                        </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
716
                        <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
d.arizona's avatar
d.arizona committed
717 718 719 720 721
                            <button onClick={() => this.validasi()}>
                                <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
                                    <span style={{ color: '#fff', fontSize: 11 }}>Simpan</span>
                                </div>
                            </button>
d.arizona's avatar
d.arizona committed
722 723 724 725 726 727 728
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}