HomePage.js 15.7 KB
Newer Older
Deni Rinaldi's avatar
Deni Rinaldi committed
1
import React, { Component } from 'react';
d.arizona's avatar
d.arizona committed
2
import { Typography, MuiThemeProvider, createMuiTheme } from '@material-ui/core';
Deni Rinaldi's avatar
Deni Rinaldi committed
3
import MUIDataTable from "mui-datatables";
Deni Rinaldi's avatar
Deni Rinaldi committed
4
import Images from '../assets/Images';
Deni Rinaldi's avatar
Deni Rinaldi committed
5
import DonutChart from 'react-d3-donut';
d.arizona's avatar
d.arizona committed
6 7
import Constant from '../library/Constant';
import api from '../api';
d.arizona's avatar
d.arizona committed
8
import { Link } from 'react-router-dom';
Deni Rinaldi's avatar
Deni Rinaldi committed
9

Deni Rinaldi's avatar
Deni Rinaldi committed
10 11 12
var ct = require("../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());

Deni Rinaldi's avatar
Deni Rinaldi committed
13
class HomePage extends Component {
d.arizona's avatar
d.arizona committed
14 15 16
    constructor(props) {
        super(props)
        this.state = {
d.arizona's avatar
d.arizona committed
17 18
            userData: null,
            listDashboard: []
d.arizona's avatar
d.arizona committed
19 20 21 22 23 24 25
        }
    }

    componentDidMount() {
        let userId = localStorage.getItem(Constant.USER)
        api.create().getDetailUser(userId).then((response) => {
            if (response.data) {
Deni Rinaldi's avatar
Deni Rinaldi committed
26
                if (response.data.status === 'success') {
Deni Rinaldi's avatar
Deni Rinaldi committed
27
                    this.setState({ userData: response.data.data }, () => {
d.arizona's avatar
d.arizona committed
28 29 30 31 32
                        console.log(this.state.userData)
                    })
                }
            }
        })
d.arizona's avatar
d.arizona committed
33 34 35
        this.getDashboard()
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
36
    componentDidUpdate() {
d.arizona's avatar
d.arizona committed
37
        window.onpopstate = e => {
Deni Rinaldi's avatar
Deni Rinaldi committed
38 39
            //your code...
            this.props.selectIndex('Home')
d.arizona's avatar
d.arizona committed
40 41 42
        }
    }

d.arizona's avatar
d.arizona committed
43 44 45
    getDashboard() {
        let listDashboard = []
        api.create().getDashboard().then((response) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
46
            console.log(response);
d.arizona's avatar
d.arizona committed
47 48
            if (String(response.data.status).toLocaleLowerCase() == 'success') {
                let data = response.data.data
Deni Rinaldi's avatar
Deni Rinaldi committed
49 50
                data.map((item, index) => {
                    listDashboard.push([index + 1, item.approval_id, item.company_name, `${item.type_report} - ${item.periode}`, item.revision, item.status])
d.arizona's avatar
d.arizona committed
51
                })
Deni Rinaldi's avatar
Deni Rinaldi committed
52
                this.setState({ listDashboard, rawData: response.data.data })
d.arizona's avatar
d.arizona committed
53 54
            }
        })
d.arizona's avatar
d.arizona committed
55 56
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
57
    render() {
d.arizona's avatar
d.arizona committed
58
        const columns = ["#", "ID", "Nama Perusahaan", "Jenis Report", "Revisi", "Status", {
Deni Rinaldi's avatar
Deni Rinaldi committed
59 60 61
            name: "Action",
            options: {
                customBodyRender: (val, tableMeta) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
62
                    // console.log(tableMeta);
Deni Rinaldi's avatar
Deni Rinaldi committed
63 64
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
65 66 67 68 69 70 71
                            <Link to={{
                                pathname: `/home/master-budget/`,
                                state: { 
                                    userType: 'approver',
                                    rawData: this.state.rawData[tableMeta.rowIndex]
                                }
                            }}>
d.arizona's avatar
d.arizona committed
72 73 74 75 76 77 78 79 80 81 82 83
                                <button
                                    style={{
                                        backgroundColor: 'transparent',
                                        cursor: 'pointer',
                                        borderColor: 'transparent',
                                        marginRight: 10
                                    }}
                                    onClick={() => null}
                                >
                                    <img src={Images.editCopy2} />
                                </button>
                            </Link>
Deni Rinaldi's avatar
Deni Rinaldi committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                        </div >
                    );
                }
            }
        }]
        const data = [
            ["1", "TRIPUTRA AGRO PERSADA", "Laporan Bulanan - September 2020", "1 (20 Oktober 2020)", "Belum Disetujui"],
            ["2", "DAYA GROUP", "Laporan Bulanan - September 2020", "1 (20 Oktober 2020)", "Belum Disetujui"],
            ["3", "PUNINAR INFINITE RAYA", "Budget Tahunan 2021", "0 (20 Oktober 2020)", "Belum Disetujui"],
            ["4", "DHARMA GROUP", "Laporan Bulanan - September 2020", "0 (20 Oktober 2020)", "Belum Disetujui"],
            ["5", "PUNINAR INFINITE RAYA", "Budget Tahunan 2021", "0 (20 Oktober 2020)", "Belum Disetujui"],
        ]
        const options = {
            filter: false,
            sort: false,
            responsive: "scroll",
            print: false,
            download: false,
            selectableRows: false,
            viewColumns: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
104 105
            rowsPerPage: 5,
            search: false
Deni Rinaldi's avatar
Deni Rinaldi committed
106
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
        const dataChart = [{
            count: 90,
            color: '#5198ea',
            name: 'My name',
        }, {
            count: 10,
            color: '#ffd600',
            name: 'name',
        }]
        const dataChart2 = [{
            count: 90,
            color: '#f65a4c',
            name: 'My name',
        }, {
            count: 10,
            color: '#5198ea',
            name: 'name',
        }]
        const dataChart3 = [{
            count: 90,
            color: '#4caf51',
            name: 'My name',
        }, {
            count: 10,
            color: '#f65a4c',
            name: 'name',
        }]
Deni Rinaldi's avatar
Deni Rinaldi committed
134
        return (
Deni Rinaldi's avatar
Deni Rinaldi committed
135
            <div style={{ flex: 1, backgroundColor: '#f8f8f8' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
136
                <div className={"main-color"} style={{ height: 78, flex: 1, display: 'flex', alignItems: 'center', paddingLeft: 20 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
137
                    <Typography style={{ fontSize: '24px', color: 'white' }}>{this.state.userData === null ? '' : `Welcome, ${this.state.userData.fullname} !`}</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
138 139 140
                </div>
                <div style={{ flex: 1, padding: 20, width: '100%' }}>
                    <div style={{ display: 'flex' }}>
d.arizona's avatar
d.arizona committed
141
                        <Typography style={{ color: '#656565', fontSize: '16px', fontWeight: 'bold' }}>Waiting Your Submission</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
142 143 144 145 146
                    </div>

                </div>
                <div style={{ flex: 1, padding: 20, width: '100%' }}>
                    <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
147 148
                        <MuiThemeProvider theme={getMuiTheme()}>
                            <MUIDataTable
Deni Rinaldi's avatar
Deni Rinaldi committed
149
                                data={this.state.listDashboard}
Deni Rinaldi's avatar
Deni Rinaldi committed
150 151 152 153
                                columns={columns}
                                options={options}
                            />
                        </MuiThemeProvider>
Deni Rinaldi's avatar
Deni Rinaldi committed
154 155 156
                    </div>
                    <div style={{ marginTop: 20 }}>
                        <Typography style={{ color: '#656565', fontSize: '16px', fontWeight: 'bold' }}>Status Laporan</Typography>
Deni Rinaldi's avatar
Deni Rinaldi committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
                        <div style={{ marginTop: 10, display: 'flex' }}>
                            <div style={{ width: 280, height: 400, padding: 20, backgroundColor: 'white', borderRadius: 6, border: 'solid 1px #c4c4c4', marginRight: 25 }}>
                                <Typography style={{ color: '#4b4b4b', fontSize: '24px', fontWeight: 'bold' }}>Budget Tahunan - 2021</Typography>
                                <div style={{ textAlign: 'center' }}>
                                    <DonutChart
                                        innerRadius={70}
                                        outerRadius={100}
                                        transition={true}
                                        pieClass="pie1"
                                        displayTooltip={true}
                                        strokeWidth={3}
                                        data={dataChart} />
                                </div>
                                <div style={{ display: 'flex', width: '100%', marginTop: 10 }}>
                                    <div style={{ width: '33%' }}>
                                        <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Submit</Typography>
                                        <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>92.8 %</Typography>
                                        <div style={{ display: 'flex' }} >
                                            <img src={Images.red} />
                                            <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>-0.6%</Typography>
                                        </div>
                                    </div>
                                    <div style={{ width: '33%' }}>
                                        <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>On Time</Typography>
                                        <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>6.1 %</Typography>
                                        <div style={{ display: 'flex' }} >
                                            <img src={Images.green} />
                                            <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.7%</Typography>
                                        </div>

                                    </div>
                                    <div style={{ width: '33%' }}>
                                        <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Overdue</Typography>
                                        <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>1.1 %</Typography>
                                        <div style={{ display: 'flex' }} >
                                            <img src={Images.green} />
                                            <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.1%</Typography>
                                        </div>
                                    </div>
                                </div>
                            </div>

Deni Rinaldi's avatar
Deni Rinaldi committed
199
                            <div style={{ width: 280, height: 400, padding: 20, backgroundColor: 'white', borderRadius: 6, border: 'solid 1px #c4c4c4', marginRight: 25 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
                                <Typography style={{ color: '#4b4b4b', fontSize: '24px', fontWeight: 'bold' }}>Laporan Bulanan - Oct 2020</Typography>
                                <div style={{ textAlign: 'center' }}>
                                    <DonutChart
                                        innerRadius={70}
                                        outerRadius={100}
                                        transition={true}
                                        pieClass="pie5"
                                        displayTooltip={true}
                                        strokeWidth={3}
                                        data={dataChart2}
                                    />
                                </div>
                                <div style={{ display: 'flex', width: '100%', marginTop: 10 }}>
                                    <div style={{ width: '33%' }}>
                                        <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Submit</Typography>
                                        <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>92.8 %</Typography>
                                        <div style={{ display: 'flex' }} >
                                            <img src={Images.red} />
                                            <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>-0.6%</Typography>
                                        </div>
                                    </div>
                                    <div style={{ width: '33%' }}>
                                        <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>On Time</Typography>
                                        <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>6.1 %</Typography>
                                        <div style={{ display: 'flex' }} >
                                            <img src={Images.green} />
                                            <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.7%</Typography>
                                        </div>

                                    </div>
                                    <div style={{ width: '33%' }}>
                                        <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Overdue</Typography>
                                        <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>1.1 %</Typography>
                                        <div style={{ display: 'flex' }} >
                                            <img src={Images.green} />
                                            <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.1%</Typography>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div style={{ width: 280, height: 400, padding: 20, backgroundColor: 'white', borderRadius: 6, border: 'solid 1px #c4c4c4', }}>
                                <Typography style={{ color: '#4b4b4b', fontSize: '24px', fontWeight: 'bold', height: 71 }}>Lainnya</Typography>
                                <div style={{ textAlign: 'center' }}>
                                    <DonutChart
                                        innerRadius={70}
                                        outerRadius={100}
                                        transition={true}
                                        pieClass="pie2"
                                        displayTooltip={true}
                                        strokeWidth={3}
                                        data={dataChart3}
                                    />
                                </div>
                                <div style={{ display: 'flex', width: '100%', marginTop: 10 }}>
                                    <div style={{ width: '33%' }}>
                                        <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Submit</Typography>
                                        <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>92.8 %</Typography>
                                        <div style={{ display: 'flex' }} >
                                            <img src={Images.red} />
                                            <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>-0.6%</Typography>
                                        </div>
                                    </div>
                                    <div style={{ width: '33%' }}>
                                        <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>On Time</Typography>
                                        <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>6.1 %</Typography>
                                        <div style={{ display: 'flex' }} >
                                            <img src={Images.green} />
                                            <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.7%</Typography>
                                        </div>

                                    </div>
                                    <div style={{ width: '33%' }}>
                                        <Typography style={{ color: '#656565', fontSize: '15px', textAlign: 'left' }}>Overdue</Typography>
                                        <Typography style={{ color: '#656565', fontSize: '20px', textAlign: 'left' }}>1.1 %</Typography>
                                        <div style={{ display: 'flex' }} >
                                            <img src={Images.green} />
                                            <Typography style={{ color: '#656565', fontSize: '14px', textAlign: 'left' }}>0.1%</Typography>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


Deni Rinaldi's avatar
Deni Rinaldi committed
284 285 286 287 288 289 290 291
                    </div>
                </div>

            </div>
        );
    }
}

Deni Rinaldi's avatar
Deni Rinaldi committed
292
export default HomePage;