Discounts support / make rates configurable
This commit is contained in:
@@ -1,22 +1,92 @@
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Container, Button, Loader } from 'semantic-ui-react';
|
||||
import { Container, Button, Loader, Input, Message, Grid } from 'semantic-ui-react';
|
||||
|
||||
import MainMenu from '../../components/MainMenu';
|
||||
|
||||
import { fetchMemberPracticeSummaryReport } from '../../store/actions';
|
||||
|
||||
class MemberPracticeSummaryReport extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
year: new Date().getFullYear(),
|
||||
stateError: null,
|
||||
}
|
||||
}
|
||||
|
||||
onGenerateReportClick = () => {
|
||||
const {fetchMemberPracticeSummaryReport} = this.props;
|
||||
const { year } = this.state;
|
||||
|
||||
const currentYear = new Date().getFullYear();
|
||||
const parsedYear = parseInt(year);
|
||||
|
||||
if (!parsedYear || isNaN(parsedYear)){
|
||||
this.setState({stateError: 'Year is not a number'});
|
||||
return;
|
||||
}
|
||||
|
||||
if (parsedYear > currentYear){
|
||||
this.setState({stateError: 'Selected year cannot be greater than current year'});
|
||||
return;
|
||||
}
|
||||
|
||||
fetchMemberPracticeSummaryReport(year);
|
||||
};
|
||||
|
||||
onYearInputChange = (event, data) => {
|
||||
let newYear = parseInt(data.value)
|
||||
if (!newYear || isNaN(newYear)){
|
||||
newYear = new Date().getFullYear();
|
||||
}
|
||||
this.setState({year: newYear, stateError: null})
|
||||
};
|
||||
|
||||
render () {
|
||||
const { fetchMemberPracticeSummaryReport, pendingReport } = this.props;
|
||||
const { pendingReport, fetchReportError } = this.props;
|
||||
const { year, stateError } = this.state;
|
||||
|
||||
let error;
|
||||
error = stateError ? stateError : null;
|
||||
error = fetchReportError ? fetchReportError : error;
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<MainMenu/>
|
||||
<h3>Member Practice Summary Report</h3>
|
||||
<hr/>
|
||||
<br/>
|
||||
<Grid stackable>
|
||||
<Grid.Row>
|
||||
<Grid.Column width={5}>
|
||||
<Input
|
||||
fluid
|
||||
type="number"
|
||||
label={'Report for : '}
|
||||
value={year}
|
||||
onChange={this.onYearInputChange}
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={5}>
|
||||
<Button disabled={pendingReport} onClick={this.onGenerateReportClick}>Generate Report</Button>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
{error &&
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Message negative>
|
||||
<Message.Header>Error</Message.Header>
|
||||
<br/>
|
||||
<Message.Content><p>{error}</p></Message.Content>
|
||||
</Message>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
}
|
||||
</Grid>
|
||||
<Loader active={pendingReport} />
|
||||
<Button disabled={pendingReport} onClick={fetchMemberPracticeSummaryReport}>Generate Report</Button>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@@ -24,10 +94,11 @@ class MemberPracticeSummaryReport extends Component {
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
pendingReport: state.memberPracticeSummaryReport.pending,
|
||||
fetchReportError: state.memberPracticeSummaryReport.error,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
fetchMemberPracticeSummaryReport: () => fetchMemberPracticeSummaryReport(dispatch),
|
||||
fetchMemberPracticeSummaryReport: (year) => fetchMemberPracticeSummaryReport(dispatch, year),
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(MemberPracticeSummaryReport);
|
||||
|
||||
@@ -113,15 +113,24 @@ export const checkProcessing = (dispatch) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchMemberPracticeSummaryReport = (dispatch) => {
|
||||
export const fetchMemberPracticeSummaryReport = (dispatch, year) => {
|
||||
dispatch({type: FETCH_MEMBER_PRACTICE_SUMMARY_REPORT_PENDING});
|
||||
API.get('integration/report/practiceSummary', {
|
||||
API.get(`integration/report/practiceSummary/${year}`, {
|
||||
responseType: 'blob',
|
||||
})
|
||||
.then(response => {
|
||||
dispatch({type: FETCH_MEMBER_PRACTICE_SUMMARY_REPORT_SUCCESS, payload: response});
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch({type: FETCH_MEMBER_PRACTICE_SUMMARY_REPORT_FAILED, payload: error.response});
|
||||
let errorMessage = 'Error generating Member Practice Summary Report';
|
||||
switch (error.response.status) {
|
||||
case 400:
|
||||
errorMessage = 'Year cannot be greater than current year and it has to be a number';
|
||||
break;
|
||||
case 500:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
dispatch({type: FETCH_MEMBER_PRACTICE_SUMMARY_REPORT_FAILED, payload: errorMessage});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user