From 7437972a53b375baba7a7525a742d642d7eef5b9 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 18 Jul 2019 03:44:16 +0200 Subject: [PATCH] send request to add fees in ORD --- .../GenerateFeesInORDButton/index.js | 19 +++++++++++++----- client/src/scenes/IncidentsReport/index.js | 20 +++++++++++-------- .../src/scenes/PracticeSummaryReport/index.js | 7 +++---- .../src/store/actions/integrationActions.js | 17 ++++++++++++++++ client/src/store/constants.js | 4 ++++ 5 files changed, 50 insertions(+), 17 deletions(-) diff --git a/client/src/components/GenerateFeesInORDButton/index.js b/client/src/components/GenerateFeesInORDButton/index.js index 9fae85c..43e6d0f 100644 --- a/client/src/components/GenerateFeesInORDButton/index.js +++ b/client/src/components/GenerateFeesInORDButton/index.js @@ -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); diff --git a/client/src/scenes/IncidentsReport/index.js b/client/src/scenes/IncidentsReport/index.js index 0ce667c..0dc98fc 100644 --- a/client/src/scenes/IncidentsReport/index.js +++ b/client/src/scenes/IncidentsReport/index.js @@ -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 (

Incidents Report


- +



@@ -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); diff --git a/client/src/scenes/PracticeSummaryReport/index.js b/client/src/scenes/PracticeSummaryReport/index.js index 379934b..a3d6488 100644 --- a/client/src/scenes/PracticeSummaryReport/index.js +++ b/client/src/scenes/PracticeSummaryReport/index.js @@ -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 { diff --git a/client/src/store/actions/integrationActions.js b/client/src/store/actions/integrationActions.js index 5e9a127..79a9068 100644 --- a/client/src/store/actions/integrationActions.js +++ b/client/src/store/actions/integrationActions.js @@ -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}); + }); +}; diff --git a/client/src/store/constants.js b/client/src/store/constants.js index 6dd4fd8..6d67aef 100644 --- a/client/src/store/constants.js +++ b/client/src/store/constants.js @@ -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';