send request to add fees in ORD

This commit is contained in:
Bilal Catic
2019-07-18 03:44:16 +02:00
parent fdd4491e07
commit 7437972a53
5 changed files with 50 additions and 17 deletions

View File

@@ -1,17 +1,22 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Button, Modal } from 'semantic-ui-react';
import { addFeesToOrd } from '../../store/actions';
class GenerateFeesInORDButton extends Component {
state = { open: false };
show = size => () => this.setState({ size, open: true });
close = () => this.setState({ open: false });
confirm = () => {
const { onConfirm } = this.props;
this.close();
if (onConfirm){
onConfirm();
const { addFeesToOrd, dateRange, memberIds } = this.props;
if (dateRange){
addFeesToOrd(dateRange, memberIds);
}
this.close();
};
render() {
@@ -41,4 +46,8 @@ class GenerateFeesInORDButton extends Component {
}
}
export default GenerateFeesInORDButton;
const mapDispatchToProps = (dispatch) => ({
addFeesToOrd: (dateRange, memberIds) => addFeesToOrd(dispatch, dateRange, memberIds),
});
export default connect(null, mapDispatchToProps)(GenerateFeesInORDButton);

View File

@@ -7,29 +7,32 @@ import DateRangePicker from '../../components/DateRangePicker';
import MemberIncidentsTables from '../../components/MemberIncidentsTables';
import GenerateFeesInORDButton from '../../components/GenerateFeesInORDButton';
import { fetchIncidents } from '../../store/actions';
import { fetchIncidents, addFeesToOrd } from '../../store/actions';
class IncidentsReport extends Component {
onDatesUpdate(dateRange) {
const { fetchIncidents } = this.props;
fetchIncidents(dateRange);
}
state = {dateRange: null};
onAddFeesClick = () => {};
onDatesUpdate = (dateRange) => {
const { fetchIncidents } = this.props;
this.setState({dateRange});
fetchIncidents(dateRange);
};
render () {
const { pendingIncidents, incidents } = this.props;
const { dateRange } = this.state;
return (
<Container>
<MainMenu/>
<h3>Incidents Report</h3>
<hr/>
<DateRangePicker buttonLabel="Show report" onDatesUpdate={this.onDatesUpdate.bind(this)} inlineButton />
<DateRangePicker buttonLabel="Show report" onDatesUpdate={this.onDatesUpdate} inlineButton />
<br/>
<GenerateFeesInORDButton
disabled={pendingIncidents}
onConfirm={this.onAddFeesClick}
dateRange={dateRange}
/>
<br/><br/>
<hr/>
@@ -47,6 +50,7 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = (dispatch) => ({
fetchIncidents: (dateRange) => fetchIncidents(dispatch, dateRange),
addFeesToOrd: (dateRange, memberIds) => addFeesToOrd(dispatch, dateRange, memberIds),
});
export default connect(mapStateToProps, mapDispatchToProps)(IncidentsReport);

View File

@@ -9,7 +9,7 @@ import MemberSummary from './components/MemberSummary';
import MemberIncidentsTables from '../../components/MemberIncidentsTables';
import GenerateFeesInORDButton from '../../components/GenerateFeesInORDButton';
import { fetchMemberIncidents } from '../../store/actions';
import { fetchMemberIncidents, addFeesToOrd } from '../../store/actions';
class PracticeSummaryReport extends Component {
constructor(props){
@@ -39,8 +39,6 @@ class PracticeSummaryReport extends Component {
}
}
onAddFeesClick = () => {};
render () {
const { memberIncidents, loading } = this.props;
const { memberId, dateRange } = this.state;
@@ -74,7 +72,8 @@ class PracticeSummaryReport extends Component {
<GenerateFeesInORDButton
singleMember
disabled={addFeesButtonDisabled}
onConfirm={this.onAddFeesClick}
dateRange={dateRange}
memberIds={[memberId]}
/>
</Grid.Column>
</Grid.Row>

View File

@@ -14,6 +14,9 @@ import {
FETCH_MEMBER_INCIDENTS_PENDING,
FETCH_MEMBER_INCIDENTS_SUCCESS,
FETCH_MEMBER_INCIDENTS_FAILED,
ADD_FEES_TO_ORD_PENDING,
ADD_FEES_TO_ORD_SUCCESS,
ADD_FEES_TO_ORD_FAILED,
} from '../constants';
import API from '../../utilities/api';
@@ -78,3 +81,17 @@ export const fetchMemberIncidents = (dispatch, memberId, dateRange) => {
dispatch({type: FETCH_MEMBER_INCIDENTS_FAILED, payload: error.response});
});
};
export const addFeesToOrd = (dispatch, dateRange, memberIds) => {
dispatch({type: ADD_FEES_TO_ORD_PENDING});
API.post(`integration/addFees`, {
dateRange,
memberIds: memberIds || [],
})
.then(response => {
dispatch({type: ADD_FEES_TO_ORD_SUCCESS, payload: response.data});
})
.catch(error => {
dispatch({type: ADD_FEES_TO_ORD_FAILED, payload: error.response});
});
};

View File

@@ -21,3 +21,7 @@ export const FETCH_MEMBERS_FAILED = 'FETCH_MEMBERS_FAILED';
export const FETCH_MEMBER_INCIDENTS_PENDING = 'FETCH_MEMBER_INCIDENTS_PENDING';
export const FETCH_MEMBER_INCIDENTS_SUCCESS = 'FETCH_MEMBER_INCIDENTS_SUCCESS';
export const FETCH_MEMBER_INCIDENTS_FAILED = 'FETCH_MEMBER_INCIDENTS_FAILED';
export const ADD_FEES_TO_ORD_PENDING = 'ADD_FEES_TO_ORD_PENDING';
export const ADD_FEES_TO_ORD_SUCCESS = 'ADD_FEES_TO_ORD_SUCCESS';
export const ADD_FEES_TO_ORD_FAILED = 'ADD_FEES_TO_ORD_FAILED';