import React, { Component } from 'react' import { TextField, Typography } from '@material-ui/core' import { DatePicker } from '@material-ui/pickers' import * as R from 'ramda' import api from '../../../api' import Autocomplete from '@material-ui/lab/Autocomplete' import { format } from 'date-fns' import Images from '../../../assets/Images' export default class EditPerusahaan extends Component { constructor(props) { super(props) this.state = { id: '', company: '', companyID: '', parent: '', unitBisnis: '', totalReport: '', startDate: '', endDate: '', status: '', types: null, getTypes: null, perusahaan: null, getPerusahaan: null, errorNP: false, errorPC: false, errorSD: false, errorED: false, errorJL: false, msgErrorNP: '', msgErrorPC: '', msgErrorSD: '', msgErrorED: '', msgErrorJL: '', } } componentDidMount() { let data = this.props.data this.getDetailPerusahaan(data.company_id,) // this.getAllUnitBisnis() } getDetailPerusahaan(id) { api.create().getDetailPerusahaan(id).then(response => { if (response.data.status === "success") { console.log(response); this.setState({ businessID: response.data.data.business_unit_id, companyID: response.data.data.company_id, status: response.data.data.status, company: response.data.data.company_name, parentID: response.data.data.parent, parent: response.data.data.parent_name, startDate: response.data.data.start_date, endDate: response.data.data.end_date, totalReport: response.data.data.total_report, created: response.data.data.created, updated: response.data.data.updated === null ? "" : response.data.data.updated }, () => this.getAllUnitBisnis(), this.getCompanyActive()) } }) } getAllUnitBisnis() { api.create().getUnitBisnisActive().then(response => { console.log(response); if (response.data.status == 'success') { let data = response.data.data let typeData = data.map((item) => { return { business_unit_id: item.business_unit_id, business_unit_name: item.business_unit_name } }) let index = typeData.findIndex((val) => val.business_unit_id == this.state.businessID) let typeProps = { options: typeData, getOptionLabel: (option) => option.business_unit_name, }; this.setState({ types: typeProps, typeData: response.data.data, getTypes: index == -1 ? typeData[0] : typeData[index] }) } else { alert(response.data.message) } }) } getCompanyActive() { api.create().getPerusahaanActive().then(response => { 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 } }) let index = perusahaanData.sort((a, b) => a.company_id - b.company_id).findIndex((val) => val.company_id == this.state.parentID) let typeProps = { options: perusahaanData, getOptionLabel: (option) => option.company_name, }; this.setState({ perusahaan: typeProps, perusahaanData: response.data.data, getPerusahaan: index == -1 ? perusahaanData[0] : perusahaanData[index] }) } else { alert(response.data.message) } }) } clearError() { this.setState({ errorNP: false, errorPC: false, errorSD: false, errorED: false, errorJL: false, msgErrorNP: '', msgErrorPC: '', msgErrorSD: '', msgErrorED: '', msgErrorJL: '', }) } validasi() { if (R.isEmpty(this.state.company)) { this.setState({ errorNP: true, msgErrorNP: 'Nama perusahaan harus diisi' }) } else if (R.isEmpty(this.state.totalReport)) { this.setState({ errorJL: true, msgErrorJL: 'Total Report harus diisi' }) } else if (R.isNil(this.state.startDate)) { this.setState({ errorSD: true, msgErrorSD: 'Start Date tidak boleh kosong' }) } else if (R.isNil(this.state.endDate)) { this.setState({ errorED: true, msgErrorED: 'End Date tidak boleh kosong' }) } let payload = { "company_id": this.state.companyID, "company_name": this.state.company, "business_unit_id": this.state.getTypes.business_unit_id, "parent": this.state.getPerusahaan == null ? null : this.state.getPerusahaan.company_id, "total_report": this.state.totalReport, "start_date": this.state.startDate, "end_date": this.state.endDate } // console.log(payload); this.props.updatePerusahaan(payload) } handleChange(e, type) { let data = this.state let isDate = type !== '' ? true : false if (isDate && type == 'start_date') { this.setState({ startDate: format(e, 'yyyy-MM-dd'), endDate: null }, () => { console.log(this.state.startDate) }) } else if (isDate && type == 'end_date') { this.setState({ endDate: format(e, 'yyyy-MM-dd') }, () => { console.log(this.state.endDate) }) } else { // this.setState({...data, tempData: {...this.state.tempData, [e.target.name] : e.target.value}}) } } render() { return (
Ubah Data
this.setState({ getTypes: newInputValue })} renderInput={(params) => } value={this.state.getTypes} />
this.handleChange(e, 'start_date'), () => this.clearError()} KeyboardButtonProps={{ 'aria-label': 'change date', }} inputProps={{ style: { fontSize: 11 } }} InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }} error={this.state.errorSD} helperText={this.state.msgErrorSD} style={{ padding: 0, margin: 0, width: '100%' }} />
Dibuat : {this.state.created}
Diubah : {this.state.updated == - null ? "" : this.props.data.updated}
this.setState({ company: e.target.value }, () => this.clearError())} error={this.state.errorNP} helperText={this.state.msgErrorNP} >
this.setState({ getPerusahaan: newInputValue })} renderInput={(params) => } value={this.state.getPerusahaan} />
this.handleChange(e, 'end_date'), () => this.clearError()} KeyboardButtonProps={{ 'aria-label': 'change date', }} inputProps={{ style: { fontSize: 11 } }} InputLabelProps={{ style: { fontSize: 11, color: '#7e8085' } }} style={{ padding: 0, margin: 0, width: '100%' }} error={this.state.errorED} helperText={this.state.msgErrorED} />
this.setState({ totalReport: e.target.value }, () => this.clearError())} error={this.state.errorJL} helperText={this.state.msgErrorJL} >
) } }