Commit b62e1c5d authored by Rifka Kurnia Irfiana's avatar Rifka Kurnia Irfiana

upsate validasi

parent 34a1f518
...@@ -518,7 +518,7 @@ export default class ApprovalMatrix extends Component { ...@@ -518,7 +518,7 @@ export default class ApprovalMatrix extends Component {
}} }}
onClick={() => this.downloadFile()} onClick={() => this.downloadFile()}
> >
<img src={Images.template} /> <img src={Images.template} title="Download Template"/>
</button> </button>
<button <button
style={{ style={{
...@@ -531,7 +531,7 @@ export default class ApprovalMatrix extends Component { ...@@ -531,7 +531,7 @@ export default class ApprovalMatrix extends Component {
}} }}
onClick={() => this.setState({ visibleUpload: true })} onClick={() => this.setState({ visibleUpload: true })}
> >
<img src={Images.upload} /> <img src={Images.upload} title="Upload File"/>
</button> </button>
<button <button
style={{ style={{
...@@ -544,7 +544,7 @@ export default class ApprovalMatrix extends Component { ...@@ -544,7 +544,7 @@ export default class ApprovalMatrix extends Component {
}} }}
onClick={() => this.downloadDataTable()} onClick={() => this.downloadDataTable()}
> >
<img src={Images.download} /> <img src={Images.download} title="Download File"/>
</button> </button>
<button <button
style={{ style={{
...@@ -557,7 +557,7 @@ export default class ApprovalMatrix extends Component { ...@@ -557,7 +557,7 @@ export default class ApprovalMatrix extends Component {
}} }}
onClick={() => this.setState({ visibleVisual: true, visibleAM: false })} onClick={() => this.setState({ visibleVisual: true, visibleAM: false })}
> >
<img src={Images.visualisasi} /> <img src={Images.visualisasi} title="Visualisasi"/>
</button> </button>
<button <button
style={{ style={{
...@@ -570,7 +570,7 @@ export default class ApprovalMatrix extends Component { ...@@ -570,7 +570,7 @@ export default class ApprovalMatrix extends Component {
}} }}
onClick={() => this.setState({ visibleCreate: true })} onClick={() => this.setState({ visibleCreate: true })}
> >
<img src={Images.add} /> <img src={Images.add} title="Tambah Approval Matrix"/>
</button> </button>
</div > </div >
</div> </div>
......
...@@ -26,6 +26,12 @@ export default class CreateApprovalMatrix extends Component { ...@@ -26,6 +26,12 @@ export default class CreateApprovalMatrix extends Component {
date: new Date(), date: new Date(),
errorOrder: false, errorOrder: false,
msgErrOrder: '', msgErrOrder: '',
errorType: false,
msgErrType: '',
errorStartDate: false,
errorEndDate: false,
msgErrorStartDate: "",
msgErrorEndDate: ""
} }
} }
...@@ -108,51 +114,61 @@ export default class CreateApprovalMatrix extends Component { ...@@ -108,51 +114,61 @@ export default class CreateApprovalMatrix extends Component {
let data = this.state let data = this.state
let isDate = type !== '' ? true : false let isDate = type !== '' ? true : false
if (isDate && type == 'start_date') { if (isDate && type == 'start_date') {
this.setState({ startDate: format(e, 'yyyy-MM-dd'), this.setState({ startDate: format(e, 'yyyy-MM-dd'), endDate: null }, () => {
errorOrder: false, this.clearError()
msgErrOrder: '', console.log(this.state.startDate)
// }, () => {
// console.log(this.state.startDate)
}) })
} else if (isDate && type == 'end_date') { } else if (isDate && type == 'end_date') {
this.setState({ endDate: format(e, 'yyyy-MM-dd'), this.setState({ endDate: format(e, 'yyyy-MM-dd')}, () => {
errorOrder: false, this.clearError()
msgErrOrder: '', console.log(this.state.endDate)
// }, () => {
// console.log(this.state.endDate)
}) })
} else { } else {
// this.setState({...data, tempData: {...this.state.tempData, [e.target.name] : e.target.value}}) // this.setState({...data, tempData: {...this.state.tempData, [e.target.name] : e.target.value}})
this.setState({
errorOrder: false,
msgErrOrder: '',
})
} }
} }
clearError() {
this.setState({
errorOrder: false,
msgErrOrder: "",
errorType: false,
msgErrType: '',
errorStartDate: false,
errorEndDate: false,
msgErrorStartDate: "",
msgErrorEndDate: ""
})
}
validasi() { validasi() {
if (R.isNil(this.state.typeId)) return alert("Tipe Persetujuan is Required."); if (R.isNil(this.state.typeId)) {
if (R.isEmpty(this.state.order)) { return alert("Tipe Persetujuan tidak boleh kosong");
this.setState({ errorOrder: true, msgErrOrder: 'Order is Required.'})
} }
if (R.isNil(this.state.userId)) return alert("Pemberi Persetujuan is Required."); else if (R.isEmpty(this.state.order)) {
if (R.isNil(this.state.operatorId)) return alert("Operator is Required."); this.setState({ errorOrder: true, msgErrOrder: 'Order tidak boleh kosong'})
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."); else if (R.isNil(this.state.userId)) return alert("Pemberi Persetujuan tidak boleh kosong");
if (R.isEmpty(this.state.endDate)) return alert("Tanggal Berakhir is Required."); else if (R.isNil(this.state.operatorId)) return alert("Operator tidak boleh kosong");
console.log('masuk'); else 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");
let payload = { else if (R.isEmpty(this.state.startDate)) {
"approval_type_id": this.state.typeId.approval_type_id, this.setState({ errorStartDate: true, msgErrorStartDate: 'Tanggal Mulai tidak boleh kosong' })
"orders": this.state.order, } else if (R.isEmpty(this.state.endDate)) {
"user_id": this.state.userId.user_id, this.setState({ errorEndDate: true, msgErrorEndDate: 'Tanggal Berakhir tidak boleh kosong' })
"operator_type_id": this.state.operatorId.operator_type_id, } else {
"start_date": this.state.startDate, console.log('masuk');
"end_date": this.state.endDate let payload = {
"approval_type_id": this.state.typeId.approval_type_id,
"orders": this.state.order,
"user_id": this.state.userId.user_id,
"operator_type_id": this.state.operatorId.operator_type_id,
"start_date": this.state.startDate,
"end_date": this.state.endDate
}
this.props.createAM(payload)
// console.log(payload)
} }
this.props.createAM(payload)
// console.log(payload)
} }
render() { render() {
...@@ -206,7 +222,6 @@ export default class CreateApprovalMatrix extends Component { ...@@ -206,7 +222,6 @@ export default class CreateApprovalMatrix extends Component {
{...this.state.types} {...this.state.types}
id="tipe" id="tipe"
onChange={(event, newInputValue) => this.setState({typeId:newInputValue})} onChange={(event, newInputValue) => this.setState({typeId:newInputValue})}
// disableClearable
debug debug
renderInput={(params) => renderInput={(params) =>
<TextField <TextField
...@@ -222,6 +237,8 @@ export default class CreateApprovalMatrix extends Component { ...@@ -222,6 +237,8 @@ export default class CreateApprovalMatrix extends Component {
/> />
} }
value={this.state.typeId} value={this.state.typeId}
error={this.state.errorType}
helperText={this.state.msgErrType}
// inputProps={{ // inputProps={{
// style: { // style: {
// fontSize: 11 // fontSize: 11
...@@ -241,7 +258,7 @@ export default class CreateApprovalMatrix extends Component { ...@@ -241,7 +258,7 @@ export default class CreateApprovalMatrix extends Component {
value={this.state.order} value={this.state.order}
error={this.state.errorOrder} error={this.state.errorOrder}
helperText={this.state.msgErrOrder} helperText={this.state.msgErrOrder}
onChange={(e) => this.setState({ order: e.target.value })} onChange={(e) => this.setState({ order: e.target.value }, () => this.clearError())}
inputProps={{ inputProps={{
style: { style: {
fontSize: 11 fontSize: 11
...@@ -345,6 +362,8 @@ export default class CreateApprovalMatrix extends Component { ...@@ -345,6 +362,8 @@ export default class CreateApprovalMatrix extends Component {
color: '#7e8085' color: '#7e8085'
} }
}} }}
error={this.state.errorStartDate}
helperText={this.state.msgErrorStartDate}
style={{ padding: 0, margin: 0, width: '100%' }} style={{ padding: 0, margin: 0, width: '100%' }}
/> />
</div> </div>
...@@ -357,7 +376,10 @@ export default class CreateApprovalMatrix extends Component { ...@@ -357,7 +376,10 @@ export default class CreateApprovalMatrix extends Component {
label="Berlaku Hingga" label="Berlaku Hingga"
format="dd MMMM yyyy" format="dd MMMM yyyy"
value={this.state.endDate == "" ? null : this.state.endDate} value={this.state.endDate == "" ? null : this.state.endDate}
error={this.state.errorEndDate}
helperText={this.state.msgErrorEndDate}
onChange={(e) => this.handleChange(e, 'end_date')} onChange={(e) => this.handleChange(e, 'end_date')}
minDate={this.state.startDate}
KeyboardButtonProps={{ KeyboardButtonProps={{
'aria-label': 'change date', 'aria-label': 'change date',
}} }}
......
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