Commit 61329c10 authored by EKSAD's avatar EKSAD

create item report

parent 5e620906
import React, { Component } from 'react'; import React, { Component } from 'react';
import { TextField, Typography } from '@material-ui/core'; import { TextField, Typography, Snackbar, withStyles } from '@material-ui/core';
import * as R from 'ramda'; import * as R from 'ramda';
import api from '../../../api'; import api from '../../../api';
import Autocomplete from '@material-ui/lab/Autocomplete'; import Autocomplete from '@material-ui/lab/Autocomplete';
...@@ -7,6 +7,9 @@ import { titleCase } from '../../../library/Utils'; ...@@ -7,6 +7,9 @@ import { titleCase } from '../../../library/Utils';
import format from "date-fns/format"; import format from "date-fns/format";
import { DatePicker } from '@material-ui/pickers'; import { DatePicker } from '@material-ui/pickers';
import Images from '../../../assets/Images'; import Images from '../../../assets/Images';
import MuiAlert from '@material-ui/lab/Alert';
const Alert = withStyles({
})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
export default class CreateReportItems extends Component { export default class CreateReportItems extends Component {
constructor(props) { constructor(props) {
...@@ -53,7 +56,10 @@ export default class CreateReportItems extends Component { ...@@ -53,7 +56,10 @@ export default class CreateReportItems extends Component {
disabledFormula: true, disabledFormula: true,
disabledCondt: true, disabledCondt: true,
disabledValue: true, disabledValue: true,
options: ['WARNING', 'STOPPER'] options: ['WARNING', 'STOPPER'],
alert: false,
tipeAlert: '',
messageAlert: ''
} }
} }
...@@ -196,22 +202,28 @@ export default class CreateReportItems extends Component { ...@@ -196,22 +202,28 @@ export default class CreateReportItems extends Component {
getInputType() { getInputType() {
api.create().getInputType().then((response) => { api.create().getInputType().then((response) => {
console.log(response.data) // console.log(response.data)
if (response.data.status === 'success') { if(response.data) {
let data = response.data.data
let inputData = data.map((item) => { if (response.data.status === 'success') {
return { let data = response.data.data
type_report_id: item.type_report_id, let inputData = data.map((item) => {
type_report_name: item.type_report_name return {
} type_report_id: item.type_report_id,
}) type_report_name: item.type_report_name
let defaultProps = { }
options: inputData, })
getOptionLabel: (option) => titleCase(option.type_report_name), let defaultProps = {
}; options: inputData,
this.setState({ listInputType: defaultProps, inputData: response.data.data }) getOptionLabel: (option) => titleCase(option.type_report_name),
};
this.setState({ listInputType: defaultProps, inputData: response.data.data })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
// alert(response.data.message)
}
} else { } else {
alert(response.data.message) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
}) })
} }
...@@ -219,21 +231,26 @@ export default class CreateReportItems extends Component { ...@@ -219,21 +231,26 @@ export default class CreateReportItems extends Component {
getPerusahaan() { getPerusahaan() {
api.create().getPerusahaanActive().then((response) => { api.create().getPerusahaanActive().then((response) => {
// console.log(response) // console.log(response)
if (response.data.status === 'success') { if (response.data) {
let data = response.data.data if (response.data.status === 'success') {
let companyData = data.map((item) => { let data = response.data.data
return { let companyData = data.map((item) => {
company_id: item.company_id, return {
company_name: item.company_name company_id: item.company_id,
} company_name: item.company_name
}) }
let defaultProps = { })
options: companyData, let defaultProps = {
getOptionLabel: (option) => titleCase(option.company_name), options: companyData,
}; getOptionLabel: (option) => titleCase(option.company_name),
this.setState({ listCompany: defaultProps, companyData: response.data.data }) };
this.setState({ listCompany: defaultProps, companyData: response.data.data })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
// alert(response.data.message)
}
} else { } else {
alert(response.data.message) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
}) })
} }
...@@ -241,21 +258,26 @@ export default class CreateReportItems extends Component { ...@@ -241,21 +258,26 @@ export default class CreateReportItems extends Component {
getReportType() { getReportType() {
api.create().getReportType().then((response) => { api.create().getReportType().then((response) => {
// console.log(response) // console.log(response)
if (response.data.status === 'success') { if (response.data) {
let data = response.data.data if (response.data.status === 'success') {
let reportTypeData = data.map((item) => { let data = response.data.data
return { let reportTypeData = data.map((item) => {
report_id: item.report_id, return {
report_name: item.report_name, report_id: item.report_id,
} report_name: item.report_name,
}) }
let defaultProps = { })
options: reportTypeData, let defaultProps = {
getOptionLabel: (option) => titleCase(option.report_name), options: reportTypeData,
}; getOptionLabel: (option) => titleCase(option.report_name),
this.setState({ listReportType: defaultProps, reportTypeData: response.data.data }) };
this.setState({ listReportType: defaultProps, reportTypeData: response.data.data })
} else {
// alert(response.data.message)
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' })
} }
}) })
} }
...@@ -267,22 +289,28 @@ export default class CreateReportItems extends Component { ...@@ -267,22 +289,28 @@ export default class CreateReportItems extends Component {
"company_id": this.state.company.company_id "company_id": this.state.company.company_id
} }
api.create().getReportParent(payload).then((response) => { api.create().getReportParent(payload).then((response) => {
console.log(response) // console.log(response)
if (response.data.status === 'success') { if (response.data) {
let data = response.data.data
let parentData = data.map((item) => { if (response.data.status === 'success') {
return { let data = response.data.data
item_report_id: item.item_report_id, let parentData = data.map((item) => {
description: item.description return {
} item_report_id: item.item_report_id,
}) description: item.description
let defaultProps = { }
options: parentData, })
getOptionLabel: (option) => titleCase(option.description), let defaultProps = {
}; options: parentData,
this.setState({ listParent: defaultProps, parentData: response.data.data }) getOptionLabel: (option) => titleCase(option.description),
};
this.setState({ listParent: defaultProps, parentData: response.data.data })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' })
// alert(response.data.message)
}
} else { } else {
alert(response.data.message) this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
} }
}) })
} }
...@@ -327,6 +355,11 @@ export default class CreateReportItems extends Component { ...@@ -327,6 +355,11 @@ export default class CreateReportItems extends Component {
</button> </button>
</div> </div>
</div> </div>
<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="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}> <div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20 }}>
<div className="column-1"> <div className="column-1">
......
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