Commit 865f91e5 authored by Rifka Kurnia Irfiana's avatar Rifka Kurnia Irfiana

update create dan edit AM

parent 586128e4
...@@ -51,9 +51,11 @@ export default class CreateApprovalMatrix extends Component { ...@@ -51,9 +51,11 @@ export default class CreateApprovalMatrix extends Component {
super(props) super(props)
this.state = { this.state = {
userId: null, userId: null,
typeId: null,
// type: '', // type: '',
order: '', order: '',
approvedBy: null, approvedBy: null,
types: null,
// operator: '', // operator: '',
startDate: '', startDate: '',
endDate: '', endDate: '',
...@@ -63,6 +65,7 @@ export default class CreateApprovalMatrix extends Component { ...@@ -63,6 +65,7 @@ export default class CreateApprovalMatrix extends Component {
componentDidMount() { componentDidMount() {
this.getUserData() this.getUserData()
this.getTypeData()
} }
getUserData() { getUserData() {
...@@ -87,6 +90,50 @@ export default class CreateApprovalMatrix extends Component { ...@@ -87,6 +90,50 @@ export default class CreateApprovalMatrix extends Component {
}) })
} }
getTypeData() {
api.create().getTypeAM().then((response) => {
if (response.data.status == 'success') {
let data = response.data.data
let typeData = data.map((item) => {
return {
approval_type_id: item.approval_type_id,
approval_type_name: item.approval_type_name
}
})
// console.log(userData)
let typeProps = {
options: typeData,
getOptionLabel: (option) => option.approval_type_name,
};
this.setState({ types: typeProps, typeData: response.data.data })
} else {
alert(response.data.message)
}
})
}
getOperatorData() {
api.create().getOperatorAM().then((response) => {
if (response.data.status == 'success') {
let data = response.data.data
let operatorData = data.map((item) => {
return {
approval_type_id: item.approval_type_id,
approval_type_name: item.approval_type_name
}
})
// console.log(userData)
let operatorProps = {
options: operatorData,
getOptionLabel: (option) => option.approval_type_name,
};
this.setState({ types: operatorProps, operatorData: response.data.data })
} else {
alert(response.data.message)
}
})
}
handleChange(e, type) { handleChange(e, type) {
let data = this.state let data = this.state
...@@ -155,32 +202,19 @@ export default class CreateApprovalMatrix extends Component { ...@@ -155,32 +202,19 @@ export default class CreateApprovalMatrix extends Component {
variant="filled" variant="filled"
label="ID" label="ID"
disabled disabled
// value={this.state.periode}
> >
{/* {periode.map((option) => (
<MenuItem key={option.value} value={option.value}>
{option.label}
</MenuItem>
))} */}
</TextField> </TextField>
</div> </div>
</div> </div>
<div className="column-2"> <div className="column-2">
<div className="margin-bottom-20px" style={{ marginTop: 8 }}> <div className="margin-bottom-20px" style={{ marginTop: 8 }}>
<TextField <Autocomplete
style={{ width: '100%' }} {...this.state.types}
id="type" id="tipe"
select onChange={(event, newInputValue) => this.setState({typeId:newInputValue.approval_type_id})}
label="Tipe Persetujuan" debug
value={this.state.type} renderInput={(params) => <TextField {...params} label="Tipe" margin="normal" />}
onChange={(e) => null} />
>
{type.map((option) => (
<MenuItem key={option.value} value={option.value}>
{option.label}
</MenuItem>
))}
</TextField>
</div> </div>
</div> </div>
</div> </div>
...@@ -202,7 +236,7 @@ export default class CreateApprovalMatrix extends Component { ...@@ -202,7 +236,7 @@ export default class CreateApprovalMatrix extends Component {
<Autocomplete <Autocomplete
{...this.state.approvedBy} {...this.state.approvedBy}
id="debug" id="debug"
onChange={(event, newInputValue) => this.setState({userId:newInputValue.user_id}, () => console.log(this.state.userId))} onChange={(event, newInputValue) => this.setState({userId:newInputValue.user_id})}
debug debug
renderInput={(params) => <TextField {...params} label="debug" margin="normal" />} renderInput={(params) => <TextField {...params} label="debug" margin="normal" />}
/> />
......
...@@ -4,6 +4,8 @@ import { DateTimePicker, KeyboardDatePicker, DatePicker} from "@material-ui/pick ...@@ -4,6 +4,8 @@ import { DateTimePicker, KeyboardDatePicker, DatePicker} from "@material-ui/pick
import MenuItem from '@material-ui/core/MenuItem'; import MenuItem from '@material-ui/core/MenuItem';
import format from "date-fns/format"; import format from "date-fns/format";
import localeID from "date-fns/locale/id" import localeID from "date-fns/locale/id"
import api from "../../api";
import Autocomplete from '@material-ui/lab/Autocomplete';
const type = [ const type = [
{ {
...@@ -49,20 +51,53 @@ export default class EditApprovalMatrix extends Component { ...@@ -49,20 +51,53 @@ export default class EditApprovalMatrix extends Component {
this.state = { this.state = {
startDate: null, startDate: null,
endDate: null, endDate: null,
date: new Date() date: new Date(),
approvedBy: null,
getApprovedBy: null
} }
} }
componentDidMount() { componentDidMount() {
if (this.props.type === 'edit') { if (this.props.type === 'edit') {
let data = this.props.data let data = this.props.data
// let getApprovedBy = {
// user_id: data.user_id,
// fullname: data.fullname
// }
this.setState({ this.setState({
id: data.business_unit_id, id: data.business_unit_id,
name: data.business_unit_name,
startDate: data.start_date, startDate: data.start_date,
endDate: data.end_date endDate: data.end_date,
getUserId: data.user_id,
}, () => this.getUserData())
}
console.log(this.props.data)
// this.getUserData()
}
getUserData() {
api.create().getApprovedByAM().then((response) => {
console.log(response)
if (response.data.status == 'success') {
let data = response.data.data
let userData = data.map((item) => {
return {
user_id: item.user_id,
fullname: item.fullname
}
}) })
let index = userData.findIndex((val) => val.user_id == this.state.getUserId)
// console.log(userData)
let defaultProps = {
options: userData,
getOptionLabel: (option) => option.fullname,
};
this.setState({ approvedBy: defaultProps, userData: response.data.data, getApprovedBy: index == -1 ? userData[0]: userData[index] })
} else {
alert(response.data.message)
} }
})
} }
handleChange(e, type) { handleChange(e, type) {
...@@ -82,6 +117,25 @@ export default class EditApprovalMatrix extends Component { ...@@ -82,6 +117,25 @@ export default class EditApprovalMatrix extends Component {
} }
validasi() {
// if (R.isEmpty(this.state.order)) return alert("Order is Required.");
// if (!R.isEmpty(this.state.startDate) && !R.isEmpty(this.state.endDate) && (this.state.startDate > this.state.endDate)) return alert("Masa Berlaku Tidak Boleh Kurang Dari Tanggal Mulai");
// if (R.isEmpty(this.state.startDate)) return alert("Tanggal Mulai is Required.");
// if (R.isEmpty(this.state.endDate)) return alert("Tanggal Berakhir is Required.");
console.log('masuk');
let payload = {
"approval_type_id": 2,
"orders": this.state.order,
"user_id": this.state.getApprovedBy.user_id,
"operator_type_id": 2,
"start_date": this.state.startDate,
"end_date": this.state.endDate
}
// this.props.createAM(payload)
console.log(payload)
}
handleDate(item) { handleDate(item) {
let value = format(item, 'dd MMMM yyyy') let value = format(item, 'dd MMMM yyyy')
return value return value
...@@ -189,31 +243,15 @@ export default class EditApprovalMatrix extends Component { ...@@ -189,31 +243,15 @@ export default class EditApprovalMatrix extends Component {
</div> </div>
<div className="column-2"> <div className="column-2">
<div className="margin-top-10px" style={{ paddingTop: 4, paddingRight: 10, paddingBottom: 10, paddingLeft: 10, borderRadius: 5 }}> <div className="margin-top-10px" style={{ paddingTop: 4, paddingRight: 10, paddingBottom: 10, paddingLeft: 10, borderRadius: 5 }}>
<TextField <Autocomplete
style={{ width: '100%' }} {...this.state.approvedBy}
id="approve-by" option
select id="debug"
label="Pemberi Persetujuan" onChange={(event, newInputValue) => this.setState({getApprovedBy: newInputValue})}
value={this.props.data.fullname} debug
onChange={(e) => null} renderInput={(params) => <TextField {...params} label="debug" margin="normal" />}
selectProps={{ value={this.state.getApprovedBy}
style: { />
fontSize: 11
}
}}
InputLabelProps={{
style: {
fontSize: 11,
color: '#7e8085'
}
}}
>
{approve_by.map((option) => (
<MenuItem key={option.value} value={option.value}>
{option.label}
</MenuItem>
))}
</TextField>
</div> </div>
</div> </div>
</div> </div>
...@@ -363,7 +401,7 @@ export default class EditApprovalMatrix extends Component { ...@@ -363,7 +401,7 @@ export default class EditApprovalMatrix extends Component {
</div> </div>
</div> </div>
<div className="column-2" style={{display: 'flex', justifyContent: 'flex-end', alignItems: 'center'}}> <div className="column-2" style={{display: 'flex', justifyContent: 'flex-end', alignItems: 'center'}}>
<div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center', cursor:"pointer" }}> <div onClick={() => this.validasi()} style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center', cursor:"pointer" }}>
<span style={{ color: '#fff', fontSize: 11 }}>Simpan</span> <span style={{ color: '#fff', fontSize: 11 }}>Simpan</span>
</div> </div>
</div> </div>
......
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