Display error message if sending fees fails
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { Button, Modal } from 'semantic-ui-react';
|
import { Button, Modal, Message } from 'semantic-ui-react';
|
||||||
import moment from 'moment';
|
|
||||||
|
|
||||||
import { addFeesToOrd } from '../../store/actions';
|
import { addFeesToOrd } from '../../store/actions';
|
||||||
import { defaultDateFormat } from '../../constants/constants';
|
|
||||||
|
|
||||||
class GenerateFeesInORDButton extends Component {
|
class GenerateFeesInORDButton extends Component {
|
||||||
state = { open: false };
|
state = { open: false };
|
||||||
@@ -23,25 +21,7 @@ class GenerateFeesInORDButton extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { open, size } = this.state;
|
const { open, size } = this.state;
|
||||||
const { singleMember, disabled, dateRange } = this.props;
|
const { singleMember, disabled, sendFeesError } = this.props;
|
||||||
|
|
||||||
let submitIsDisabled = disabled;
|
|
||||||
|
|
||||||
if (dateRange && dateRange.startDate) {
|
|
||||||
const startDateMoment = moment(dateRange.startDate, defaultDateFormat);
|
|
||||||
const currentMoment = moment();
|
|
||||||
|
|
||||||
const startMomentMonth = startDateMoment.month();
|
|
||||||
const startMomentYear = startDateMoment.year();
|
|
||||||
const currentMonth = currentMoment.month();
|
|
||||||
const currentYear = currentMoment.year();
|
|
||||||
|
|
||||||
const monthSelectorIsInPast = (startMomentYear < currentYear) ||
|
|
||||||
(startMomentYear === currentYear && startMomentMonth < currentMonth);
|
|
||||||
|
|
||||||
submitIsDisabled = disabled || !monthSelectorIsInPast;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const modalContent = singleMember ?
|
const modalContent = singleMember ?
|
||||||
'This will remove all existing fees in ORD for selected member in selected date range and generate new fees based on shown incident tables. Do you want to continue ?':
|
'This will remove all existing fees in ORD for selected member in selected date range and generate new fees based on shown incident tables. Do you want to continue ?':
|
||||||
@@ -49,7 +29,13 @@ class GenerateFeesInORDButton extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button disabled={submitIsDisabled} onClick={this.show('tiny')}>Generate fees in ORD</Button>
|
<Button disabled={disabled} onClick={this.show('tiny')}>Generate fees in ORD</Button>
|
||||||
|
|
||||||
|
{sendFeesError &&
|
||||||
|
<Message negative>
|
||||||
|
{sendFeesError.data ? sendFeesError.data : 'Error sending fees'}
|
||||||
|
</Message>
|
||||||
|
}
|
||||||
|
|
||||||
<Modal size={size} open={open} onClose={this.close}>
|
<Modal size={size} open={open} onClose={this.close}>
|
||||||
<Modal.Header>Add fees to the ORD</Modal.Header>
|
<Modal.Header>Add fees to the ORD</Modal.Header>
|
||||||
@@ -66,8 +52,12 @@ class GenerateFeesInORDButton extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
|
sendFeesError: state.addFeesStatus.error,
|
||||||
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
addFeesToOrd: (dateRange, memberIds) => addFeesToOrd(dispatch, dateRange, memberIds),
|
addFeesToOrd: (dateRange, memberIds) => addFeesToOrd(dispatch, dateRange, memberIds),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps)(GenerateFeesInORDButton);
|
export default connect(mapStateToProps, mapDispatchToProps)(GenerateFeesInORDButton);
|
||||||
|
|||||||
Reference in New Issue
Block a user