Parameter.js 57.5 KB
Newer Older
faisalhamdi's avatar
faisalhamdi committed
1 2 3 4
import React, { Component } from 'react';
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
import Images from '../../../assets/Images';
import MUIDataTable from "mui-datatables";
Deni Rinaldi's avatar
Deni Rinaldi committed
5
import { InputBase, Snackbar, withStyles, Typography, Tooltip } from "@material-ui/core";
6
import MuiAlert from '@material-ui/lab/Alert';
faisalhamdi's avatar
faisalhamdi committed
7
import CreateParameter from '../Parameter/CreateParameter';
8 9 10 11 12
import api from '../../../api';
import PopUpFailedSave from "../../../library/PopUpFailedSave";
import ReactTooltip from 'react-tooltip';
import UploadFile from "../../../library/Upload";
import { ExcelRenderer } from 'react-excel-renderer';
a.bairuha's avatar
a.bairuha committed
13
import Constant from '../../../library/Constant';
Deni Rinaldi's avatar
Deni Rinaldi committed
14
import PopUpDelete from '../../../library/PopUpDelete';
d.arizona's avatar
d.arizona committed
15 16
import { css } from "@emotion/core";
import PropagateLoader from "react-spinners/PropagateLoader"
faisalhamdi's avatar
faisalhamdi committed
17

Deni Rinaldi's avatar
Deni Rinaldi committed
18 19 20 21 22 23 24 25 26
const LightTooltip = withStyles((theme) => ({
    tooltip: {
        backgroundColor: theme.palette.common.white,
        color: 'rgba(0, 0, 0, 0.87)',
        boxShadow: theme.shadows[1],
        fontSize: 11,
    },
}))(Tooltip);

faisalhamdi's avatar
faisalhamdi committed
27 28 29
var ct = require("../../../library/CustomTable");
const getMuiTheme = () => createMuiTheme(ct.customTable());
const options = ct.customOptions();
30
const options2 = ct.customOptions2();
faisalhamdi's avatar
faisalhamdi committed
31

32 33 34
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);

faisalhamdi's avatar
faisalhamdi committed
35 36 37 38 39 40
export default class Parameter extends Component {
    constructor(props) {
        super(props)
        this.state = {
            visibleCreate: false,
            visibleEdit: false,
41 42 43
            visibleParameter: true,
            popupError: false,
            data: [],
44 45 46
            dataTable: [],
            alert: false,
            tipeAlert: '',
Deni Rinaldi's avatar
Deni Rinaldi committed
47 48 49
            messageAlert: '',
            create: false,
            edit: false,
d.arizona's avatar
d.arizona committed
50
            delete: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
51
            load: false,
d.arizona's avatar
d.arizona committed
52
            judul: '',
53 54
            loading: false,
            sizeUpload: "1"
faisalhamdi's avatar
faisalhamdi committed
55
        }
56
        this.fileHandler = this.fileHandler.bind(this);
faisalhamdi's avatar
faisalhamdi committed
57 58 59
    }

    componentDidMount() {
60
        this.getAllParameter()
Deni Rinaldi's avatar
Deni Rinaldi committed
61
        this.getPermission()
62 63 64 65 66 67 68 69 70 71
        this.getSizeUpload()
    }

    getSizeUpload(){
        let body = {
            group: 'MAX_FILE_SIZE',
            company_id: 0,
            type: 'MAX_FILE_SIZE'
        }
        api.create().getAllSettingByType(body).then(response => {
Deni Rinaldi's avatar
Deni Rinaldi committed
72
            // console.log(response.data.data[0]);
73 74 75
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
76
                        sizeUpload: response.data.data[0] ? response.data.data[0].value === undefined ? "1" : response.data.data[0].value : "1"
77 78 79 80
                    })
                }
            }
        })
Deni Rinaldi's avatar
Deni Rinaldi committed
81 82 83 84 85 86 87
    }

    getPermission() {
        let payload = {
            menu: "parameters"
        }
        api.create().getPermission(payload).then(response => {
Deni Rinaldi's avatar
Deni Rinaldi committed
88
            // console.log(response)
Deni Rinaldi's avatar
Deni Rinaldi committed
89 90 91 92 93
            if (response.data) {
                if (response.data.status === "success") {
                    this.setState({
                        create: response.data.data.create,
                        edit: response.data.data.edit,
d.arizona's avatar
d.arizona committed
94
                        delete: response.data.data.delete,
Deni Rinaldi's avatar
Deni Rinaldi committed
95 96 97 98 99 100 101
                        load: true
                    })
                } else {
                    this.setState({ load: true })
                }
            }
        })
102 103 104
    }

    getAllParameter() {
Deni Rinaldi's avatar
Deni Rinaldi committed
105
        this.setState({ loading: true })
106
        api.create().getAllParameter().then(response => {
107
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
108 109
                if (response.ok) {
                    if (response.data.status === "success") {
110
                        console.log(response);
a.bairuha's avatar
a.bairuha committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
                        let data = response.data.data
                        let listData = data.map((item, index) => {
                            return [
                                item.setting_id,
                                item.setting_id,
                                item.setting_group,
                                item.setting_type,
                                item.company_name,
                                item.description,
                                item.order,
                                item.value,
                                item.min_value,
                                item.max_value,
                                item.status
                            ]
                        })
d.arizona's avatar
d.arizona committed
127 128
                        this.setState({ dataTable: listData, data: response.data.data }, () => {
                            setTimeout(() => {
Deni Rinaldi's avatar
Deni Rinaldi committed
129
                                this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
130
                            }, 2000);
Deni Rinaldi's avatar
Deni Rinaldi committed
131
                        })
a.bairuha's avatar
a.bairuha committed
132
                    } else {
d.arizona's avatar
d.arizona committed
133
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
134
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
135 136 137 138 139 140 141
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
142
                } else {
d.arizona's avatar
d.arizona committed
143
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
144
                }
145
            } else {
d.arizona's avatar
d.arizona committed
146
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
147 148 149 150
            }
        })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
151
    openPopUp(rowData, type) {
152 153
        if (type === 'edit') {
            this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
154
                rowData: rowData,
155 156
                visibleEdit: true
            })
Deni Rinaldi's avatar
Deni Rinaldi committed
157 158 159 160 161
        } else if (type === 'delete') {
            this.setState({
                rowData: rowData,
                visibleDelete: true
            })
162 163
        } else {
            this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
164
                rowData: rowData,
165 166 167 168 169 170 171 172
                visibleCreate: true
            })
        }
    }

    updateParameter = (payload) => {
        this.setState({ visibleEdit: false })
        api.create().updateParameter(payload).then(response => {
Deni Rinaldi's avatar
Deni Rinaldi committed
173
            // console.log(response);
174
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
175 176 177 178 179 180
                if (response.ok) {
                    if (response.data.status == 'success') {
                        this.getAllParameter()
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
181
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
182 183 184 185 186 187 188
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
189
                } else {
a.bairuha's avatar
a.bairuha committed
190
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
191
                }
192
            } else {
193
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
194 195 196 197 198 199 200
            }
        })
    }

    createParameter = (payload) => {
        this.setState({ visibleCreate: false })
        api.create().createParameter(payload).then(response => {
Riri Novita's avatar
Riri Novita committed
201
            console.log(response);
202
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
203 204 205 206 207 208
                if (response.ok) {
                    if (response.data.status == 'success') {
                        this.getAllParameter()
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
209
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
210 211 212 213 214 215 216
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
217
                } else {
a.bairuha's avatar
a.bairuha committed
218
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
219
                }
220
            } else {
221
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
222 223 224 225 226 227
            }
        })
    }

    downloadFile = async () => {
        let res = await fetch(
d.arizona's avatar
d.arizona committed
228
            `${process.env.REACT_APP_URL_MAIN_BE}/public/attachment/download_file?fileName=ParameterTemplate&&fileType=xlsx`
229 230
        )
        res = await res.blob()
Deni Rinaldi's avatar
Deni Rinaldi committed
231
        // console.log(res)
232 233 234 235
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
Deni Rinaldi's avatar
Deni Rinaldi committed
236
            a.download = 'Template Parameter.xlsx';
237 238 239 240 241 242
            a.click();
        }
    }

    downloadDataTable = async () => {
        let res = await fetch(
d.arizona's avatar
d.arizona committed
243
            `${process.env.REACT_APP_URL_MAIN_BE}/public/setting/export_setting`
244 245
        )
        res = await res.blob()
Deni Rinaldi's avatar
Deni Rinaldi committed
246
        // console.log(res)
247 248 249 250
        if (res.size > 0) {
            let url = window.URL.createObjectURL(res);
            let a = document.createElement('a');
            a.href = url;
Deni Rinaldi's avatar
Deni Rinaldi committed
251
            a.download = 'Parameter.xlsx';
252 253 254 255
            a.click();
        }
    }

256 257 258 259 260 261
    handleInputChange(e) {
        this.setState({ search: e })
        let body = {
            "keyword": e
        }
        api.create().searchParameter(body).then(response => {
Deni Rinaldi's avatar
Deni Rinaldi committed
262
            // console.log(response.data);
a.bairuha's avatar
a.bairuha committed
263
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let listData = data.map((item, index) => {
                            return [
                                item.setting_id,
                                item.setting_id,
                                item.setting_group,
                                item.setting_type,
                                item.company_name,
                                item.description,
                                item.order,
                                item.value,
                                item.min_value,
                                item.max_value,
                                item.status
                            ]
                        })
                        this.setState({ dataTable: listData, listData: response.data.data })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
285
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
286 287 288 289 290 291 292
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
a.bairuha's avatar
a.bairuha committed
293
                } else {
a.bairuha's avatar
a.bairuha committed
294
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
295
                }
296
            } else {
a.bairuha's avatar
a.bairuha committed
297
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
298 299 300 301
            }
        })
    }

302 303 304 305 306
    fileHandler = (event) => {
        let fileObj = event
        ExcelRenderer(fileObj, (err, resp) => {
            // console.log(resp)
            if (err) {
Deni Rinaldi's avatar
Deni Rinaldi committed
307
                // console.log(err);
308 309
            }
            else {
Deni Rinaldi's avatar
Deni Rinaldi committed
310
                // let judul = resp.rows[2]
311
                let isi = resp.rows.slice(3)
312
                console.log(isi);
313 314 315 316 317
                let payload = []
                isi.map((item, index) => {
                    if (item.length > 0) {
                        payload.push({
                            id: index + 1,
Deni Rinaldi's avatar
Deni Rinaldi committed
318
                            group: item[0] === undefined ? "" : item[0],
Deni Rinaldi's avatar
Deni Rinaldi committed
319 320
                            parameter: item[1] === undefined ? "" : item[1],
                            company: item[2] === undefined ? "" : item[2],
321
                            reference: item[3] === undefined ? "" : item[3],
322 323 324 325 326 327 328
                            description: item[4] === undefined ? "" : item[4],
                            orders: item[5] === undefined ? "" : item[5],
                            value: item[6] === undefined ? "" : item[6],
                            min_value: item[7] === undefined ? "" : item[7],
                            max_value: item[8] === undefined ? "" : item[8],
                            start_date: item[9] === undefined ? "" : item[9],
                            end_date: item[10] === undefined ? "" : item[10],
329 330 331 332
                        })
                    }
                })
                let body = {
Deni Rinaldi's avatar
Deni Rinaldi committed
333
                    setting: payload
334
                }
Deni Rinaldi's avatar
Deni Rinaldi committed
335
                // console.log(resp.rows[1]);
Deni Rinaldi's avatar
Deni Rinaldi committed
336
                this.setState({ payload: body, buttonError: false, judul: resp.rows[1] === undefined ? "" : resp.rows[1][0] })
Deni Rinaldi's avatar
Deni Rinaldi committed
337 338 339 340
            }
        });
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
341
    checkUpload() {
Deni Rinaldi's avatar
Deni Rinaldi committed
342
        api.create().checkUploadParameter(this.state.payload).then(response => {
343
            console.log(response);
Deni Rinaldi's avatar
Deni Rinaldi committed
344 345 346 347 348 349 350 351 352
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
                        let dataRow = response.data.data.map((item, index) => {
                            return [
                                index + 1,
                                item.group,
                                item.parameter,
                                item.company,
353
                                item.reference,
Deni Rinaldi's avatar
Deni Rinaldi committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
                                item.description,
                                item.orders,
                                item.value,
                                item.min_value,
                                item.max_value,
                                item.start_date,
                                item.end_date,
                                item.error,
                            ]
                        })
                        let columns = [
                            "Data",
                            {
                                name: "Group",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
370
                                        console.log(tableMeta);
Deni Rinaldi's avatar
Deni Rinaldi committed
371
                                        let check = null
372 373
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('group'))
Deni Rinaldi's avatar
Deni Rinaldi committed
374 375
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
376
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
377
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
378 379
                                        return (
                                            <div style={{ display: 'flex' }}>
380 381
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
382
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
383
                                                    </LightTooltip> :
Deni Rinaldi's avatar
Deni Rinaldi committed
384
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
385
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
386 387 388 389 390 391 392 393 394 395
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Parameter",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
396 397
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('parameter'))
Deni Rinaldi's avatar
Deni Rinaldi committed
398 399
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
400
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
401
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
402 403
                                        return (
                                            <div style={{ display: 'flex' }}>
404 405
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
406
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
407
                                                    </LightTooltip> :
Deni Rinaldi's avatar
Deni Rinaldi committed
408
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
409
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
410 411 412 413 414 415 416 417 418 419
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Company",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
420 421
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('company'))
Deni Rinaldi's avatar
Deni Rinaldi committed
422 423
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
424
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
425
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
426 427
                                        return (
                                            <div style={{ display: 'flex' }}>
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                }
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Type Report",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('type_report'))
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
                                            }
                                        }
                                        return (
                                            <div style={{ display: 'flex' }}>
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
454
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
455
                                                    </LightTooltip> :
Deni Rinaldi's avatar
Deni Rinaldi committed
456
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
457
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
458 459 460 461 462 463 464 465 466 467
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Description",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
468 469
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('description'))
Deni Rinaldi's avatar
Deni Rinaldi committed
470 471
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
472
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
473
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
474 475
                                        return (
                                            <div style={{ display: 'flex' }}>
476 477
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
478 479
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
Deni Rinaldi's avatar
Deni Rinaldi committed
480
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
481
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
482 483 484 485 486 487 488 489 490 491
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Order",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
492 493
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('order'))
Deni Rinaldi's avatar
Deni Rinaldi committed
494 495
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
496
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
497
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
498 499
                                        return (
                                            <div style={{ display: 'flex' }}>
500 501
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
502 503
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
Deni Rinaldi's avatar
Deni Rinaldi committed
504
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
505
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
506 507 508 509 510 511 512 513 514 515
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Value",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
516 517
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('value'))
Deni Rinaldi's avatar
Deni Rinaldi committed
518 519
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
520
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
521
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
522 523
                                        return (
                                            <div style={{ display: 'flex' }}>
524 525
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
526 527
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
Deni Rinaldi's avatar
Deni Rinaldi committed
528
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
529
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
530 531 532 533 534 535 536 537 538 539
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Min Value",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
540 541
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('min_value'))
Deni Rinaldi's avatar
Deni Rinaldi committed
542 543
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
544
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
545
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
546 547
                                        return (
                                            <div style={{ display: 'flex' }}>
548 549
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
550 551
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
Deni Rinaldi's avatar
Deni Rinaldi committed
552
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
553
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
554 555 556 557 558 559 560 561 562 563
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Max Value",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
564 565
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('max_value'))
Deni Rinaldi's avatar
Deni Rinaldi committed
566 567
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
568
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
569
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
570 571
                                        return (
                                            <div style={{ display: 'flex' }}>
572 573
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
574 575 576
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
                                                    </LightTooltip> :
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
577
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
578 579 580 581 582 583 584 585 586 587
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Valid To",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
588 589
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('start_date'))
Deni Rinaldi's avatar
Deni Rinaldi committed
590 591
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
592
                                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
593
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
594 595
                                        return (
                                            <div style={{ display: 'flex' }}>
596 597
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
598
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
599
                                                    </LightTooltip> :
Deni Rinaldi's avatar
Deni Rinaldi committed
600
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
601
                                                }
Deni Rinaldi's avatar
Deni Rinaldi committed
602 603 604 605 606 607 608 609 610 611
                                            </div >
                                        );
                                    }
                                }
                            },
                            {
                                name: "Valid From",
                                options: {
                                    customBodyRender: (val, tableMeta) => {
                                        let check = null
612 613
                                        if (tableMeta.rowData[12] != null) {
                                            check = tableMeta.rowData[12].findIndex((val) => val.field.includes('end_date'))
Deni Rinaldi's avatar
Deni Rinaldi committed
614 615
                                            if (check > -1) {
                                                this.setState({ buttonError: true })
a.bairuha's avatar
a.bairuha committed
616 617
                                            }
                                        }
Deni Rinaldi's avatar
Deni Rinaldi committed
618 619
                                        return (
                                            <div style={{ display: 'flex' }}>
620 621
                                                {tableMeta.rowData[12] != null && check > -1 ?
                                                    <LightTooltip title={tableMeta.rowData[12][check].message} arrow>
Deni Rinaldi's avatar
Deni Rinaldi committed
622
                                                        <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
623
                                                    </LightTooltip> :
Deni Rinaldi's avatar
Deni Rinaldi committed
624
                                                    <span style={{ color: check != null && check > -1 ? "red" : 'black' }}>{val === "" ? "Empty" : val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
625 626 627
                                                }
                                            </div >
                                        );
a.bairuha's avatar
a.bairuha committed
628
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
629 630 631 632 633 634 635
                                }
                            },
                            {
                                name: "",
                                options: {
                                    display: false
                                }
a.bairuha's avatar
a.bairuha committed
636
                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
637 638
                        ]

Deni Rinaldi's avatar
Deni Rinaldi committed
639
                        // console.log(dataRow);
640 641
                        this.setState({
                            dataLoaded: true,
Deni Rinaldi's avatar
Deni Rinaldi committed
642 643
                            cols: columns,
                            rows: dataRow,
Deni Rinaldi's avatar
Deni Rinaldi committed
644
                            visibleUpload: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
645
                            visibleParameter: false
646
                        });
Deni Rinaldi's avatar
Deni Rinaldi committed
647 648
                    } else {
                        this.setState({ dataLoaded: true, cols: [], rows: [], alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
649
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Deni Rinaldi's avatar
Deni Rinaldi committed
650 651 652 653 654 655
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
656
                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
                } else {
                    this.setState({
                        alert: true, messageAlert: response.data.message, tipeAlert: 'error',
                        dataLoaded: true,
                        cols: [],
                        rows: []
                    });
                }
            } else {
                this.setState({
                    alert: true, messageAlert: response.problem, tipeAlert: 'error',
                    dataLoaded: true,
                    cols: [],
                    rows: []
                });
672
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
673 674

        })
faisalhamdi's avatar
faisalhamdi committed
675 676
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
677
    uploadParameter() {
678
        console.log(this.state.payload);
Deni Rinaldi's avatar
Deni Rinaldi committed
679
        api.create().uploadParameter(this.state.payload).then(response => {
680
            console.log(response)
681
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
682 683 684 685 686 687
                if (response.ok) {
                    if (response.data.status === "success") {
                        this.getAllParameter()
                        this.setState({ visibleParameter: true, alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
688
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
689 690 691 692 693 694 695
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
696
                } else {
a.bairuha's avatar
a.bairuha committed
697
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
698
                }
699 700
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
701
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
702 703 704
        })
    }

705 706 707 708
    closeAlert() {
        this.setState({ alert: false })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
709 710 711 712 713 714 715 716 717 718
    deleteParameter(payload) {
        let id = String(payload[1])
        api.create().deleteParameter(id).then(response => {
            if (response.data) {
                if (response.ok) {
                    if (response.data.status === "success") {
                        this.getAllParameter()
                        this.setState({ visibleDelete: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success' })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
719
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Deni Rinaldi's avatar
Deni Rinaldi committed
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
                } else {
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
                }
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
            }
        })
    }

faisalhamdi's avatar
faisalhamdi committed
736 737 738 739
    render() {
        const columns = [{
            name: "Action",
            options: {
Deni Rinaldi's avatar
Deni Rinaldi committed
740
                sort: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
741
                filter: false,
faisalhamdi's avatar
faisalhamdi committed
742 743
                customBodyRender: (val, tableMeta) => {
                    return (
d.arizona's avatar
d.arizona committed
744
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
745
                            {this.state.edit &&
d.arizona's avatar
d.arizona committed
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
                                <span>
                                    <a data-tip={'Edit'} data-for="edit">
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                                marginRight: 15
                                            }}
                                            // onClick={() => console.log(tableMeta)}
                                            onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}
                                        >
                                            <img src={Images.editCopy} />
                                        </button>
                                    </a>
                                    <ReactTooltip border={true} id="edit" place="bottom" type="light" effect="solid" />
                                </span>
                            }
Deni Rinaldi's avatar
Deni Rinaldi committed
764
                            {this.state.delete &&
d.arizona's avatar
d.arizona committed
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
                                <span>
                                    <a data-tip={'Delete'} data-for="delete">
                                        <button
                                            style={{
                                                backgroundColor: 'transparent',
                                                cursor: 'pointer',
                                                borderColor: 'transparent',
                                            }}
                                            // onClick={() => console.log(tableMeta)}
                                            onClick={() => this.openPopUp(tableMeta.rowData, 'delete')}
                                        >
                                            <img src={Images.delete} />
                                        </button>
                                    </a>
                                    <ReactTooltip border={true} id="delete" place="bottom" type="light" effect="solid" />
                                </span>
                            }
                        </div >
Deni Rinaldi's avatar
Deni Rinaldi committed
783

faisalhamdi's avatar
faisalhamdi committed
784 785 786
                    );
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
787
        }, {
Deni Rinaldi's avatar
Deni Rinaldi committed
788 789 790 791 792
            name: "ID",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
793
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
794 795 796 797
                        </div >
                    );
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
798
        }, {
faisalhamdi's avatar
faisalhamdi committed
799 800 801 802 803
            name: "Group",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
804
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
805 806 807 808 809 810 811 812 813 814
                        </div >
                    );
                }
            }
        }, {
            name: "Parameter",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
815
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
816 817 818 819 820
                        </div >
                    );
                }
            }
        }, {
821
            name: "Company",
faisalhamdi's avatar
faisalhamdi committed
822 823 824 825
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
826
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
827 828 829 830 831
                        </div >
                    );
                }
            }
        }, {
832
            name: "Description",
faisalhamdi's avatar
faisalhamdi committed
833 834 835 836
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
837
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
838 839 840 841 842 843 844 845 846 847
                        </div >
                    );
                }
            }
        }, {
            name: "Order",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
848
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
849 850 851 852 853 854 855 856 857 858
                        </div >
                    );
                }
            }
        }, {
            name: "Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
859
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
860 861 862 863 864 865 866 867 868 869
                        </div >
                    );
                }
            }
        }, {
            name: "Min Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
870
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
871 872 873 874 875 876 877 878 879 880
                        </div >
                    );
                }
            }
        }, {
            name: "Max Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
881
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
882 883 884 885 886 887 888 889 890 891
                        </div >
                    );
                }
            }
        }, {
            name: "Status",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
892
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
893 894 895 896 897 898 899 900 901 902
                        </div >
                    );
                }
            }
        }]
        const data = [
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "Default", "Range Periode Lap", "1", "-", "1", "10", "Aktif"],
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "Puninar Group", "Range Periode Lap", "2", "-", "1", "15", "Aktif"],
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "TAP Group", "Range Periode Lap", "3", "-", "1", "15", "Aktif"],
            ["", "LAPORAN_BULANAN", "BALANCE_SHEET", "Daya Group", "Range Periode Lap", "4", "-", "1", "20", "Non Aktif"],
903
            ["", "-", "-", "-", "-", "-"]
faisalhamdi's avatar
faisalhamdi committed
904
        ]
d.arizona's avatar
d.arizona committed
905
        const loadingComponent = (
Deni Rinaldi's avatar
Deni Rinaldi committed
906 907 908 909 910 911 912
            <div style={{ position: 'absolute', zIndex: 110, top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', background: 'rgba(255,255,255,0.8)' }}>
                <PropagateLoader
                    // css={override}
                    size={20}
                    color={"#274B80"}
                    loading={this.state.loading}
                />
d.arizona's avatar
d.arizona committed
913
            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
914
        );
faisalhamdi's avatar
faisalhamdi committed
915 916 917
        return (
            <div style={{ height: this.props.height }}>
                {/* <Row> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
918
                <div className={"main-color"} style={{ height: 195, width: '100%' }} />
919 920 921 922 923
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
924 925
                {this.state.visibleParameter === true ?
                    <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
926
                        {this.state.load && (
Deni Rinaldi's avatar
Deni Rinaldi committed
927 928
                            <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingRight: 25, paddingLeft: 25, marginTop: -182 }}>
                                <label style={{ color: 'white', fontSize: 16, alignSelf: 'center', width: '40%', }}>Parameter</label>
Deni Rinaldi's avatar
Deni Rinaldi committed
929
                                {/* <div style={{ color: 'white', width: '50%', height: 37, display: 'flex', backgroundColor: 'white', borderWidth: 2, alignItems: 'center', borderRadius: 6, paddingLeft: 5, paddingRight: 5, alignSelf: 'center' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
930 931 932 933 934 935 936 937
                                    <img src={Images.searchBlack} style={{ marginRight: 10 }} />
                                    <InputBase
                                        style={{ width: '100%' }}
                                        placeholder="Search"
                                        value={this.state.search}
                                        onChange={(e) => this.handleInputChange(e.target.value)}
                                        inputProps={{ 'aria-label': 'naked' }}
                                    />
Deni Rinaldi's avatar
Deni Rinaldi committed
938
                                </div> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
939
                                <div style={{ width: '40%', justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
                                    <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" />
                                    {this.state.create && (
                                        <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.downloadDataTable()}
                                        >
                                            <img src={Images.download} />
                                        </button>
                                    </a>
                                    <ReactTooltip border={true} id="download" place="bottom" type="light" effect="solid" />
                                    {this.state.create && (
                                        <a data-tip={'Add New'} data-for="create">
                                            <button
                                                style={{
                                                    backgroundColor: 'transparent',
                                                    cursor: 'pointer',
                                                    borderColor: 'transparent',
                                                    margin: 5,
                                                    marginRight: 20
                                                }}
                                                onClick={() => this.setState({ visibleCreate: true })}
                                            >
                                                <img src={Images.add} />
                                            </button>
                                        </a>
                                    )}

                                    <ReactTooltip multiline={false} border={true} id="create" place="bottom" type="light" effect="solid" />
                                </div>
1003
                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
1004 1005

                        )}
1006
                        <div style={{ padding: 25 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
1007
                            {this.state.loading && loadingComponent}
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
                            <MuiThemeProvider theme={getMuiTheme()}>
                                <MUIDataTable
                                    theme={getMuiTheme()}
                                    data={this.state.dataTable}
                                    columns={columns}
                                    options={options}
                                />
                            </MuiThemeProvider>

                        </div>
                    </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>
faisalhamdi's avatar
faisalhamdi committed
1023
                        </div>
1024
                        <div style={{ padding: 25 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
1025
                            {this.state.dataLoaded && (
1026 1027 1028 1029 1030 1031 1032 1033
                                <MuiThemeProvider theme={getMuiTheme()}>
                                    <MUIDataTable
                                        theme={getMuiTheme()}
                                        data={this.state.rows}
                                        columns={this.state.cols}
                                        options={options2}
                                    />
                                </MuiThemeProvider>
Deni Rinaldi's avatar
Deni Rinaldi committed
1034
                            )}
1035 1036
                        </div>
                        <div style={{ display: 'flex', width: '100%', placeContent: 'flex-end', padding: 20 }}>
faisalhamdi's avatar
faisalhamdi committed
1037
                            <button
1038
                                type="button"
Deni Rinaldi's avatar
Deni Rinaldi committed
1039
                                onClick={() => this.setState({ visibleParameter: true, judul: "" })}
1040
                                style={{ marginRight: 20 }}
faisalhamdi's avatar
faisalhamdi committed
1041
                            >
1042
                                <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
1043
                                    <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
1044 1045 1046 1047
                                </div>
                            </button>
                            <button
                                type="button"
Deni Rinaldi's avatar
Deni Rinaldi committed
1048 1049
                                disabled={this.state.buttonError ? true : false}
                                onClick={() => this.uploadParameter()}
1050 1051 1052
                                style={{}}
                            >
                                <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
1053
                                    <span style={{ color: '#fff', fontSize: 11 }}>Save</span>
1054
                                </div>
faisalhamdi's avatar
faisalhamdi committed
1055 1056 1057
                            </button>
                        </div>
                    </div>
1058
                }
faisalhamdi's avatar
faisalhamdi committed
1059
                {this.state.visibleCreate && (
1060
                    <CreateParameter
faisalhamdi's avatar
faisalhamdi committed
1061
                        onClickClose={() => this.setState({ visibleCreate: false })}
1062
                        createParameter={this.createParameter.bind(this)}
faisalhamdi's avatar
faisalhamdi committed
1063 1064 1065 1066
                    />
                )}

                {this.state.visibleEdit && (
1067
                    <CreateParameter
faisalhamdi's avatar
faisalhamdi committed
1068 1069
                        type={"edit"}
                        onClickClose={() => this.setState({ visibleEdit: false })}
Deni Rinaldi's avatar
Deni Rinaldi committed
1070
                        data={this.state.rowData}
1071
                        updateParameter={this.updateParameter.bind(this)}
faisalhamdi's avatar
faisalhamdi committed
1072 1073
                    />
                )}
1074
                {this.state.popupError && (
Deni Rinaldi's avatar
Deni Rinaldi committed
1075
                    <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
1076 1077 1078 1079
                )}
                {this.state.visibleUpload && (
                    <div className="test app-popup-show">
                        <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
1080
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
                                <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>
                                </div>
                                <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 })}
                                    >
1092
                                        <img src={Images.close} />
1093 1094 1095 1096 1097 1098 1099
                                    </button>
                                </div>
                            </div>
                            <UploadFile
                                type={this.state.uploadStatus}
                                percentage={this.state.percentage}
                                result={this.state.result}
1100
                                sizeUpload={Number(this.state.sizeUpload)}
1101
                                acceptedFiles={["xlsx"]}
1102 1103 1104 1105
                                onHandle={(dt) => {
                                    this.fileHandler(dt)
                                    this.setState({ uploadStatus: 'idle', percentage: '0' })
                                }}
Deni Rinaldi's avatar
Deni Rinaldi committed
1106
                                onUpload={() => {
r.kurnia's avatar
r.kurnia committed
1107
                                    String(this.state.judul).includes("MASTER") && String(this.state.judul).includes("DATA") && String(this.state.judul).includes("PARAMETER") ?
Deni Rinaldi's avatar
Deni Rinaldi committed
1108 1109 1110
                                        this.checkUpload() :
                                        this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' })
                                }}
1111 1112 1113 1114
                            />
                        </div>
                    </div>
                )}
Deni Rinaldi's avatar
Deni Rinaldi committed
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124

                {this.state.visibleDelete && (
                    <PopUpDelete
                        rowData={this.state.rowData}
                        intent={'parameter'}
                        onClickClose={() => this.setState({ visibleDelete: false })}
                        onClickDelete={this.deleteParameter.bind(this)}
                    />
                )}

faisalhamdi's avatar
faisalhamdi committed
1125 1126 1127 1128
            </div>
        );
    }
}