User.js 24.6 KB
Newer Older
d.arizona's avatar
d.arizona committed
1
import React, { Component } from "react";
d.arizona's avatar
d.arizona committed
2
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
d.arizona's avatar
d.arizona committed
3 4
import SearchIcon from '@material-ui/icons/Search';
import Images from "../../assets/Images";
d.arizona's avatar
d.arizona committed
5
import MUIDataTable from "mui-datatables";
d.arizona's avatar
d.arizona committed
6 7
import AddUser from './User/AddUser';
import EditUser from './User/EditUser'
d.arizona's avatar
d.arizona committed
8 9
import api from "../../api";
import { titleCase } from "../../library/Utils";
a.bairuha's avatar
a.bairuha committed
10 11
import { InputAdornment, Snackbar, InputBase } from "@material-ui/core";
import MuiAlert from '@material-ui/lab/Alert';
d.arizona's avatar
d.arizona committed
12
import UploadFile from "../../library/Upload";
a.bairuha's avatar
a.bairuha committed
13
import { withStyles } from '@material-ui/core/styles';
d.arizona's avatar
d.arizona committed
14
import { ExcelRenderer } from 'react-excel-renderer';
Deni Rinaldi's avatar
Deni Rinaldi committed
15 16
import ReactTooltip from "react-tooltip";
import PopUpFailedSave from "../../library/PopUpFailedSave";
d.arizona's avatar
d.arizona committed
17 18 19 20 21

var ct = require("../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());
const options = ct.customOptions();

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

d.arizona's avatar
d.arizona committed
25 26 27 28
export default class UserRole extends Component {
  constructor(props) {
    super(props)
    this.state = {
d.arizona's avatar
d.arizona committed
29
      listUser: [],
d.arizona's avatar
d.arizona committed
30 31
      indexData: {},
      add: false,
d.arizona's avatar
d.arizona committed
32
      edit: false,
d.arizona's avatar
d.arizona committed
33 34
      visibleUser: true,
      buttonError: false,
a.bairuha's avatar
a.bairuha committed
35 36 37
      alert: false,
      tipeAlert: '',
      messageAlert: ''
d.arizona's avatar
d.arizona committed
38 39 40 41
    }
  }

  componentDidMount() {
d.arizona's avatar
d.arizona committed
42
    this.getUser()
d.arizona's avatar
d.arizona committed
43 44 45
  }

  closeEdit() {
Deni Rinaldi's avatar
Deni Rinaldi committed
46
    this.setState({ edit: false })
d.arizona's avatar
d.arizona committed
47 48 49
  }

  closeAdd() {
Deni Rinaldi's avatar
Deni Rinaldi committed
50
    this.setState({ add: false })
d.arizona's avatar
d.arizona committed
51 52
  }

d.arizona's avatar
d.arizona committed
53 54
  getUser() {
    api.create().getUser().then((response) => {
a.bairuha's avatar
a.bairuha committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68
      if (response.data) {
        if (response.ok) {
            if (response.data.status === 'success') {
                let data = response.data.data
                let listData = data.sort((a, b) => a.user_id - b.user_id).map((item, index) => {
                  return [index, item.user_id, item.fullname === null ? '-' : item.fullname, item.email, item.role_name, item.totalCompany, item.status]
                })
                this.setState({ listUser: listData })
            } else {
                this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) 
            }
        } else {
            this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })    
        }
d.arizona's avatar
d.arizona committed
69
      } else {
a.bairuha's avatar
a.bairuha committed
70
        this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
71 72 73 74
      }
    })
  }

d.arizona's avatar
d.arizona committed
75 76 77 78 79
  searchUser() {
    let payload = {
      "keyword": this.state.search
    }
    api.create().searchUser(payload).then((response) => {
a.bairuha's avatar
a.bairuha committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93
      if (response.data) {
        if (response.ok) {
            if (response.data.status === 'success') {
                let data = response.data.data
                let listData = data.sort((a, b) => a.user_id - b.user_id).map((item, index) => {
                  return [index, item.user_id, item.fullname == null ? '-' : item.fullname, item.email, item.role_name, item.totalCompany, item.status]
                })
                this.setState({ listUser: listData })
              } else {                
                  this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) 
              }
        } else {
            this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })    
        }
d.arizona's avatar
d.arizona committed
94
      } else {
a.bairuha's avatar
a.bairuha committed
95
        this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
d.arizona's avatar
d.arizona committed
96
      }
Deni Rinaldi's avatar
Deni Rinaldi committed
97
    })
d.arizona's avatar
d.arizona committed
98 99
  }

d.arizona's avatar
d.arizona committed
100 101 102
  fileHandler = (event) => {
    let fileObj = event
    ExcelRenderer(fileObj, (err, resp) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
103 104 105 106
      if (err) {
        console.log(err);
      }
      else {
d.arizona's avatar
d.arizona committed
107
        // let judul = resp.rows[0]
Deni Rinaldi's avatar
Deni Rinaldi committed
108 109
        let isi = resp.rows.slice(3)
        let payload = []
d.arizona's avatar
d.arizona committed
110
        console.log(isi)
Deni Rinaldi's avatar
Deni Rinaldi committed
111
        isi.map((item, index) => {
d.arizona's avatar
d.arizona committed
112 113 114 115 116 117 118 119 120 121
          if (item.length > 0) {
            payload.push({
              id: index + 1,
              fullname: item[0],
              email: item[1],
              role: item[2],
              start_date: item[3],
              end_date: item[4],
            })
          }
Deni Rinaldi's avatar
Deni Rinaldi committed
122 123 124
        })
        let body = {
          user: payload
d.arizona's avatar
d.arizona committed
125
        }
d.arizona's avatar
d.arizona committed
126
        this.setState({ payload: body, rows: []})
Deni Rinaldi's avatar
Deni Rinaldi committed
127 128
        api.create().checkUploadUser(body).then(response => {
          console.log(response);
a.bairuha's avatar
a.bairuha committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
          if (response.data) {
            if (response.data.status === "success") {
                let dataRow = response.data.data.map((item, index) => {
                  return [
                    index + 1,
                    item.fullname,
                    item.email,
                    item.role,
                    item.start_date,
                    item.end_date,
                    item.error
                  ]
                })
    
                let columns = [
                  "Data Ke-",
d.arizona's avatar
d.arizona committed
145
                  "Full Name",
a.bairuha's avatar
a.bairuha committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
                  {
                    name: "Email",
                    options: {
                      customBodyRender: (val, tableMeta) => {
                        console.log(tableMeta)
                        let check = null
                        if (tableMeta.rowData[6] != null) {
                          check = tableMeta.rowData[6].findIndex((val) => val.field.includes('email'))
                          if (check > -1) {
                            this.setState({ buttonError: true })
                          }
                        }
                        return (
                          <div style={{ display: 'flex' }}>
                            {tableMeta.rowData[6] != null && check > -1 ?
                              <a data-tip={tableMeta.rowData[6][check].message} data-for="email">
                                <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                              </a> :
                              <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                            }
                            <ReactTooltip border={true} id="email" place="bottom" type="light" effect="solid" />
                          </div >
                        );
Deni Rinaldi's avatar
Deni Rinaldi committed
169 170
                      }
                    }
a.bairuha's avatar
a.bairuha committed
171 172 173 174 175 176 177 178 179 180 181
                  },
                  {
                    name: "Role",
                    options: {
                      customBodyRender: (val, tableMeta) => {
                        let check = null
                        if (tableMeta.rowData[6] != null) {
                          check = tableMeta.rowData[6].findIndex((val) => val.field.includes('role'))
                          if (check > -1) {
                            this.setState({ buttonError: true })
                          }
Deni Rinaldi's avatar
Deni Rinaldi committed
182
                        }
a.bairuha's avatar
a.bairuha committed
183 184 185 186 187 188 189 190 191 192 193
                        return (
                          <div style={{ display: 'flex' }}>
                            {tableMeta.rowData[6] != null && check > -1 ?
                              <a data-tip={tableMeta.rowData[6][check].message} data-for="role">
                                <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                              </a> :
                              <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                            }
                            <ReactTooltip border={true} id="role" place="bottom" type="light" effect="solid" />
                          </div >
                        );
Deni Rinaldi's avatar
Deni Rinaldi committed
194 195
                      }
                    }
a.bairuha's avatar
a.bairuha committed
196 197 198 199 200 201 202 203 204 205 206
                  },
                  {
                    name: "Berlaku Mulai",
                    options: {
                      customBodyRender: (val, tableMeta) => {
                        let check = null
                        if (tableMeta.rowData[6] != null) {
                          check = tableMeta.rowData[6].findIndex((val) => val.field.includes('start_date'))
                          if (check > -1) {
                            this.setState({ buttonError: true })
                          }
Deni Rinaldi's avatar
Deni Rinaldi committed
207
                        }
a.bairuha's avatar
a.bairuha committed
208 209 210 211 212 213 214 215 216 217 218
                        return (
                          <div style={{ display: 'flex' }}>
                            {tableMeta.rowData[6] != null && check > -1 ?
                              <a data-tip={tableMeta.rowData[6][check].message} data-for="startdate">
                                <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                              </a> :
                              <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                            }
                            <ReactTooltip border={true} id="startdate" place="bottom" type="light" effect="solid" />
                          </div >
                        );
Deni Rinaldi's avatar
Deni Rinaldi committed
219 220
                      }
                    }
a.bairuha's avatar
a.bairuha committed
221 222 223 224 225 226 227 228 229 230 231
                  },
                  {
                    name: "Berakhir Hingga",
                    options: {
                      customBodyRender: (val, tableMeta) => {
                        let check = null
                        if (tableMeta.rowData[6] != null) {
                          check = tableMeta.rowData[6].findIndex((val) => val.field.includes('end_date'))
                          if (check > -1) {
                            this.setState({ buttonError: true })
                          }
Deni Rinaldi's avatar
Deni Rinaldi committed
232
                        }
a.bairuha's avatar
a.bairuha committed
233 234 235 236 237 238 239 240 241 242 243
                        return (
                          <div style={{ display: 'flex' }}>
                            {tableMeta.rowData[6] != null && check > -1 ?
                              <a data-tip={tableMeta.rowData[6][check].message} data-for="enddate">
                                <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                              </a> :
                              <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
                            }
                            <ReactTooltip border={true} id="enddate" place="bottom" type="light" effect="solid" />
                          </div >
                        );
Deni Rinaldi's avatar
Deni Rinaldi committed
244 245
                      }
                    }
a.bairuha's avatar
a.bairuha committed
246 247 248 249 250 251
                  },
                  {
                    name: "",
                    options: {
                      display: false
                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
252
                  }
a.bairuha's avatar
a.bairuha committed
253 254 255 256 257 258 259
                ]
    
                this.setState({
                  dataLoaded: true,
                  cols: columns,
                  rows: dataRow
                });
Deni Rinaldi's avatar
Deni Rinaldi committed
260 261 262 263
              }
          }
        })
      }
d.arizona's avatar
d.arizona committed
264 265 266 267 268
    });
  }

  downloadFile = async () => {
    let res = await fetch(
Deni Rinaldi's avatar
Deni Rinaldi committed
269
      "https://tia.eksad.com/tia-reporting-dev/public/attachment/download_file?fileName=UserTemplate&&fileType=xlsx"
d.arizona's avatar
d.arizona committed
270 271 272 273
    )
    res = await res.blob()
    console.log(res)
    if (res.size > 0) {
Deni Rinaldi's avatar
Deni Rinaldi committed
274 275 276 277 278
      let url = window.URL.createObjectURL(res);
      let a = document.createElement('a');
      a.href = url;
      a.download = 'User Template.xlsx';
      a.click();
d.arizona's avatar
d.arizona committed
279 280 281 282
    }
  }

  downloadDataTables = async () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
283
    let res = await fetch("https://tia.eksad.com/tia-reporting-dev/public/user/export_user")
d.arizona's avatar
d.arizona committed
284 285 286
    res = await res.blob()
    console.log(res)
    if (res.size > 0) {
Deni Rinaldi's avatar
Deni Rinaldi committed
287 288 289
      let url = window.URL.createObjectURL(res);
      let a = document.createElement('a');
      a.href = url;
a.bairuha's avatar
a.bairuha committed
290
      a.download = 'User.xlsx';
Deni Rinaldi's avatar
Deni Rinaldi committed
291
      a.click();
d.arizona's avatar
d.arizona committed
292 293 294
    }
  }

d.arizona's avatar
d.arizona committed
295 296 297 298 299
  _handleKeyDown(e) {
    if (e.key === 'Enter') {
      if (this.state.search.length > 0) {
        this.searchUser()
      } else {
d.arizona's avatar
d.arizona committed
300
        this.getUser()
d.arizona's avatar
d.arizona committed
301 302 303 304
      }
    }
  }

Deni Rinaldi's avatar
Deni Rinaldi committed
305 306
  uploadUser() {
    api.create().uploadUser(this.state.payload).then(response => {
307
      if (response.data) {
a.bairuha's avatar
a.bairuha committed
308 309 310 311 312 313 314 315 316 317 318
        if (response.ok) {
            if (response.data.status === "success") {
                console.log(response)
                alert(response.data.message)
                this.getUser()
                this.setState({ visibleUser: true })
              } else {
                  this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }) 
              }
        } else {
            this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' }) 
319
        }
a.bairuha's avatar
a.bairuha committed
320 321
      } else {
        this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' }) 
322
      }
Deni Rinaldi's avatar
Deni Rinaldi committed
323 324 325
    })
  }

a.bairuha's avatar
a.bairuha committed
326 327 328 329
  closeAlert() {
    this.setState({ alert: false })
  }

d.arizona's avatar
d.arizona committed
330 331 332 333 334 335 336
  render() {
    const columns = [{
      name: "Action",
      options: {
        customBodyRender: (val, tableMeta) => {
          return (
            <div style={{ display: 'flex' }}>
d.arizona's avatar
d.arizona committed
337
              {/* {tableMeta.rowData[6] === "Active" ? */}
d.arizona's avatar
d.arizona committed
338
                <button
339 340 341 342 343 344 345 346 347 348
                  style={{
                    backgroundColor: 'transparent',
                    cursor: 'pointer',
                    borderColor: 'transparent',
                  }}
                  // onClick={() => console.log(tableMeta.rowData[1])}
                  onClick={() => this.setState({ edit: true, indexData: tableMeta.rowData[1] })}
                >
                  <img src={Images.editCopy} />
                </button>
Deni Rinaldi's avatar
Deni Rinaldi committed
349
                {/* :
d.arizona's avatar
d.arizona committed
350
                null
Deni Rinaldi's avatar
Deni Rinaldi committed
351
              } */}
d.arizona's avatar
d.arizona committed
352 353 354 355 356 357 358 359 360
            </div >
          );
        }
      }
    }, {
      name: "ID",
      options: {
        customBodyRender: (val, tableMeta) => {
          return (
361
            <div style={{ display: 'flex' }}>
d.arizona's avatar
d.arizona committed
362
              <span style={{ color: tableMeta.rowData[6] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{titleCase(val)}</span>
d.arizona's avatar
d.arizona committed
363 364 365 366 367
            </div >
          );
        }
      }
    }, {
d.arizona's avatar
d.arizona committed
368
      name: "Full Name",
d.arizona's avatar
d.arizona committed
369 370 371
      options: {
        customBodyRender: (val, tableMeta) => {
          return (
372
            <div style={{ display: 'flex' }}>
d.arizona's avatar
d.arizona committed
373
              <span style={{ color: tableMeta.rowData[6] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{titleCase(val)}</span>
d.arizona's avatar
d.arizona committed
374 375 376 377 378 379 380 381 382
            </div >
          );
        }
      }
    }, {
      name: "Email",
      options: {
        customBodyRender: (val, tableMeta) => {
          return (
383
            <div style={{ display: 'flex' }}>
d.arizona's avatar
d.arizona committed
384
              <span style={{ color: tableMeta.rowData[6] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{titleCase(val)}</span>
d.arizona's avatar
d.arizona committed
385 386 387 388 389 390 391 392 393
            </div >
          );
        }
      }
    }, {
      name: "Role",
      options: {
        customBodyRender: (val, tableMeta) => {
          return (
394
            <div style={{ display: 'flex' }}>
d.arizona's avatar
d.arizona committed
395
              <span style={{ color: tableMeta.rowData[6] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{titleCase(val)}</span>
d.arizona's avatar
d.arizona committed
396 397 398 399 400
            </div >
          );
        }
      }
    }, {
d.arizona's avatar
d.arizona committed
401
      name: "Company",
d.arizona's avatar
d.arizona committed
402 403 404
      options: {
        customBodyRender: (val, tableMeta) => {
          return (
Deni Rinaldi's avatar
Deni Rinaldi committed
405
            <div style={{ display: 'flex' }}>
d.arizona's avatar
d.arizona committed
406
              <span style={{ color: tableMeta.rowData[6] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{titleCase(val)}</span>
d.arizona's avatar
d.arizona committed
407 408 409 410 411 412 413 414 415 416
            </div >
          );
        }
      }
    }, {
      name: "Status",
      options: {
        customBodyRender: (val, tableMeta) => {
          return (
            <div style={{ display: 'flex' }}>
d.arizona's avatar
d.arizona committed
417
              <span style={{ color: tableMeta.rowData[6] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{titleCase(val)}</span>
d.arizona's avatar
d.arizona committed
418 419 420 421
            </div >
          );
        }
      }
d.arizona's avatar
d.arizona committed
422
    }]
d.arizona's avatar
d.arizona committed
423 424 425
    return (
      <div style={{ height: this.props.height }}>
        {/* <Row> */}
d.arizona's avatar
d.arizona committed
426
        <div className={"main-color"} style={{ height: 195, width: '100%' }} />
a.bairuha's avatar
a.bairuha committed
427 428 429 430 431
        <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
432
        {this.state.visibleUser ? <div>
d.arizona's avatar
d.arizona committed
433
          <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -118 }}>
434 435
            <label style={{ color: 'white', fontSize: 16, alignSelf: 'center', width: '20%', }}>Master Data - User</label>
            {/* <div style={{ width: '60%', justifyContent: 'center', display: 'flex', borderWidth: 2, alignItems: 'center' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
436
              <div style={{ width: '50%', backgroundColor: 'white', padding: 10, borderRadius: 7.5 }}>
d.arizona's avatar
d.arizona committed
437 438
                <TextField
                  id="input-with-icon-textfield"
Deni Rinaldi's avatar
Deni Rinaldi committed
439
                  name="search"
d.arizona's avatar
d.arizona committed
440 441 442 443 444
                  value={this.state.search}
                  placeholder={'Search'}
                  onChange={(e) => {
                    this.setState({ search: e.target.value }, () => {
                      if (this.state.search.length > 0) {
d.arizona's avatar
d.arizona committed
445
                        this.searchUser()
d.arizona's avatar
d.arizona committed
446
                      } else {
d.arizona's avatar
d.arizona committed
447
                        this.getUser()
d.arizona's avatar
d.arizona committed
448 449 450 451
                      }
                    });
                  }}
                  onKeyDown={(e) => this._handleKeyDown(e)}
Deni Rinaldi's avatar
Deni Rinaldi committed
452
                  style={{ width: '100%', borderBottomWidth: 0, borderBottomColor: 'red' }}
d.arizona's avatar
d.arizona committed
453
                  InputProps={{
Deni Rinaldi's avatar
Deni Rinaldi committed
454
                    style: { fontFamily: 'nunito', borderBottomColor: 'white' },
d.arizona's avatar
d.arizona committed
455 456 457 458 459 460 461
                    startAdornment: (
                      <InputAdornment position="start">
                        <SearchIcon />
                      </InputAdornment>
                    ),
                  }}
                />
d.arizona's avatar
d.arizona committed
462
              </div>
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
            </div> */}
            <div style={{ color: 'white', width: '50%', height: 37, display: 'flex', backgroundColor: 'white', borderWidth: 2, alignItems: 'center', borderRadius: 6, paddingLeft: 5, paddingRight: 5, alignSelf: 'center' }}>
              <img src={Images.searchBlack} style={{ marginRight: 10 }} />
              <InputBase
                style={{ width: '100%' }}
                placeholder="Search"
                value={this.state.search}
                onChange={(e) => {
                  this.setState({ search: e.target.value }, () => {
                    if (this.state.search.length > 0) {
                      this.searchUser()
                    } else {
                      this.getUser()
                    }
                  });
                }}
                inputProps={{ 'aria-label': 'naked' }}
              />
d.arizona's avatar
d.arizona committed
481 482 483
            </div>
            {/* <label style={{ color: 'white', width: '60%', justifyContent: 'center', display: 'flex', backgroundColor: 'white', borderWidth: 2, alignItems: 'center' }}>Search</label> */}
            <div style={{ width: '20%', justifyContent: 'flex-end', display: 'flex' }}>
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
              <a data-tip={'Download Template'} data-for="template">
                <button
                  style={{
                    backgroundColor: 'transparent',
                    cursor: 'pointer',
                    borderColor: 'transparent',
                    margin: 5
                  }}
                  onClick={() => this.downloadFile()}
                >
                  <img src={Images.template} />
                </button>
              </a>
              <ReactTooltip border={true} id="template" place="bottom" type="light" effect="solid" />
              <a data-tip={'Upload'} data-for="upload">
                <button
                  style={{
                    backgroundColor: 'transparent',
                    cursor: 'pointer',
                    borderColor: 'transparent',
                    margin: 5
                  }}
                  onClick={() => this.setState({ visibleUpload: true })}
                >
                  <img src={Images.upload} />
                </button>
              </a>
              <ReactTooltip border={true} id="upload" place="bottom" type="light" effect="solid" />
              <a data-tip={'Download'} data-for="download">
                <button
                  style={{
                    backgroundColor: 'transparent',
                    cursor: 'pointer',
                    borderColor: 'transparent',
                    margin: 5
                  }}
                  onClick={() => this.downloadDataTables()}
                >
                  <img src={Images.download} />
                </button>
              </a>
              <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
d.arizona's avatar
d.arizona committed
526
              <a data-tip={'Create'} data-for="create">
527 528 529 530 531 532 533 534 535 536 537 538 539
                <button
                  style={{
                    backgroundColor: 'transparent',
                    cursor: 'pointer',
                    borderColor: 'transparent',
                    margin: 5
                  }}
                  onClick={() => this.setState({ add: true })}
                >
                  <img src={Images.add} />
                </button>
              </a>
              <ReactTooltip border={true} id="create" place="bottom" type="light" effect="solid" />
d.arizona's avatar
d.arizona committed
540 541 542 543 544
            </div>
          </div>
          <div style={{ padding: 25 }}>
            <MuiThemeProvider theme={getMuiTheme()}>
              <MUIDataTable
d.arizona's avatar
d.arizona committed
545
                data={this.state.listUser}
d.arizona's avatar
d.arizona committed
546 547 548 549 550
                columns={columns}
                options={options}
              />
            </MuiThemeProvider>
          </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
        </div> :
          <div>
            <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -150 }}>
              <label style={{ color: 'white', fontSize: 16, alignSelf: 'center' }}>Preview Data</label>
            </div>
            <div style={{ padding: 25 }}>
              {this.state.dataLoaded && (
                <MuiThemeProvider theme={getMuiTheme()}>
                  <MUIDataTable
                    theme={getMuiTheme()}
                    data={this.state.rows}
                    columns={this.state.cols}
                    options={options}
                  />
                </MuiThemeProvider>
              )}
            </div>
            <div style={{ display: 'flex', width: '100%', placeContent: 'flex-end', padding: 20 }}>
              <button
                type="button"
                onClick={() => this.setState({ visibleUser: true })}
                style={{ marginRight: 20 }}
              >
                <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
575
                  <span style={{ color: '#354960', fontSize: 11 }}>Batal</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
576 577 578 579
                </div>
              </button>
              <button
                type="button"
d.arizona's avatar
d.arizona committed
580
                onClick={() => this.state.buttonError ? this.setState({ popupError: true }) : this.uploadUser()}
Deni Rinaldi's avatar
Deni Rinaldi committed
581 582 583 584 585 586 587
                style={{}}
              >
                <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>
            </div>
d.arizona's avatar
d.arizona committed
588 589
          </div>
        }
d.arizona's avatar
d.arizona committed
590
        {this.state.add && (
Deni Rinaldi's avatar
Deni Rinaldi committed
591
          <AddUser
d.arizona's avatar
d.arizona committed
592
            onClickClose={this.closeAdd.bind(this)}
d.arizona's avatar
d.arizona committed
593
            refresh={this.getUser.bind(this)}
d.arizona's avatar
d.arizona committed
594 595 596 597
            data={this.state.indexData}
          />
        )}
        {this.state.edit && (
Deni Rinaldi's avatar
Deni Rinaldi committed
598
          <EditUser
d.arizona's avatar
d.arizona committed
599
            onClickClose={this.closeEdit.bind(this)}
d.arizona's avatar
d.arizona committed
600
            refresh={this.getUser.bind(this)}
d.arizona's avatar
d.arizona committed
601 602 603
            data={this.state.indexData}
          />
        )}
Deni Rinaldi's avatar
Deni Rinaldi committed
604 605 606
        {this.state.popupError && (
          <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
        )}
d.arizona's avatar
d.arizona committed
607
        {this.state.visibleUpload && (
Deni Rinaldi's avatar
Deni Rinaldi committed
608 609
          <div className="test app-popup-show">
            <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
610
              <div className="popup-panel grid grid-2x main-color" style={{height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
611 612 613 614
                <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                  <div className="popup-title">
                    <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Upload File</span>
                  </div>
d.arizona's avatar
d.arizona committed
615
                </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
616 617 618 619 620 621
                <div className="col-2 content-right" style={{ maxWidth: "inherit", alignSelf: 'center' }}>
                  <button
                    type="button"
                    className="btn btn-circle btn-white"
                    onClick={() => this.setState({ visibleUpload: false })}
                  >
622
                    <img src={Images.close} />
Deni Rinaldi's avatar
Deni Rinaldi committed
623 624 625 626 627 628 629
                  </button>
                </div>
              </div>
              <UploadFile
                type={this.state.uploadStatus}
                percentage={this.state.percentage}
                result={this.state.result}
630
                acceptedFiles={["xlsx"]}
Deni Rinaldi's avatar
Deni Rinaldi committed
631 632 633 634 635 636
                onHandle={(dt) => {
                  this.fileHandler(dt)
                  this.setState({ uploadStatus: 'idle', percentage: '0' })
                }}
                onUpload={() => this.setState({ visibleUpload: false, visibleUser: false })}
              />
d.arizona's avatar
d.arizona committed
637
            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
638
          </div>
d.arizona's avatar
d.arizona committed
639
        )}
d.arizona's avatar
d.arizona committed
640 641 642 643
      </div>
    );
  }
}