import React, { Component } from 'react'; import { Typography, MuiThemeProvider, createMuiTheme, Paper } from '@material-ui/core'; import MUIDataTable from "mui-datatables"; import Images from '../assets/Images'; import DonutChart from 'react-d3-donut'; import Constant from '../library/Constant'; import api from '../api'; import { Link } from 'react-router-dom'; import { PropagateLoader } from 'react-spinners'; import { titleCase } from '../library/Utils'; var ct = require("../library/CustomTable"); const getMuiTheme = () => createMuiTheme(ct.customTable()); class HomePage extends Component { constructor(props) { super(props) this.state = { userData: null, listDashboard: [], listMasterBudget: [ { nama: 'Triputra Agro Persada', status: 'complete' }, { nama: 'Puninar Infinite Raya', status: 'complete' }, { nama: 'Dharma Group', status: 'overdue' }, { nama: 'Daya Group', status: 'open' }, ], isApprover: true, listSubcoMB: [], valueSubmit: 0, listdmb: [], dataTableMB: [], loading: false } } componentDidMount() { this.setState({ loading: true }) let userId = localStorage.getItem(Constant.USER) api.create().getDetailUser(userId).then((response) => { if (response.data) { if (response.data.status === 'success') { this.setState({ userData: response.data.data }, () => { // console.log(this.state.userData) }) } } }) // api.create().checkApprover().then(response => { // console.log(response); // if (response.data.data.is_approver === true) { // this.setState({ isApprover: true }, () => // this.getDashboard()) // } else { // this.setState({ isApprover: false }) // } // }) this.getApprMat() this.getListUserSubco() this.getDashboardMB() this.getDashboard() } componentDidUpdate() { window.onpopstate = e => { //your code... this.props.selectIndex('Home') } } getListUserSubco() { api.create().getDashboardUser().then(response => { // console.log(response); let valueSubmit = 0 if (response.data) { if (response.data.status === "success") { response.data.data.map((item, index) => { if (item.is_submit === true) { valueSubmit += 1 } }) this.setState({ listSubcoMB: response.data.data, valueSubmit, loading: false }) } } }) } getDashboard() { let listDashboard = [] let rawData = [] api.create().getDashboard().then((response) => { // console.log(response); if (String(response.data.status).toLocaleLowerCase() == 'success') { let data = response.data.data data.map((item, index) => { let statusConvert = item.status == 'approval_review'? 'Waiting For Review' : item.status == 'approval_proccess'? 'Waiting For Approval' : titleCase(item.status) listDashboard.push([index + 1, item.approval_id, item.company_name, `${item.type_report} - ${item.periode}`, item.revision, item.status, statusConvert]) rawData.push(item) }) this.setState({ listDashboard, rawData }) } }) } getApprMat() { this.setState({loading: true}) api.create().getAM().then((response) => { console.log(response); let actAMActive = [] let actAM = response.data.data.map((item, index) => { if (String(item.status).toLocaleLowerCase() == 'active') { actAMActive.push(item) return item } }) let userId = localStorage.getItem(Constant.USER) let indexId = actAMActive.findIndex((val) => val.user_id == userId) if (indexId === -1) { this.setState({ isApprover: false }) this.getListUserSubco() } this.getDashboardMB() // console.log(actAM) this.setState({loading: false}) }) } getDashboardMB() { api.create().getDashboardMB().then((response) => { // console.log(response) if (String(response.data.status).toLocaleLowerCase() == 'success') { let data = response.data.data let listdmb = data.sort((a, b) => a.company_id - b.company_id).map((item, index) => { return [ item.company_name, item.master_budget, item.operating_indicator ] }) this.setState({ dataTableMB: listdmb, loading: false }) } }) } render() { const columns = ["#", "ID", "Company", "Report Type", "Revision", { name: "", options: { display: false } }, 'Status', { name: "Action", options: { customBodyRender: (val, tableMeta) => { // console.log(tableMeta); return (