import React, { Component } from 'react'; import { Container, Row, Col } from "react-bootstrap"; import { makeStyles, createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles'; import { Typography } from '@material-ui/core'; import Images from '../../../assets/Images'; import UploadFile from "../../../library/Upload"; import MUIDataTable from "mui-datatables"; import { render } from '@testing-library/react'; import { TextField, InputBase } from "@material-ui/core"; import { ExcelRenderer } from 'react-excel-renderer'; import CreatePerusahaan from "../Perusahaan/CreatePerusahaan"; import api from "../../../api"; var ct = require("../../../library/CustomTable"); const getMuiTheme = () => createMuiTheme(ct.customTable()); const options = ct.customOptions(); const options2 = ct.customOptions2(); export default class Perusahaan extends Component { constructor(props) { super(props) this.state = { visibleCreate: false, visibleEdit: false, dataTable: [], listData: [], data: [], search: "", visiblePerusahaan: true, cols: null, rows: null, dataLoaded: false } this.fileHandler = this.fileHandler.bind(this); } fileHandler = (event) => { let fileObj = event ExcelRenderer(fileObj, (err, resp) => { if (err) { console.log(err); } else { let judul = resp.rows[0] let isi = resp.rows.slice(1) // let body = isi.map((item) => { // return { // item // ] // }) console.log(JSON.stringify(isi)); this.setState({ dataLoaded: true, cols: judul, rows: isi }); } }); } componentDidMount() { this.getData() } getData() { api.create().getPerusahaan().then((response) => { console.log(response) if (response.data.status == 'success') { let data = response.data.data let listData = data.map((item, index) => { return [index, item.company_id, item.company_name, item.parent, item.businessUnitId, item.total_report, item.status] }) this.setState({ dataTable: listData, listData: response.data.data }) } else { alert(response.data.message) } }) } openPopUp(index, type) { if (type === 'edit') { this.setState({ selectIndex: index, visibleEdit: true }) } else { this.setState({ data: this.state.listData[index], visibleCreate: true }) } } handleInputChange(e) { this.setState({ search: e }) let body = { "keyword": e } api.create().searchPerusahaan(body).then(response => { // console.log(response.data); if (response.data.status == 'success') { let data = response.data.data let listData = data.map((item, index) => { // return [index, item.business_unit_id, item.business_unit_name, item.status] }) this.setState({ dataTable: listData, listData: response.data.data }) } else { alert(response.data.message) } }) } updatePerusahaan = (payload) => { this.setState({ visibleEdit: false }) api.create().updatePerusahaan(payload).then(response => { if (response.data.status == 'success') { this.getData() } else { alert(response.data.message) } }) } createPerusahaan = (payload) => { this.setState({ visibleCreate: false }) api.create().createPerusahaan(payload).then(response => { if (response.data.status == 'success') { this.getData() } else { alert(response.data.message) } }) } render() { const columns = [{ name: "Action", options: { customBodyRender: (val, tableMeta) => { return (
); } } }, { name: "ID", options: { customBodyRender: (val, tableMeta) => { return (
{val}
); } } }, { name: "Nama Perusahaan", options: { customBodyRender: (val, tableMeta) => { return (
{val}
); } } }, { name: "Parent Company", options: { customBodyRender: (val, tableMeta) => { return (
{val}
); } } }, { name: "Unit Bisnis", options: { customBodyRender: (val, tableMeta) => { return (
{val}
); } } }, { name: "Jumlah Laporan", options: { customBodyRender: (val, tableMeta) => { return (
{val}
); } } }, { name: "Status", options: { customBodyRender: (val, tableMeta) => { return (
{val}
); } } }] const data = [ ["", "1", "Triputra Agro Persada Group", "Triputra Investindo Arya", "Agrobisnis", "5", "Aktif"], ["", "2", "Gawi Bahandep Sawit Mekar", "Triputra Agro Persada Group", "Agrobisnis", "2", "Aktif"], ["", "3", "Puninar Group", "Triputra Investindo Arya", "Service", "5", "Aktif"], ["", "4", "Puninar Infinite Raya", "Puninar Group", "Service", "5", "Non Aktif"], ["", "-", "-", "-", "-","-"], ] return (
{/* */}
{this.state.visiblePerusahaan === true ?
this.handleInputChange(e.target.value)} inputProps={{ 'aria-label': 'naked' }} />
:
{this.state.dataLoaded && ( )}
Simpan
} {this.state.visibleCreate && ( this.setState({ visibleCreate: false })} type={"create"} createPerusahaan={this.createPerusahaan.bind(this)} /> )} {this.state.visibleEdit && ( this.setState({ visibleEdit: false })} data={this.state.listData[this.state.selectIndex]} updatePerusahaan={this.updatePerusahaan.bind(this)} /> )} {this.state.visibleUpload && (
Upload File
{ this.fileHandler(dt) this.setState({ uploadStatus: 'idle', percentage: '0' }) }} onUpload={() => this.setState({ visibleUpload: false, visiblePerusahaan: false })} />
)}
); } }