Commit 8d32f088 authored by Deni Rinaldi's avatar Deni Rinaldi

Merge branch 'faisal' into 'master'

fixed issue company

See merge request !202
parents 6fb1eefd d742784c
import React, { Component } from 'react'; import React, { Component } from 'react';
import { TextField, Typography } from '@material-ui/core'; import { TextField, Typography, withStyles, Snackbar } from '@material-ui/core';
import * as R from 'ramda'; import * as R from 'ramda';
import { DateTimePicker, KeyboardDatePicker, DatePicker } from "@material-ui/pickers"; import { DatePicker } from "@material-ui/pickers";
import format from "date-fns/format"; import format from "date-fns/format";
import Autocomplete from '@material-ui/lab/Autocomplete'; import Autocomplete from '@material-ui/lab/Autocomplete';
import MuiAlert from '@material-ui/lab/Alert';
import api from '../../../api'; import api from '../../../api';
import Images from '../../../assets/Images'; import Images from '../../../assets/Images';
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
export default class CreatePerusahaan extends Component { export default class CreatePerusahaan extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
...@@ -35,7 +39,10 @@ export default class CreatePerusahaan extends Component { ...@@ -35,7 +39,10 @@ export default class CreatePerusahaan extends Component {
msgErrorSD: '', msgErrorSD: '',
msgErrorED: '', msgErrorED: '',
msgErrorJL: '', msgErrorJL: '',
msgErrorUB: '' msgErrorUB: '',
alert: false,
tipeAlert: '',
messageAlert: '',
} }
} }
...@@ -45,7 +52,7 @@ export default class CreatePerusahaan extends Component { ...@@ -45,7 +52,7 @@ export default class CreatePerusahaan extends Component {
} }
componentDidMount() { componentDidMount() {
this.getParentCompany() this.getCompanyActive()
this.getAllUnitBisnis() this.getAllUnitBisnis()
if(this.props.type === 'edit') { if(this.props.type === 'edit') {
this.getDetailPerusahaan() this.getDetailPerusahaan()
...@@ -62,91 +69,112 @@ export default class CreatePerusahaan extends Component { ...@@ -62,91 +69,112 @@ export default class CreatePerusahaan extends Component {
getDetailPerusahaan() { getDetailPerusahaan() {
api.create().getDetailPerusahaan(this.props.data[1]).then(response => { api.create().getDetailPerusahaan(this.props.data[1]).then(response => {
if (response.data.status === "success") { console.log(response)
console.log(response); if (response.data) {
this.setState({ if (response.data.status === "success") {
businessID: response.data.data.business_unit_id, this.setState({
companyID: response.data.data.company_id, businessID: response.data.data.business_unit_id,
status: response.data.data.status, companyID: response.data.data.company_id,
company: response.data.data.company_name, status: response.data.data.status,
parentID: response.data.data.parent, company: response.data.data.company_name,
parent: response.data.data.parent_name, parentID: response.data.data.parent,
startDate: response.data.data.start_date, parent: response.data.data.parent_name,
endDate: response.data.data.end_date, startDate: response.data.data.start_date,
totalReport: response.data.data.total_report, endDate: response.data.data.end_date,
created: response.data.data.created, totalReport: response.data.data.total_report,
updated: response.data.data.updated === null ? "" : response.data.data.updated created: response.data.data.created,
}, () => this.getAllUnitBisnis(), this.getCompanyActive()) updated: response.data.data.updated === null ? "" : response.data.data.updated
} }, () => this.getAllUnitBisnis(), this.getCompanyActive())
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
}) })
} }
getCompanyActive() { getCompanyActive() {
api.create().getPerusahaanActive().then(response => { if (this.state.company !== null) {
if (response.data.status == 'success') { console.log(this.state.company)
let data = response.data.data let payload = {
let perusahaanData = data.map((item) => { "company_id": this.state.company.company_id
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 ? null : perusahaanData[index] })
} else {
alert(response.data.message)
} }
}) api.create().getPerusahaanActive(payload).then(response => {
console.log(response)
if (response.data) {
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 ? null : perusahaanData[index] })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
} }
getAllUnitBisnis() { getAllUnitBisnis() {
api.create().getUnitBisnisActive().then(response => { api.create().getUnitBisnisActive().then(response => {
if (response.data.status === 'success') { if (response.data) {
let data = response.data.data if (response.data.status === 'success') {
let typeData = data.map((item) => { let data = response.data.data
return { let typeData = data.map((item) => {
business_unit_id: item.business_unit_id, return {
business_unit_name: item.business_unit_name business_unit_id: item.business_unit_id,
} business_unit_name: item.business_unit_name
}) }
// console.log(typeData) })
let index = typeData.findIndex((val) => val.business_unit_id == this.state.businessID) // console.log(typeData)
console.log(index) let index = typeData.findIndex((val) => val.business_unit_id == this.state.businessID)
let typeProps = { console.log(index)
options: typeData, let typeProps = {
getOptionLabel: (option) => option.business_unit_name, options: typeData,
}; getOptionLabel: (option) => option.business_unit_name,
this.setState({ types: typeProps, typeData: response.data.data, getTypes: index == -1 ? null : typeData[index] }) };
this.setState({ types: typeProps, typeData: response.data.data, getTypes: index == -1 ? null : typeData[index] })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
}
} else { } else {
alert(response.data.message) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
}) })
} }
getParentCompany() { // getParentCompany() {
api.create().getPerusahaanActive().then((response) => { // api.create().getPerusahaanActive().then((response) => {
if (response.data.status === 'success') { // if (response.data.status === 'success') {
let data = response.data.data // let data = response.data.data
let typeData = data.map((item) => { // let typeData = data.map((item) => {
return { // return {
company_id: item.company_id, // company_id: item.company_id,
company_name: item.company_name // company_name: item.company_name
} // }
}) // })
let typeProps = { // let typeProps = {
options: typeData.sort((a, b) => a.company_id - b.company_id), // options: typeData.sort((a, b) => a.company_id - b.company_id),
getOptionLabel: (option) => option.company_name, // getOptionLabel: (option) => option.company_name,
}; // };
this.setState({ perusahaan: typeProps, perusahaanData: response.data.data }) // this.setState({ perusahaan: typeProps, perusahaanData: response.data.data })
} else { // } else {
alert(response.data.message) // alert(response.data.message)
} // }
}) // })
} // }
handleChange(e, type) { handleChange(e, type) {
let data = this.state let data = this.state
...@@ -229,9 +257,18 @@ export default class CreatePerusahaan extends Component { ...@@ -229,9 +257,18 @@ export default class CreatePerusahaan extends Component {
} }
} }
closeAlert() {
this.setState({ alert: false })
}
renderEdit() { renderEdit() {
return ( return (
<div className="test app-popup-show"> <div className="test app-popup-show">
<Snackbar open={this.state.alert} autoHideDuration={6000} onClose={() => this.closeAlert()}>
<Alert onClose={() => this.closeAlert()} severity={this.state.tipeAlert}>
{this.state.messageAlert}
</Alert>
</Snackbar>
<div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}> <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
<div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}> <div className="popup-panel grid grid-2x main-color" style={{ height: 64, borderTopRightRadius: 8, borderTopLeftRadius: 8 }}>
<div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}> <div className="col-1" style={{ maxWidth: "inherit", display: 'flex', alignItems: 'center' }}>
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Container, Row, Col } from "react-bootstrap"; import { Container, Row, Col } from "react-bootstrap";
import { makeStyles, createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles'; import { Typography, withStyles, Snackbar } from '@material-ui/core';
import { TextField } from '@material-ui/core';
import MenuItem from '@material-ui/core/MenuItem';
import Perusahaan from "./Perusahaan"; import Perusahaan from "./Perusahaan";
import TreeView from '@material-ui/lab/TreeView'; import MuiAlert from '@material-ui/lab/Alert';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import TreeItem from '@material-ui/lab/TreeItem';
import Nestable from 'react-nestable/dist/Nestable'; import Nestable from 'react-nestable/dist/Nestable';
import AddIcon from '@material-ui/icons/Add'; import AddIcon from '@material-ui/icons/Add';
import RemoveIcon from '@material-ui/icons/Remove'; import RemoveIcon from '@material-ui/icons/Remove';
import api from '../../../api'; import api from '../../../api';
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
export default class VisualPerusahaan extends Component { export default class VisualPerusahaan extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
...@@ -40,7 +38,10 @@ export default class VisualPerusahaan extends Component { ...@@ -40,7 +38,10 @@ export default class VisualPerusahaan extends Component {
}, },
], ],
arrayCollapse: [], arrayCollapse: [],
defaultCollapsed: false defaultCollapsed: false,
alert: false,
tipeAlert: '',
messageAlert: '',
} }
} }
...@@ -50,9 +51,16 @@ export default class VisualPerusahaan extends Component { ...@@ -50,9 +51,16 @@ export default class VisualPerusahaan extends Component {
getPerusahaan() { getPerusahaan() {
api.create().getPerusahaanHierarki().then((response) => { api.create().getPerusahaanHierarki().then((response) => {
if (response.data.status == 'success') { console.log(response)
this.setState({ items: response.data.data }) if (response.data) {
console.log(response.data.data) if (response.data.status == 'success') {
this.setState({ items: response.data.data })
console.log(response.data.data)
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
}) })
} }
...@@ -98,6 +106,9 @@ export default class VisualPerusahaan extends Component { ...@@ -98,6 +106,9 @@ export default class VisualPerusahaan extends Component {
) )
}; };
closeAlert() {
this.setState({ alert: false })
}
render() { render() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment