Parameter.js 58 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
        this.getSizeUpload()
    }

Riri Novita's avatar
Riri Novita committed
65
    getSizeUpload() {
66 67 68 69 70 71
        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 => {
Riri Novita's avatar
Riri Novita committed
107
            console.log(response);
108
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
109 110
                if (response.ok) {
                    if (response.data.status === "success") {
111
                        console.log(response);
a.bairuha's avatar
a.bairuha committed
112 113 114 115 116 117 118 119 120 121
                        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,
Riri Novita's avatar
Riri Novita committed
122
                                item.setting_group === "CURRENCY" ? Number(item.value) * 1000 : item.value, // convert IDR mn to IDR
a.bairuha's avatar
a.bairuha committed
123 124 125 126 127
                                item.min_value,
                                item.max_value,
                                item.status
                            ]
                        })
d.arizona's avatar
d.arizona committed
128 129
                        this.setState({ dataTable: listData, data: response.data.data }, () => {
                            setTimeout(() => {
Deni Rinaldi's avatar
Deni Rinaldi committed
130
                                this.setState({ loading: false })
d.arizona's avatar
d.arizona committed
131
                            }, 2000);
Deni Rinaldi's avatar
Deni Rinaldi committed
132
                        })
a.bairuha's avatar
a.bairuha committed
133
                    } else {
d.arizona's avatar
d.arizona committed
134
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
d.arizona's avatar
d.arizona committed
135
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
136 137 138 139 140 141 142
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
143
                } else {
d.arizona's avatar
d.arizona committed
144
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
145
                }
146
            } else {
d.arizona's avatar
d.arizona committed
147
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
148 149 150 151
            }
        })
    }

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

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

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

    downloadFile = async () => {
        let res = await fetch(
d.arizona's avatar
d.arizona committed
229
            `${process.env.REACT_APP_URL_MAIN_BE}/public/attachment/download_file?fileName=ParameterTemplate&&fileType=xlsx`
230 231
        )
        res = await res.blob()
Deni Rinaldi's avatar
Deni Rinaldi committed
232
        // console.log(res)
233 234 235 236
        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
237
            a.download = 'Template Parameter.xlsx';
238 239 240 241 242 243
            a.click();
        }
    }

    downloadDataTable = async () => {
        let res = await fetch(
d.arizona's avatar
d.arizona committed
244
            `${process.env.REACT_APP_URL_MAIN_BE}/public/setting/export_setting`
245 246
        )
        res = await res.blob()
Deni Rinaldi's avatar
Deni Rinaldi committed
247
        // console.log(res)
248 249 250 251
        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
252
            a.download = 'Parameter.xlsx';
253 254 255 256
            a.click();
        }
    }

257 258 259 260 261 262
    handleInputChange(e) {
        this.setState({ search: e })
        let body = {
            "keyword": e
        }
        api.create().searchParameter(body).then(response => {
Deni Rinaldi's avatar
Deni Rinaldi committed
263
            // console.log(response.data);
a.bairuha's avatar
a.bairuha committed
264
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
                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
286
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
287 288 289 290 291 292 293
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
a.bairuha's avatar
a.bairuha committed
294
                } else {
a.bairuha's avatar
a.bairuha committed
295
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
296
                }
297
            } else {
a.bairuha's avatar
a.bairuha committed
298
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
299 300 301 302
            }
        })
    }

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

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

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

        })
faisalhamdi's avatar
faisalhamdi committed
677 678
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
679
    uploadParameter() {
Riri Novita's avatar
Riri Novita committed
680 681 682 683 684 685 686 687 688 689 690 691 692
        let payload = this.state.payload
        let arr = []
        for (let index = 0; index < payload.setting.length; index++) {
            let item = payload.setting[index]
            arr.push({
                ...item,
                value: item?.group === 'CURRENCY' ? Number(item?.value)/1000 : item?.value
            })
        }
        payload = {
            setting: arr
        }
        api.create().uploadParameter(payload).then(response => {
693
            console.log(response)
694
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
695 696 697 698 699 700
                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
701
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
702 703 704 705 706 707 708
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
709
                } else {
a.bairuha's avatar
a.bairuha committed
710
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
711
                }
712 713
            } else {
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
714
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
715 716 717
        })
    }

718 719 720 721
    closeAlert() {
        this.setState({ alert: false })
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
722 723 724 725 726 727 728 729 730 731
    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
732
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
Deni Rinaldi's avatar
Deni Rinaldi committed
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
                                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
749 750 751 752
    render() {
        const columns = [{
            name: "Action",
            options: {
Deni Rinaldi's avatar
Deni Rinaldi committed
753
                sort: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
754
                filter: false,
faisalhamdi's avatar
faisalhamdi committed
755 756
                customBodyRender: (val, tableMeta) => {
                    return (
d.arizona's avatar
d.arizona committed
757
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
758
                            {this.state.edit &&
d.arizona's avatar
d.arizona committed
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
                                <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
777
                            {this.state.delete &&
d.arizona's avatar
d.arizona committed
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
                                <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
796

faisalhamdi's avatar
faisalhamdi committed
797 798 799
                    );
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
800
        }, {
Deni Rinaldi's avatar
Deni Rinaldi committed
801 802 803 804 805
            name: "ID",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
806
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
Deni Rinaldi's avatar
Deni Rinaldi committed
807 808 809 810
                        </div >
                    );
                }
            }
Deni Rinaldi's avatar
Deni Rinaldi committed
811
        }, {
faisalhamdi's avatar
faisalhamdi committed
812 813 814 815 816
            name: "Group",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
817
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
818 819 820 821 822 823 824 825 826 827
                        </div >
                    );
                }
            }
        }, {
            name: "Parameter",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
828
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
829 830 831 832 833
                        </div >
                    );
                }
            }
        }, {
834
            name: "Company",
faisalhamdi's avatar
faisalhamdi committed
835 836 837 838
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
839
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
840 841 842 843 844
                        </div >
                    );
                }
            }
        }, {
845
            name: "Description",
faisalhamdi's avatar
faisalhamdi committed
846 847 848 849
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
850
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
851 852 853 854 855 856 857 858 859 860
                        </div >
                    );
                }
            }
        }, {
            name: "Order",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
861
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
862 863 864 865 866 867 868 869 870 871
                        </div >
                    );
                }
            }
        }, {
            name: "Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
872
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
873 874 875 876 877 878 879 880 881 882
                        </div >
                    );
                }
            }
        }, {
            name: "Min Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
883
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
884 885 886 887 888 889 890 891 892 893
                        </div >
                    );
                }
            }
        }, {
            name: "Max Value",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
894
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
895 896 897 898 899 900 901 902 903 904
                        </div >
                    );
                }
            }
        }, {
            name: "Status",
            options: {
                customBodyRender: (val, tableMeta) => {
                    return (
                        <div style={{ display: 'flex' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
905
                            <span style={{ color: tableMeta.rowData[10] === "Active" ? "#656565" : 'rgba(0, 0, 0, 0.25)' }}>{val}</span>
faisalhamdi's avatar
faisalhamdi committed
906 907 908 909 910 911 912 913 914 915
                        </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"],
916
            ["", "-", "-", "-", "-", "-"]
faisalhamdi's avatar
faisalhamdi committed
917
        ]
d.arizona's avatar
d.arizona committed
918
        const loadingComponent = (
Deni Rinaldi's avatar
Deni Rinaldi committed
919 920 921 922 923 924 925
            <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
926
            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
927
        );
faisalhamdi's avatar
faisalhamdi committed
928 929 930
        return (
            <div style={{ height: this.props.height }}>
                {/* <Row> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
931
                <div className={"main-color"} style={{ height: 195, width: '100%' }} />
932 933 934 935 936
                <Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
                    <Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
                        {this.state.messageAlert}
                    </Alert>
                </Snackbar>
937 938
                {this.state.visibleParameter === true ?
                    <div>
Deni Rinaldi's avatar
Deni Rinaldi committed
939
                        {this.state.load && (
Deni Rinaldi's avatar
Deni Rinaldi committed
940 941
                            <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
942
                                {/* <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
943 944 945 946 947 948 949 950
                                    <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
951
                                </div> */}
Deni Rinaldi's avatar
Deni Rinaldi committed
952
                                <div style={{ width: '40%', justifyContent: 'flex-end', display: 'flex', flexFlow: 'wrap' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
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 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
                                    <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>
1016
                            </div>
Deni Rinaldi's avatar
Deni Rinaldi committed
1017 1018

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

                {this.state.visibleEdit && (
1080
                    <CreateParameter
faisalhamdi's avatar
faisalhamdi committed
1081 1082
                        type={"edit"}
                        onClickClose={() => this.setState({ visibleEdit: false })}
Deni Rinaldi's avatar
Deni Rinaldi committed
1083
                        data={this.state.rowData}
1084
                        updateParameter={this.updateParameter.bind(this)}
faisalhamdi's avatar
faisalhamdi committed
1085 1086
                    />
                )}
1087
                {this.state.popupError && (
Deni Rinaldi's avatar
Deni Rinaldi committed
1088
                    <PopUpFailedSave onClickClose={() => this.setState({ popupError: false })} />
1089 1090 1091 1092
                )}
                {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
1093
                            <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
                                <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 })}
                                    >
1105
                                        <img src={Images.close} />
1106 1107 1108 1109 1110 1111 1112
                                    </button>
                                </div>
                            </div>
                            <UploadFile
                                type={this.state.uploadStatus}
                                percentage={this.state.percentage}
                                result={this.state.result}
1113
                                sizeUpload={Number(this.state.sizeUpload)}
1114
                                acceptedFiles={["xlsx"]}
1115 1116 1117 1118
                                onHandle={(dt) => {
                                    this.fileHandler(dt)
                                    this.setState({ uploadStatus: 'idle', percentage: '0' })
                                }}
Deni Rinaldi's avatar
Deni Rinaldi committed
1119
                                onUpload={() => {
r.kurnia's avatar
r.kurnia committed
1120
                                    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
1121 1122 1123
                                        this.checkUpload() :
                                        this.setState({ alert: true, messageAlert: "Invalid Template", tipeAlert: 'warning' })
                                }}
1124 1125 1126 1127
                            />
                        </div>
                    </div>
                )}
Deni Rinaldi's avatar
Deni Rinaldi committed
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137

                {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
1138 1139 1140 1141
            </div>
        );
    }
}