CreateParameter.js 65.5 KB
Newer Older
faisalhamdi's avatar
faisalhamdi committed
1 2
import React, { Component } from 'react';
import { TextField, Typography } from '@material-ui/core';
3 4 5 6 7
import Autocomplete from '@material-ui/lab/Autocomplete';
import api from '../../../api';
import { DatePicker } from '@material-ui/pickers';
import { format } from 'date-fns';
import * as R from 'ramda'
d.arizona's avatar
d.arizona committed
8
import Images from '../../../assets/Images';
a.bairuha's avatar
a.bairuha committed
9
import Constant from '../../../library/Constant';
faisalhamdi's avatar
faisalhamdi committed
10 11

export default class CreateParameter extends Component {
12 13 14 15 16 17
    constructor(props) {
        super(props)
        this.state = {
            enableParameter: false,
            id: '',
            description: '',
18
            value: '',
19
            order: null,
20 21
            minValue: '',
            maxValue: '',
22
            startDate: '',
Deni Rinaldi's avatar
Deni Rinaldi committed
23
            endDate: null,
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
            date: new Date(),
            approvedBy: null,
            getApprovedBy: null,
            types: null,
            getTypes: null,
            perusahaan: null,
            getPerusahaan: null,
            parameter: null,
            getParameter: null,
            operators: null,
            getOperators: null,
            tempData: null,
            errorParameter: false,
            errorDeskripsi: false,
            errorValue: false,
            errorMinValue: false,
            errorOrder: false,
            errorMaxValue: false,
            errorStartDate: false,
            errorEndDate: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
44 45 46 47
            errorGroup: false,
            errorPerusahaan: false,
            msgErrorPerusahaan: '',
            msgErrorGroup: '',
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
            msgErrorParameter: '',
            msgErrorDeskripsi: '',
            msgErrorValue: '',
            msgErrorMinValue: '',
            msgErrorOrder: '',
            msgErrorMaxValue: '',
            msgErrorStartDate: '',
            msgErrorEndDate: ''
        }
    }

    componentDidMount() {
        if (this.props.type === 'edit') {
            this.getDetailParameter()
        } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
63 64 65 66 67
            let date = format(new Date, 'yyyy-MM-dd')
            this.setState({
                startDate: date,
                endDate: date
            })
68 69 70 71 72 73
            this.getDataGroup()
            this.getDataPerusahaan()
        }
    }

    getDetailParameter() {
Deni Rinaldi's avatar
Deni Rinaldi committed
74
        api.create().getDetailParameter(this.props.data[0]).then((response) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
75
            // console.log(response);
a.bairuha's avatar
a.bairuha committed
76
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
77 78 79 80 81
                if (response.ok) {
                    if (response.data.status === 'success') {
                        let data = response.data.data
                        this.setState({
                            tempData: response.data.data,
82
                            getSettingGroupID: response.data.data.setting_group_id,
a.bairuha's avatar
a.bairuha committed
83 84
                            getCompanyID: data.company_id,
                            settingType: data.setting_type,
Deni Rinaldi's avatar
Deni Rinaldi committed
85
                            getSettingTypeID: data.setting_type_id
a.bairuha's avatar
a.bairuha committed
86 87 88
                        }, () => {
                            this.getAllGroup()
                            this.getPerusahaan()
Deni Rinaldi's avatar
Deni Rinaldi committed
89
                            // console.log(this.state.tempData)
a.bairuha's avatar
a.bairuha committed
90 91 92
                        })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
93
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
94 95 96 97 98 99 100
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
                    }
a.bairuha's avatar
a.bairuha committed
101
                } else {
a.bairuha's avatar
a.bairuha committed
102
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
103
                }
104
            } else {
a.bairuha's avatar
a.bairuha committed
105
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
106 107 108 109 110 111
            }
        })
    }

    getAllGroup() {
        api.create().getAllGroup().then(response => {
Deni Rinaldi's avatar
Deni Rinaldi committed
112
            // console.log(response);
a.bairuha's avatar
a.bairuha committed
113
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let typeData = data.map((item) => {
                            return {
                                setting_group_id: item.setting_group_id,
                                setting_group_name: item.setting_group_name
                            }
                        })
                        let index = typeData.findIndex((val) => val.setting_group_id == this.state.getSettingGroupID)
                        let typeProps = {
                            options: typeData,
                            getOptionLabel: (option) => option.setting_group_name,
                        };
Deni Rinaldi's avatar
Deni Rinaldi committed
128 129 130
                        this.setState({ types: typeProps, typeData: response.data.data, getTypes: index == -1 ? typeData[0] : typeData[index] }, () => {
                            this.getParameterByGroup(this.state.getTypes.setting_group_id)
                        })
a.bairuha's avatar
a.bairuha committed
131 132
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
133
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
134 135 136 137 138 139
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
140
                    }
a.bairuha's avatar
a.bairuha committed
141
                } else {
a.bairuha's avatar
a.bairuha committed
142
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
143
                }
144
            } else {
a.bairuha's avatar
a.bairuha committed
145
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
146 147 148 149 150 151
            }
        })
    }

    getPerusahaan() {
        api.create().getPerusahaanActive().then(response => {
a.bairuha's avatar
a.bairuha committed
152
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let perusahaanData = data.map((item) => {
                            return {
                                company_id: item.company_id,
                                company_name: item.company_name
                            }
                        })
                        perusahaanData.push({
                            company_id: 0,
                            company_name: 'Default'
                        })
                        let index = perusahaanData.sort((a, b) => a.company_id - b.company_id).findIndex((val) => val.company_id == this.state.getCompanyID)
                        let typeProps = {
                            options: perusahaanData,
                            getOptionLabel: (option) => option.company_name,
                        };
a.bairuha's avatar
a.bairuha committed
171
                        this.setState({ perusahaan: typeProps, perusahaanData: response.data.data, getPerusahaan: index == -1 ? null : perusahaanData[index], msgErrorPerusahaan: index === -1 ? 'Company has been Inactive' : "", errorPerusahaan: index === -1 ? true : false })
a.bairuha's avatar
a.bairuha committed
172 173
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
174
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
175 176 177 178 179 180
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
181
                    }
a.bairuha's avatar
a.bairuha committed
182
                } else {
a.bairuha's avatar
a.bairuha committed
183
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
184
                }
185
            } else {
a.bairuha's avatar
a.bairuha committed
186
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
187 188 189 190 191 192
            }
        })
    }

    getDataGroup() {
        api.create().getAllGroup().then((response) => {
a.bairuha's avatar
a.bairuha committed
193
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let typeData = data.map((item) => {
                            return {
                                setting_group_id: item.setting_group_id,
                                setting_group_name: item.setting_group_name
                            }
                        })
                        let typeProps = {
                            options: typeData,
                            getOptionLabel: (option) => option.setting_group_name,
                        };
                        this.setState({ types: typeProps, typeData: response.data.data })
                    } 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
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
217
                    }
a.bairuha's avatar
a.bairuha committed
218
                } else {
a.bairuha's avatar
a.bairuha committed
219
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
220
                }
221
            } else {
a.bairuha's avatar
a.bairuha committed
222
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
223 224 225 226 227 228
            }
        })
    }

    getDataPerusahaan() {
        api.create().getPerusahaanActive().then((response) => {
a.bairuha's avatar
a.bairuha committed
229
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
                if (response.ok) {
                    if (response.data.status == 'success') {
                        let data = response.data.data
                        let typeData = data.map((item) => {
                            return {
                                company_id: item.company_id,
                                company_name: item.company_name
                            }
                        })
                        typeData.push({
                            company_id: 0,
                            company_name: 'Default'
                        })
                        let typeProps = {
                            options: typeData.sort((a, b) => a.company_id - b.company_id),
                            getOptionLabel: (option) => option.company_name,
                        };
                        this.setState({ perusahaan: typeProps, perusahaanData: response.data.data })
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
250
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
251 252 253 254 255 256
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
257
                    }
a.bairuha's avatar
a.bairuha committed
258
                } else {
a.bairuha's avatar
a.bairuha committed
259
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
260
                }
261
            } else {
a.bairuha's avatar
a.bairuha committed
262
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
263 264 265 266 267 268
            }
        })
    }

    getParameterByGroup(id) {
        api.create().getParameterByGroup(id).then(response => {
Deni Rinaldi's avatar
Deni Rinaldi committed
269
            // console.log(id, response);
a.bairuha's avatar
a.bairuha committed
270
            if (response.data) {
a.bairuha's avatar
a.bairuha committed
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 typeData = data.map((item) => {
                            return {
                                setting_type_id: item.setting_type_id,
                                setting_type_name: item.setting_type_name
                            }
                        })
                        let index = typeData.findIndex((val) => val.setting_type_id == this.state.getSettingTypeID)
                        let typeProps = {
                            options: typeData,
                            getOptionLabel: (option) => option.setting_type_name,
                        };
Deni Rinaldi's avatar
Deni Rinaldi committed
285
                        this.setState({ enableParameter: true, parameter: typeProps, parameterData: response.data.data, getParameter: index == -1 ? null : typeData[index] })
a.bairuha's avatar
a.bairuha committed
286 287
                    } else {
                        this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
d.arizona's avatar
d.arizona committed
288
                            if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
a.bairuha's avatar
a.bairuha committed
289 290 291 292 293 294
                                setTimeout(() => {
                                    localStorage.removeItem(Constant.TOKEN)
                                    window.location.reload();
                                }, 1000);
                            }
                        })
295
                    }
a.bairuha's avatar
a.bairuha committed
296
                } else {
a.bairuha's avatar
a.bairuha committed
297
                    this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
a.bairuha's avatar
a.bairuha committed
298
                }
299
            } else {
a.bairuha's avatar
a.bairuha committed
300
                this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
            }
        })
    }

    handleChange(e, type) {
        let data = this.state
        let isDate = type !== '' ? true : false
        if (isDate && type == 'start_date') {
            this.setState({
                ...data, tempData: { ...this.state.tempData, start_date: format(e, 'yyyy-MM-dd'), end_date: null },
                errorParameter: false,
                errorDeskripsi: false,
                errorValue: false,
                errorMinValue: false,
                errorOrder: false,
                errorMaxValue: false,
                errorStartDate: false,
                errorEndDate: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
319 320 321 322
                errorGroup: false,
                errorPerusahaan: false,
                msgErrorPerusahaan: '',
                msgErrorGroup: '',
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
                msgErrorParameter: '',
                msgErrorDeskripsi: '',
                msgErrorValue: '',
                msgErrorMinValue: '',
                msgErrorOrder: '',
                msgErrorMaxValue: '',
                msgErrorStartDate: '',
                msgErrorEndDate: ''
            })
        } else if (isDate && type == 'end_date') {
            this.setState({
                ...data, tempData: { ...this.state.tempData, end_date: format(e, 'yyyy-MM-dd') },
                errorParameter: false,
                errorDeskripsi: false,
                errorValue: false,
                errorMinValue: false,
                errorOrder: false,
                errorMaxValue: false,
                errorStartDate: false,
                errorEndDate: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
343 344 345 346
                errorGroup: false,
                errorPerusahaan: false,
                msgErrorPerusahaan: '',
                msgErrorGroup: '',
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
                msgErrorParameter: '',
                msgErrorDeskripsi: '',
                msgErrorValue: '',
                msgErrorMinValue: '',
                msgErrorOrder: '',
                msgErrorMaxValue: '',
                msgErrorStartDate: '',
                msgErrorEndDate: ''
            })
        } else {
            this.setState({
                ...data,
                tempData: { ...this.state.tempData, [e.target.name]: e.target.value },
                errorParameter: false,
                errorDeskripsi: false,
                errorValue: false,
                errorMinValue: false,
                errorOrder: false,
                errorMaxValue: false,
                errorStartDate: false,
                errorEndDate: false,
Deni Rinaldi's avatar
Deni Rinaldi committed
368 369 370 371
                errorGroup: false,
                errorPerusahaan: false,
                msgErrorPerusahaan: '',
                msgErrorGroup: '',
372 373 374 375 376 377 378 379 380 381 382 383
                msgErrorParameter: '',
                msgErrorDeskripsi: '',
                msgErrorValue: '',
                msgErrorMinValue: '',
                msgErrorOrder: '',
                msgErrorMaxValue: '',
                msgErrorStartDate: '',
                msgErrorEndDate: ''
            })
        }
    }

Deni Rinaldi's avatar
Deni Rinaldi committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
    clearMessage() {
        this.setState({
            errorParameter: false,
            errorDeskripsi: false,
            errorValue: false,
            errorMinValue: false,
            errorOrder: false,
            errorMaxValue: false,
            errorStartDate: false,
            errorEndDate: false,
            errorGroup: false,
            errorPerusahaan: false,
            msgErrorPerusahaan: '',
            msgErrorGroup: '',
            msgErrorParameter: '',
            msgErrorDeskripsi: '',
            msgErrorValue: '',
            msgErrorMinValue: '',
            msgErrorOrder: '',
            msgErrorMaxValue: '',
            msgErrorStartDate: '',
            msgErrorEndDate: ''
        })
    }

409 410 411 412
    handleChangeCreate(e, type) {
        let data = this.state
        let isDate = type !== '' ? true : false
        if (isDate && type == 'start_date') {
Deni Rinaldi's avatar
Deni Rinaldi committed
413
            this.setState({ startDate: format(e, 'yyyy-MM-dd'), endDate: null }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
414
                // console.log(this.state.startDate)
415 416 417
            })
        } else if (isDate && type == 'end_date') {
            this.setState({ endDate: format(e, 'yyyy-MM-dd') }, () => {
Deni Rinaldi's avatar
Deni Rinaldi committed
418
                // console.log(this.state.endDate)
419 420
            })
        } else {
Deni Rinaldi's avatar
Deni Rinaldi committed
421
            this.setState({ ...data, [e.target.name]: e.target.value }, () => this.clearMessage())
422 423 424 425
        }
    }

    validasi() {
Deni Rinaldi's avatar
Deni Rinaldi committed
426
        if (R.isNil(this.state.getTypes)) {
EKSAD's avatar
EKSAD committed
427
            this.setState({ errorGroup: true, msgErrorGroup: 'Group Cannot be Empty' })
Deni Rinaldi's avatar
Deni Rinaldi committed
428
        } else if (R.isNil(this.state.getParameter)) {
EKSAD's avatar
EKSAD committed
429
            this.setState({ errorParameter: true, msgErrorParameter: 'Parameter Cannot be Empty' })
Deni Rinaldi's avatar
Deni Rinaldi committed
430
        } else if (R.isNil(this.state.getPerusahaan)) {
EKSAD's avatar
EKSAD committed
431
            this.setState({ errorPerusahaan: true, msgErrorPerusahaan: 'Company Cannot be Empty' })
Deni Rinaldi's avatar
Deni Rinaldi committed
432 433
            // } else if (R.isEmpty(this.state.tempData.description)) {
            //     this.setState({ errorDeskripsi: true, msgErrorDeskripsi: 'Deskripsi tidak boleh kosong' })
434
        } else if (R.isEmpty(this.state.tempData.value) && R.isEmpty(this.state.tempData.min_value) && R.isEmpty(this.state.tempData.max_value)) {
EKSAD's avatar
EKSAD committed
435
            this.setState({ errorValue: true, msgErrorValue: 'Value Cannot be Empty' })
436
        } else if ((!R.isEmpty(this.state.tempData.max_value) && R.isEmpty(this.state.tempData.min_value))) {
EKSAD's avatar
EKSAD committed
437
            this.setState({ errorMinValue: true, msgErrorMinValue: 'Min Value Cannot be Empty' })
438
        } else if (R.isNil(this.state.tempData.start_date)) {
EKSAD's avatar
EKSAD committed
439
            this.setState({ errorStartDate: true, msgErrorStartDate: 'Valid From Cannot be Empty' })
Deni Rinaldi's avatar
Deni Rinaldi committed
440 441
            // } else if (R.isNil(this.state.tempData.order)) {
            //     this.setState({ errorOrder: true, msgErrorOrder: 'Order tidak boleh kosong' })
442
        } else if ((!R.isEmpty(this.state.tempData.min_value) && R.isEmpty(this.state.tempData.max_value))) {
EKSAD's avatar
EKSAD committed
443
            this.setState({ errorMaxValue: true, msgErrorMaxValue: 'Max Value Cannot be Empty' })
444
        } else if (R.isNil(this.state.tempData.end_date)) {
EKSAD's avatar
EKSAD committed
445
            this.setState({ errorEndDate: true, msgErrorEndDate: 'Valid To Cannot be Empty' })
446 447 448 449 450 451
        } else {
            this.updateParameter()
        }
    }

    validasiCreate() {
Deni Rinaldi's avatar
Deni Rinaldi committed
452
        if (R.isNil(this.state.getTypes)) {
EKSAD's avatar
EKSAD committed
453
            this.setState({ errorGroup: true, msgErrorGroup: 'Group Cannot be Empty' })
Deni Rinaldi's avatar
Deni Rinaldi committed
454
        } else if (R.isNil(this.state.getParameter)) {
EKSAD's avatar
EKSAD committed
455
            this.setState({ errorParameter: true, msgErrorParameter: 'Parameter Cannot be Empty' })
Deni Rinaldi's avatar
Deni Rinaldi committed
456
        } else if (R.isNil(this.state.getPerusahaan)) {
EKSAD's avatar
EKSAD committed
457
            this.setState({ errorPerusahaan: true, msgErrorPerusahaan: 'Company Cannot be Empty' })
Deni Rinaldi's avatar
Deni Rinaldi committed
458 459
            // } else if (R.isEmpty(this.state.description)) {
            //     this.setState({ errorDeskripsi: true, msgErrorDeskripsi: 'Deskripsi tidak boleh kosong' })
460
        } else if ((R.isEmpty(this.state.value) && R.isEmpty(this.state.maxValue) && R.isEmpty(this.state.minValue))) {
EKSAD's avatar
EKSAD committed
461
            this.setState({ errorValue: true, msgErrorValue: 'Value Cannot be Empty' })
462
        } else if ((!R.isEmpty(this.state.maxValue) && R.isEmpty(this.state.minValue))) {
EKSAD's avatar
EKSAD committed
463
            this.setState({ errorMinValue: true, msgErrorMinValue: 'Min Value Cannot be Empty' })
464
        } else if (R.isNil(this.state.startDate)) {
EKSAD's avatar
EKSAD committed
465
            this.setState({ errorStartDate: true, msgErrorStartDate: 'Valid From Cannot be Empty' })
Deni Rinaldi's avatar
Deni Rinaldi committed
466 467
            // } else if (R.isNil(this.state.order)) {
            //     this.setState({ errorOrder: true, msgErrorOrder: 'Order tidak boleh kosong' })
468
        } else if ((!R.isEmpty(this.state.minValue) && R.isEmpty(this.state.maxValue))) {
EKSAD's avatar
EKSAD committed
469
            this.setState({ errorMaxValue: true, msgErrorMaxValue: 'Max Value Cannot be Empty' })
470
        } else if (R.isNil(this.state.endDate)) {
EKSAD's avatar
EKSAD committed
471
            this.setState({ errorEndDate: true, msgErrorEndDate: 'Valid To Cannot be Empty' })
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
        } else {
            this.createParameter()
        }
    }

    updateParameter() {
        let body = {
            "setting_id": this.state.tempData.setting_id,
            "setting_group_id": this.state.getTypes.setting_group_id,
            "setting_type_id": this.state.getParameter.setting_type_id,
            "company_id": this.state.getPerusahaan.company_id,
            "description": this.state.tempData.description,
            "orders": this.state.tempData.order,
            "value": this.state.tempData.value,
            "max_value": this.state.tempData.max_value,
            "min_value": this.state.tempData.min_value,
            "start_date": this.state.tempData.start_date,
            "end_date": this.state.tempData.end_date
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
491
        // console.log(body);
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
        this.props.updateParameter(body)
    }

    createParameter() {
        let body = {
            "setting_group_id": this.state.getTypes.setting_group_id,
            "setting_type_id": this.state.getParameter.setting_type_id,
            "company_id": this.state.getPerusahaan.company_id,
            "description": this.state.description,
            "orders": this.state.order,
            "value": this.state.value,
            "max_value": this.state.maxValue,
            "min_value": this.state.minValue,
            "start_date": this.state.startDate,
            "end_date": this.state.endDate
        }
Deni Rinaldi's avatar
Deni Rinaldi committed
508
        // console.log(body);
509 510 511
        this.props.createParameter(body)
    }

faisalhamdi's avatar
faisalhamdi committed
512 513 514 515 516 517 518
    render() {
        let { type } = this.props
        return type === 'edit' ? this.renderEdit() : this.renderCreate()
    }

    renderEdit() {
        return (
519
            <div className="test app-popup-show">
faisalhamdi's avatar
faisalhamdi committed
520
                <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
521
                    <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
faisalhamdi's avatar
faisalhamdi committed
522 523 524 525 526 527 528 529 530 531 532
                        <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                            <div className="popup-title">
                                <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Ubah Data</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.props.onClickClose()}
                            >
Deni Rinaldi's avatar
Deni Rinaldi committed
533
                                <img src={Images.close} />
faisalhamdi's avatar
faisalhamdi committed
534 535 536 537 538
                            </button>
                        </div>
                    </div>


Deni Rinaldi's avatar
Deni Rinaldi committed
539
                    <div className="grid grid-2x grid-mobile-none gap-15px" style={{ padding: 20 }}>
faisalhamdi's avatar
faisalhamdi committed
540 541 542 543
                        <div className="column-1">
                            <div style={{ backgroundColor: '#e8e8e8', padding: 10, borderRadius: 5 }}>
                                <TextField
                                    style={{ width: '100%' }}
544
                                    value={this.state.tempData === null ? '' : this.state.tempData.setting_id}
faisalhamdi's avatar
faisalhamdi committed
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
                                    id="id"
                                    label="ID"
                                    disabled
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
                                />
                            </div>
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
562 563 564 565
                                <Autocomplete
                                    {...this.state.parameter}
                                    debug
                                    id="tipe"
Deni Rinaldi's avatar
Deni Rinaldi committed
566
                                    onChange={(event, newInputValue) => this.setState({ getParameter: newInputValue }, () => this.clearMessage())}
Deni Rinaldi's avatar
Deni Rinaldi committed
567 568 569 570 571 572 573 574 575
                                    renderInput={(params) =>
                                        <TextField
                                            {...params}
                                            InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
                                            InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
                                            label="Parameter"
                                            error={this.state.errorParameter}
                                            helperText={this.state.msgErrorParameter}
                                        />}
576 577
                                    value={this.state.getParameter}
                                />
faisalhamdi's avatar
faisalhamdi committed
578 579 580 581
                            </div>
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
                                <TextField
                                    style={{ width: '100%' }}
582 583 584
                                    id="description"
                                    label="Description"
                                    value={this.state.tempData === null ? '' : this.state.tempData.description}
faisalhamdi's avatar
faisalhamdi committed
585 586 587 588 589 590 591 592 593 594 595
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
596 597
                                    name="description"
                                    onChange={(e) => this.handleChange(e, '')}
Deni Rinaldi's avatar
Deni Rinaldi committed
598 599
                                // error={this.state.errorDeskripsi}
                                // helperText={this.state.msgErrorDeskripsi}
faisalhamdi's avatar
faisalhamdi committed
600 601 602 603 604 605 606 607
                                >
                                </TextField>
                            </div>
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
                                <TextField
                                    style={{ width: '100%' }}
                                    id="value"
                                    label="Value"
608
                                    value={this.state.tempData === null ? '' : this.state.tempData.value}
faisalhamdi's avatar
faisalhamdi committed
609
                                    inputProps={{
610
                                        min: 0,
faisalhamdi's avatar
faisalhamdi committed
611 612 613 614 615 616 617 618 619 620
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
621
                                    name="value"
Deni Rinaldi's avatar
Deni Rinaldi committed
622 623 624 625
                                    onChange={(e) => {
                                        this.setState({
                                            tempData: {
                                                ...this.state.tempData,
Deni Rinaldi's avatar
Deni Rinaldi committed
626
                                                value: e.target.value
Deni Rinaldi's avatar
Deni Rinaldi committed
627 628 629 630 631 632
                                            }
                                        })
                                        this.clearMessage()
                                    }
                                        // this.handleChange(coba, 'value')}
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
633 634
                                    error={this.state.errorValue}
                                    helperText={this.state.msgErrorValue}
faisalhamdi's avatar
faisalhamdi committed
635 636 637 638 639 640
                                >
                                </TextField>
                            </div>
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
                                <TextField
                                    style={{ width: '100%' }}
641
                                    id="min_value"
faisalhamdi's avatar
faisalhamdi committed
642
                                    label="Min Value"
643
                                    value={this.state.tempData === null ? '' : this.state.tempData.min_value}
faisalhamdi's avatar
faisalhamdi committed
644
                                    inputProps={{
645
                                        min: 0,
faisalhamdi's avatar
faisalhamdi committed
646 647 648 649 650 651 652 653 654 655
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
656
                                    name="min_value"
Deni Rinaldi's avatar
Deni Rinaldi committed
657
                                    onChange={(e) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
658
                                        // let coba = String(e.target.value).replace(/[^\d]/g, '');
Deni Rinaldi's avatar
Deni Rinaldi committed
659 660 661
                                        this.setState({
                                            tempData: {
                                                ...this.state.tempData,
Deni Rinaldi's avatar
Deni Rinaldi committed
662
                                                min_value: e.target.value
Deni Rinaldi's avatar
Deni Rinaldi committed
663 664 665 666 667 668
                                            }
                                        })
                                        this.clearMessage()
                                    }
                                        // this.handleChange(coba, 'value')}
                                    }
669 670
                                    error={this.state.errorMinValue}
                                    helperText={this.state.msgErrorMinValue}
faisalhamdi's avatar
faisalhamdi committed
671 672 673 674
                                >
                                </TextField>
                            </div>
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
675 676 677
                                <DatePicker
                                    margin="normal"
                                    id="start_date"
Deni Rinaldi's avatar
Deni Rinaldi committed
678
                                    label="Valid From"
Deni Rinaldi's avatar
Deni Rinaldi committed
679
                                    format="dd-MM-yyyy"
680 681 682 683 684 685 686
                                    value={this.state.tempData === null ? '' : this.state.tempData.start_date}
                                    error={this.state.errorStartDate}
                                    helperText={this.state.msgErrorStartDate}
                                    onChange={(e) => this.handleChange(e, 'start_date')}
                                    KeyboardButtonProps={{
                                        'aria-label': 'change date',
                                    }}
faisalhamdi's avatar
faisalhamdi committed
687 688 689 690 691 692 693 694 695 696 697
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
698 699 700

                                    style={{ padding: 0, margin: 0, width: '100%' }}
                                />
faisalhamdi's avatar
faisalhamdi committed
701 702
                            </div>

703
                            <div className="margin-top-10px" style={{ backgroundColor: '#e8e8e8', padding: 10, borderRadius: 5 }}>
faisalhamdi's avatar
faisalhamdi committed
704 705 706 707
                                <TextField
                                    style={{ width: '100%' }}
                                    id="status"
                                    label="Status"
708
                                    value={this.state.tempData === null ? '' : this.state.tempData.status}
faisalhamdi's avatar
faisalhamdi committed
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
                                    disabled
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
                                />
                            </div>
                        </div>

                        <div className="column-2">
726 727 728 729 730
                            <div className="" style={{ padding: 10, borderRadius: 5 }}>
                                <Autocomplete
                                    {...this.state.types}
                                    debug
                                    id="tipe"
Deni Rinaldi's avatar
Deni Rinaldi committed
731 732 733 734 735 736 737 738 739
                                    onChange={(event, newInputValue) => this.setState({ getTypes: newInputValue }, () => newInputValue === null ? this.setState({ enableParameter: false, getParameter: null }, () => this.clearMessage()) : this.getParameterByGroup(newInputValue.setting_group_id), this.clearMessage())}
                                    renderInput={(params) =>
                                        <TextField
                                            {...params}
                                            error={this.state.errorGroup}
                                            helperText={this.state.msgErrorGroup}
                                            InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
                                            InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
                                            label="Group" />}
740 741
                                    value={this.state.getTypes}
                                />
faisalhamdi's avatar
faisalhamdi committed
742 743
                            </div>
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
744 745 746 747
                                <Autocomplete
                                    {...this.state.perusahaan}
                                    debug
                                    id="tipe"
Deni Rinaldi's avatar
Deni Rinaldi committed
748 749 750 751 752 753 754
                                    onChange={(event, newInputValue) => this.setState({ getPerusahaan: newInputValue }, () => this.clearMessage())}
                                    renderInput={(params) =>
                                        <TextField {...params}
                                            error={this.state.errorPerusahaan}
                                            helperText={this.state.msgErrorPerusahaan}
                                            InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
                                            InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
Deni Rinaldi's avatar
Deni Rinaldi committed
755
                                            label="Company Name" />}
756 757
                                    value={this.state.getPerusahaan}
                                />
faisalhamdi's avatar
faisalhamdi committed
758 759 760 761 762 763
                            </div>
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
                                <TextField
                                    style={{ width: '100%' }}
                                    id="order"
                                    label="Order"
764
                                    value={this.state.tempData === null ? '' : this.state.tempData.order}
faisalhamdi's avatar
faisalhamdi committed
765
                                    inputProps={{
766
                                        min: 0,
faisalhamdi's avatar
faisalhamdi committed
767 768 769 770 771 772 773 774 775 776
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
777
                                    name="order"
Deni Rinaldi's avatar
Deni Rinaldi committed
778
                                    onChange={(e) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
779
                                        let coba = String(e.target.value).replace(/[^\d]/g, '');
Deni Rinaldi's avatar
Deni Rinaldi committed
780 781 782 783 784 785
                                        this.setState({
                                            tempData: {
                                                ...this.state.tempData,
                                                order: coba
                                            }
                                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
786 787
                                        this.clearMessage()
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
788 789
                                        // this.handleChange(coba, 'value')}
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
790 791
                                // error={this.state.errorOrder}
                                // helperText={this.state.msgErrorOrder}
faisalhamdi's avatar
faisalhamdi committed
792 793 794 795 796 797
                                >
                                </TextField>
                            </div>
                            <div style={{ marginTop: '80px', padding: 10, borderRadius: 5 }}>
                                <TextField
                                    style={{ width: '100%' }}
798
                                    id="max_value"
faisalhamdi's avatar
faisalhamdi committed
799
                                    label="Max Value"
800
                                    value={this.state.tempData === null ? '' : this.state.tempData.max_value}
faisalhamdi's avatar
faisalhamdi committed
801
                                    inputProps={{
802
                                        min: 0,
faisalhamdi's avatar
faisalhamdi committed
803 804 805 806 807 808 809 810 811 812
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
813
                                    name="max_value"
Deni Rinaldi's avatar
Deni Rinaldi committed
814
                                    onChange={(e) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
815
                                        // let coba = String(e.target.value).replace(/[^\d]/g, '');
Deni Rinaldi's avatar
Deni Rinaldi committed
816 817 818
                                        this.setState({
                                            tempData: {
                                                ...this.state.tempData,
Deni Rinaldi's avatar
Deni Rinaldi committed
819
                                                max_value: e.target.value
Deni Rinaldi's avatar
Deni Rinaldi committed
820 821 822 823 824 825
                                            }
                                        })
                                        this.clearMessage()
                                    }
                                        // this.handleChange(coba, 'value')}
                                    }
826 827
                                    error={this.state.errorMaxValue}
                                    helperText={this.state.msgErrorMaxValue}
faisalhamdi's avatar
faisalhamdi committed
828 829 830 831
                                >
                                </TextField>
                            </div>
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
832 833 834
                                <DatePicker
                                    margin="normal"
                                    id="end_date"
Deni Rinaldi's avatar
Deni Rinaldi committed
835
                                    label="Valid To"
Deni Rinaldi's avatar
Deni Rinaldi committed
836
                                    format="dd-MM-yyyy"
837 838 839 840 841 842 843 844
                                    error={this.state.errorEndDate}
                                    helperText={this.state.msgErrorEndDate}
                                    minDate={this.state.tempData === null ? null : this.state.tempData.start_date}
                                    value={this.state.tempData === null ? '' : this.state.tempData.end_date}
                                    onChange={(e) => this.handleChange(e, 'end_date')}
                                    KeyboardButtonProps={{
                                        'aria-label': 'change date',
                                    }}
faisalhamdi's avatar
faisalhamdi committed
845 846 847 848 849 850 851 852 853 854 855
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
856 857 858

                                    style={{ padding: 0, margin: 0, width: '100%' }}
                                />
faisalhamdi's avatar
faisalhamdi committed
859 860 861 862
                            </div>
                        </div>
                    </div>

Deni Rinaldi's avatar
Deni Rinaldi committed
863 864 865 866 867 868 869 870 871 872 873
                    <div className="border-bottom margin-top-10px" style={{ padding: '0px 20px 20px 20px', borderRadius: 5 }}>
                        <div style={{ display: 'flex' }}>
                            <Typography style={{ fontSize: 11, width: '12%' }}>Created By</Typography>
                            <Typography style={{ fontSize: 11 }}>: {this.state.tempData === null ? "" : this.state.tempData.created}</Typography>
                        </div>
                        <div style={{ display: 'flex' }}>
                            <Typography style={{ fontSize: 11, width: '12%' }}>Updated By</Typography>
                            <Typography style={{ fontSize: 11 }}>: {this.state.tempData === null ? "" : this.state.tempData.updated === null ? "" : this.state.tempData.updated}</Typography>
                        </div>
                    </div>

faisalhamdi's avatar
faisalhamdi committed
874 875
                    <div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
                        <div className="column-1" style={{ alignSelf: 'center' }}>
876 877 878 879 880
                            <button
                                type="button"
                                onClick={() => this.props.onClickClose()}
                            >
                                <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
a.bairuha's avatar
a.bairuha committed
881
                                    <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
882 883
                                </div>
                            </button>
faisalhamdi's avatar
faisalhamdi committed
884 885
                        </div>
                        <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
886 887 888 889 890
                            <button
                                type="button"
                                onClick={() => this.validasi()}
                            >
                                <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
a.bairuha's avatar
a.bairuha committed
891
                                    <span style={{ color: '#fff', fontSize: 11 }}>Save</span>
892 893
                                </div>
                            </button>
faisalhamdi's avatar
faisalhamdi committed
894 895 896 897 898 899 900 901 902
                        </div>
                    </div>
                </div>
            </div>
        )
    }

    renderCreate() {
        return (
903
            <div className="test app-popup-show">
faisalhamdi's avatar
faisalhamdi committed
904
                <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
905
                    <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
faisalhamdi's avatar
faisalhamdi committed
906 907 908 909 910 911 912 913 914 915 916
                        <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
                            <div className="popup-title">
                                <span style={{ color: '#fff', fontSize: 16, fontWeight: 'bold' }}>Create Data</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.props.onClickClose()}
                            >
Deni Rinaldi's avatar
Deni Rinaldi committed
917
                                <img src={Images.close} />
faisalhamdi's avatar
faisalhamdi committed
918 919 920 921 922 923 924
                            </button>
                        </div>
                    </div>


                    <div className="border-bottom grid grid-2x grid-mobile-none gap-15px" style={{ padding: 20 }}>
                        <div className="column-1">
925
                            <div style={{ backgroundColor: '#e8e8e8', padding: 10, borderRadius: 5 }}>
faisalhamdi's avatar
faisalhamdi committed
926 927
                                <TextField
                                    style={{ width: '100%' }}
928 929 930 931
                                    value={this.state.tempData === null ? '' : this.state.tempData.setting_id}
                                    id="id"
                                    label="ID"
                                    disabled
faisalhamdi's avatar
faisalhamdi committed
932 933 934 935 936 937 938 939 940 941 942
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
943
                                />
faisalhamdi's avatar
faisalhamdi committed
944
                            </div>
945 946 947 948 949 950
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
                                <Autocomplete
                                    {...this.state.parameter}
                                    debug
                                    disabled={!this.state.enableParameter}
                                    id="tipe"
Deni Rinaldi's avatar
Deni Rinaldi committed
951
                                    onChange={(event, newInputValue) => this.setState({ getParameter: newInputValue }, () => this.clearMessage())}
Deni Rinaldi's avatar
Deni Rinaldi committed
952 953 954 955 956 957 958 959 960
                                    renderInput={(params) =>
                                        <TextField
                                            {...params}
                                            InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
                                            InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
                                            label="Parameter"
                                            error={this.state.errorParameter}
                                            helperText={this.state.msgErrorParameter}
                                        />}
961 962 963 964
                                    value={this.state.getParameter}
                                />
                            </div>
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
faisalhamdi's avatar
faisalhamdi committed
965 966
                                <TextField
                                    style={{ width: '100%' }}
967 968 969
                                    id="description"
                                    label="Description"
                                    value={this.state.description === '' ? '' : this.state.description}
faisalhamdi's avatar
faisalhamdi committed
970 971 972 973 974 975 976 977 978 979 980
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
981 982
                                    name="description"
                                    onChange={(e) => this.handleChangeCreate(e, '')}
faisalhamdi's avatar
faisalhamdi committed
983 984 985
                                >
                                </TextField>
                            </div>
986
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
faisalhamdi's avatar
faisalhamdi committed
987 988 989 990
                                <TextField
                                    style={{ width: '100%' }}
                                    id="value"
                                    label="Value"
991
                                    value={this.state.value}
faisalhamdi's avatar
faisalhamdi committed
992
                                    inputProps={{
993
                                        min: 0,
faisalhamdi's avatar
faisalhamdi committed
994 995 996 997
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
Deni Rinaldi's avatar
Deni Rinaldi committed
998

faisalhamdi's avatar
faisalhamdi committed
999 1000 1001 1002 1003 1004
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
1005
                                    name="value"
Deni Rinaldi's avatar
Deni Rinaldi committed
1006 1007
                                    onChange={(e) => {
                                        this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
1008
                                            value: e.target.value
Deni Rinaldi's avatar
Deni Rinaldi committed
1009
                                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
1010 1011
                                        this.clearMessage()
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
1012 1013
                                        // this.handleChange(coba, 'value')}
                                    }
1014 1015
                                    error={this.state.errorValue}
                                    helperText={this.state.msgErrorValue}
faisalhamdi's avatar
faisalhamdi committed
1016 1017 1018
                                >
                                </TextField>
                            </div>
1019
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
faisalhamdi's avatar
faisalhamdi committed
1020 1021
                                <TextField
                                    style={{ width: '100%' }}
1022
                                    id="min_value"
faisalhamdi's avatar
faisalhamdi committed
1023
                                    label="Min Value"
1024
                                    value={this.state.minValue}
faisalhamdi's avatar
faisalhamdi committed
1025
                                    inputProps={{
1026
                                        min: 0,
faisalhamdi's avatar
faisalhamdi committed
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
1037
                                    name="minValue"
Deni Rinaldi's avatar
Deni Rinaldi committed
1038
                                    onChange={(e) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
1039
                                        // let coba = String(e.target.value).replace(/[^\d]/g, '');
Deni Rinaldi's avatar
Deni Rinaldi committed
1040
                                        this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
1041
                                            minValue: e.target.value
Deni Rinaldi's avatar
Deni Rinaldi committed
1042
                                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
1043 1044
                                        this.clearMessage()
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
1045 1046
                                        // this.handleChange(coba, 'value')}
                                    }
1047 1048
                                    error={this.state.errorMinValue}
                                    helperText={this.state.msgErrorMinValue}
faisalhamdi's avatar
faisalhamdi committed
1049 1050 1051
                                >
                                </TextField>
                            </div>
1052 1053 1054 1055
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
                                <DatePicker
                                    margin="normal"
                                    id="startDate"
Deni Rinaldi's avatar
Deni Rinaldi committed
1056
                                    label="Valid From"
Deni Rinaldi's avatar
Deni Rinaldi committed
1057
                                    format="dd-MM-yyyy"
1058 1059 1060 1061 1062 1063 1064
                                    error={this.state.errorStartDate}
                                    helperText={this.state.msgErrorStartDate}
                                    value={this.state.startDate == "" ? null : this.state.startDate}
                                    onChange={(e) => this.handleChangeCreate(e, 'start_date')}
                                    KeyboardButtonProps={{
                                        'aria-label': 'change date',
                                    }}
faisalhamdi's avatar
faisalhamdi committed
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
1076 1077 1078

                                    style={{ padding: 0, margin: 0, width: '100%' }}
                                />
faisalhamdi's avatar
faisalhamdi committed
1079 1080
                            </div>

1081
                            <div className="margin-top-10px" style={{ backgroundColor: '#e8e8e8', padding: 10, borderRadius: 5 }}>
faisalhamdi's avatar
faisalhamdi committed
1082 1083
                                <TextField
                                    style={{ width: '100%' }}
Deni Rinaldi's avatar
Deni Rinaldi committed
1084
                                    defaultValue={"Active"}
faisalhamdi's avatar
faisalhamdi committed
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101
                                    id="status"
                                    label="Status"
                                    disabled
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
                                />
                            </div>

a.bairuha's avatar
a.bairuha committed
1102
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
a.bairuha's avatar
a.bairuha committed
1103 1104
                                <Typography style={{ fontSize: 11, width: '25%' }}>Created By	: </Typography>
                                <Typography style={{ fontSize: 11, width: '25%' }}>Updated By	: </Typography>
faisalhamdi's avatar
faisalhamdi committed
1105 1106 1107 1108
                            </div>
                        </div>

                        <div className="column-2">
1109 1110 1111 1112 1113
                            <div className="" style={{ padding: 10, borderRadius: 5 }}>
                                <Autocomplete
                                    {...this.state.types}
                                    debug
                                    id="tipe"
Deni Rinaldi's avatar
Deni Rinaldi committed
1114
                                    onChange={(event, newInputValue) => this.setState({ getTypes: newInputValue }, () => newInputValue === null ? this.setState({ enableParameter: false, getParameter: null }, () => this.clearMessage()) : this.getParameterByGroup(newInputValue.setting_group_id), this.clearMessage())}
Deni Rinaldi's avatar
Deni Rinaldi committed
1115 1116 1117 1118 1119 1120 1121 1122 1123
                                    renderInput={(params) =>
                                        <TextField
                                            {...params}
                                            InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
                                            InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
                                            label="Group"
                                            error={this.state.errorGroup}
                                            helperText={this.state.msgErrorGroup}
                                        />}
1124 1125
                                    value={this.state.getTypes}
                                />
faisalhamdi's avatar
faisalhamdi committed
1126
                            </div>
1127 1128 1129 1130 1131
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
                                <Autocomplete
                                    {...this.state.perusahaan}
                                    debug
                                    id="tipe"
Deni Rinaldi's avatar
Deni Rinaldi committed
1132
                                    onChange={(event, newInputValue) => this.setState({ getPerusahaan: newInputValue }, () => this.clearMessage())}
Deni Rinaldi's avatar
Deni Rinaldi committed
1133 1134 1135 1136 1137
                                    renderInput={(params) =>
                                        <TextField
                                            {...params}
                                            InputProps={{ ...params.InputProps, style: { fontSize: 11 } }}
                                            InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }}
Deni Rinaldi's avatar
Deni Rinaldi committed
1138
                                            label="Company Name"
Deni Rinaldi's avatar
Deni Rinaldi committed
1139 1140 1141
                                            error={this.state.errorPerusahaan}
                                            helperText={this.state.msgErrorPerusahaan}
                                        />}
1142 1143
                                    value={this.state.getPerusahaan}
                                />
faisalhamdi's avatar
faisalhamdi committed
1144
                            </div>
1145
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
faisalhamdi's avatar
faisalhamdi committed
1146 1147 1148 1149
                                <TextField
                                    style={{ width: '100%' }}
                                    id="order"
                                    label="Order"
1150
                                    value={this.state.order === null ? '' : this.state.order}
faisalhamdi's avatar
faisalhamdi committed
1151
                                    inputProps={{
1152
                                        min: 0,
faisalhamdi's avatar
faisalhamdi committed
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
1163
                                    name="order"
Deni Rinaldi's avatar
Deni Rinaldi committed
1164
                                    onChange={(e) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
1165
                                        let coba = String(e.target.value).replace(/[^\d]/g, '');
Deni Rinaldi's avatar
Deni Rinaldi committed
1166 1167 1168
                                        this.setState({
                                            order: coba
                                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
1169 1170
                                        this.clearMessage()
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
1171 1172
                                        // this.handleChange(coba, 'value')}
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
1173 1174
                                // error={this.state.errorOrder}
                                // helperText={this.state.msgErrorOrder}
faisalhamdi's avatar
faisalhamdi committed
1175 1176 1177
                                >
                                </TextField>
                            </div>
1178
                            <div style={{ marginTop: '80px', padding: 10, borderRadius: 5 }}>
faisalhamdi's avatar
faisalhamdi committed
1179 1180
                                <TextField
                                    style={{ width: '100%' }}
1181
                                    id="max_value"
faisalhamdi's avatar
faisalhamdi committed
1182
                                    label="Max Value"
1183
                                    value={this.state.maxValue}
faisalhamdi's avatar
faisalhamdi committed
1184
                                    inputProps={{
1185
                                        min: 0,
faisalhamdi's avatar
faisalhamdi committed
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
1196
                                    name="maxValue"
Deni Rinaldi's avatar
Deni Rinaldi committed
1197
                                    onChange={(e) => {
Deni Rinaldi's avatar
Deni Rinaldi committed
1198
                                        // let coba = String(e.target.value).replace(/[^\d]/g, '');
Deni Rinaldi's avatar
Deni Rinaldi committed
1199
                                        this.setState({
Deni Rinaldi's avatar
Deni Rinaldi committed
1200
                                            maxValue: e.target.value
Deni Rinaldi's avatar
Deni Rinaldi committed
1201
                                        })
Deni Rinaldi's avatar
Deni Rinaldi committed
1202 1203
                                        this.clearMessage()
                                    }
Deni Rinaldi's avatar
Deni Rinaldi committed
1204 1205
                                        // this.handleChange(coba, 'value')}
                                    }
1206 1207
                                    error={this.state.errorMaxValue}
                                    helperText={this.state.msgErrorMaxValue}
faisalhamdi's avatar
faisalhamdi committed
1208 1209 1210
                                >
                                </TextField>
                            </div>
1211 1212 1213 1214
                            <div className="margin-top-10px" style={{ padding: 10, borderRadius: 5 }}>
                                <DatePicker
                                    margin="normal"
                                    id="endDate"
Deni Rinaldi's avatar
Deni Rinaldi committed
1215
                                    label="Valid To"
Deni Rinaldi's avatar
Deni Rinaldi committed
1216
                                    format="dd-MM-yyyy"
1217 1218 1219 1220 1221 1222 1223 1224
                                    error={this.state.errorEndDate}
                                    helperText={this.state.msgErrorEndDate}
                                    minDate={this.state.startDate}
                                    value={this.state.endDate == "" ? null : this.state.endDate}
                                    onChange={(e) => this.handleChangeCreate(e, 'end_date')}
                                    KeyboardButtonProps={{
                                        'aria-label': 'change date',
                                    }}
faisalhamdi's avatar
faisalhamdi committed
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
                                    inputProps={{
                                        style: {
                                            fontSize: 11
                                        }
                                    }}
                                    InputLabelProps={{
                                        style: {
                                            fontSize: 11,
                                            color: '#7e8085'
                                        }
                                    }}
1236 1237 1238

                                    style={{ padding: 0, margin: 0, width: '100%' }}
                                />
faisalhamdi's avatar
faisalhamdi committed
1239 1240 1241 1242 1243 1244
                            </div>
                        </div>
                    </div>

                    <div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
                        <div className="column-1" style={{ alignSelf: 'center' }}>
1245 1246 1247 1248 1249
                            <button
                                type="button"
                                onClick={() => this.props.onClickClose()}
                            >
                                <div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
a.bairuha's avatar
a.bairuha committed
1250
                                    <span style={{ color: '#354960', fontSize: 11 }}>Cancel</span>
1251 1252
                                </div>
                            </button>
faisalhamdi's avatar
faisalhamdi committed
1253 1254
                        </div>
                        <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
1255 1256 1257 1258 1259
                            <button
                                type="button"
                                onClick={() => this.validasiCreate()}
                            >
                                <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
Deni Rinaldi's avatar
Deni Rinaldi committed
1260
                                    <span style={{ color: '#fff', fontSize: 11 }}>Save</span>
1261 1262
                                </div>
                            </button>
faisalhamdi's avatar
faisalhamdi committed
1263 1264 1265 1266 1267 1268 1269
                        </div>
                    </div>
                </div>
            </div>
        )
    }
}