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 React, { Component } from 'react';
import { connect } from 'react-redux';
import { Button, Modal } from 'semantic-ui-react'; import { Button, Modal } from 'semantic-ui-react';
import { addFeesToOrd } from '../../store/actions';
class GenerateFeesInORDButton extends Component { class GenerateFeesInORDButton extends Component {
state = { open: false }; state = { open: false };
show = size => () => this.setState({ size, open: true }); show = size => () => this.setState({ size, open: true });
close = () => this.setState({ open: false }); close = () => this.setState({ open: false });
confirm = () => { confirm = () => {
const { onConfirm } = this.props; const { addFeesToOrd, dateRange, memberIds } = this.props;
this.close();
if (onConfirm){ if (dateRange){
onConfirm(); addFeesToOrd(dateRange, memberIds);
} }
this.close();
}; };
render() { 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 MemberIncidentsTables from '../../components/MemberIncidentsTables';
import GenerateFeesInORDButton from '../../components/GenerateFeesInORDButton'; import GenerateFeesInORDButton from '../../components/GenerateFeesInORDButton';
import { fetchIncidents } from '../../store/actions'; import { fetchIncidents, addFeesToOrd } from '../../store/actions';
class IncidentsReport extends Component { class IncidentsReport extends Component {
onDatesUpdate(dateRange) { state = {dateRange: null};
const { fetchIncidents } = this.props;
fetchIncidents(dateRange);
}
onAddFeesClick = () => {}; onDatesUpdate = (dateRange) => {
const { fetchIncidents } = this.props;
this.setState({dateRange});
fetchIncidents(dateRange);
};
render () { render () {
const { pendingIncidents, incidents } = this.props; const { pendingIncidents, incidents } = this.props;
const { dateRange } = this.state;
return ( return (
<Container> <Container>
<MainMenu/> <MainMenu/>
<h3>Incidents Report</h3> <h3>Incidents Report</h3>
<hr/> <hr/>
<DateRangePicker buttonLabel="Show report" onDatesUpdate={this.onDatesUpdate.bind(this)} inlineButton /> <DateRangePicker buttonLabel="Show report" onDatesUpdate={this.onDatesUpdate} inlineButton />
<br/> <br/>
<GenerateFeesInORDButton <GenerateFeesInORDButton
disabled={pendingIncidents} disabled={pendingIncidents}
onConfirm={this.onAddFeesClick} dateRange={dateRange}
/> />
<br/><br/> <br/><br/>
<hr/> <hr/>
@@ -47,6 +50,7 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({
fetchIncidents: (dateRange) => fetchIncidents(dispatch, dateRange), fetchIncidents: (dateRange) => fetchIncidents(dispatch, dateRange),
addFeesToOrd: (dateRange, memberIds) => addFeesToOrd(dispatch, dateRange, memberIds),
}); });
export default connect(mapStateToProps, mapDispatchToProps)(IncidentsReport); export default connect(mapStateToProps, mapDispatchToProps)(IncidentsReport);

View File

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

View File

@@ -14,6 +14,9 @@ import {
FETCH_MEMBER_INCIDENTS_PENDING, FETCH_MEMBER_INCIDENTS_PENDING,
FETCH_MEMBER_INCIDENTS_SUCCESS, FETCH_MEMBER_INCIDENTS_SUCCESS,
FETCH_MEMBER_INCIDENTS_FAILED, FETCH_MEMBER_INCIDENTS_FAILED,
ADD_FEES_TO_ORD_PENDING,
ADD_FEES_TO_ORD_SUCCESS,
ADD_FEES_TO_ORD_FAILED,
} from '../constants'; } from '../constants';
import API from '../../utilities/api'; import API from '../../utilities/api';
@@ -78,3 +81,17 @@ export const fetchMemberIncidents = (dispatch, memberId, dateRange) => {
dispatch({type: FETCH_MEMBER_INCIDENTS_FAILED, payload: error.response}); 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_PENDING = 'FETCH_MEMBER_INCIDENTS_PENDING';
export const FETCH_MEMBER_INCIDENTS_SUCCESS = 'FETCH_MEMBER_INCIDENTS_SUCCESS'; export const FETCH_MEMBER_INCIDENTS_SUCCESS = 'FETCH_MEMBER_INCIDENTS_SUCCESS';
export const FETCH_MEMBER_INCIDENTS_FAILED = 'FETCH_MEMBER_INCIDENTS_FAILED'; 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';