2019-06-17 12:45:23 +02:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
2019-07-07 03:45:07 +02:00
|
|
|
import { Container } from 'semantic-ui-react';
|
2019-06-17 12:45:23 +02:00
|
|
|
|
|
|
|
|
import MainMenu from '../../components/MainMenu';
|
2019-06-17 20:10:57 +02:00
|
|
|
import DateRangePicker from '../../components/DateRangePicker';
|
2019-07-07 03:45:07 +02:00
|
|
|
import MemberIncidentsTables from '../../components/MemberIncidentsTables';
|
2019-07-16 11:23:11 +02:00
|
|
|
import GenerateFeesInORDButton from '../../components/GenerateFeesInORDButton';
|
2019-06-17 20:10:57 +02:00
|
|
|
|
2019-07-18 03:44:16 +02:00
|
|
|
import { fetchIncidents, addFeesToOrd } from '../../store/actions';
|
2019-06-17 12:45:23 +02:00
|
|
|
|
|
|
|
|
class IncidentsReport extends Component {
|
2019-07-18 03:44:16 +02:00
|
|
|
state = {dateRange: null};
|
|
|
|
|
|
|
|
|
|
onDatesUpdate = (dateRange) => {
|
2019-06-17 12:45:23 +02:00
|
|
|
const { fetchIncidents } = this.props;
|
|
|
|
|
|
2019-07-18 03:44:16 +02:00
|
|
|
this.setState({dateRange});
|
|
|
|
|
fetchIncidents(dateRange);
|
|
|
|
|
};
|
2019-07-16 11:23:11 +02:00
|
|
|
|
2019-06-17 12:45:23 +02:00
|
|
|
render () {
|
|
|
|
|
const { pendingIncidents, incidents } = this.props;
|
2019-07-18 03:44:16 +02:00
|
|
|
const { dateRange } = this.state;
|
2019-06-17 12:45:23 +02:00
|
|
|
|
2019-07-25 02:00:27 +02:00
|
|
|
const membersMap = {};
|
|
|
|
|
if (incidents && Array.isArray(incidents)) {
|
|
|
|
|
incidents.forEach((incident) => {
|
|
|
|
|
membersMap[incident.memberId] = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const memberIds = Object.keys(membersMap) || [];
|
|
|
|
|
|
2019-06-17 12:45:23 +02:00
|
|
|
return (
|
|
|
|
|
<Container>
|
|
|
|
|
<MainMenu/>
|
|
|
|
|
<h3>Incidents Report</h3>
|
|
|
|
|
<hr/>
|
2019-07-18 03:44:16 +02:00
|
|
|
<DateRangePicker buttonLabel="Show report" onDatesUpdate={this.onDatesUpdate} inlineButton />
|
2019-07-16 11:23:11 +02:00
|
|
|
<br/>
|
|
|
|
|
<GenerateFeesInORDButton
|
2019-07-25 02:00:27 +02:00
|
|
|
memberIds={memberIds}
|
2019-07-16 11:23:11 +02:00
|
|
|
disabled={pendingIncidents}
|
2019-07-18 03:44:16 +02:00
|
|
|
dateRange={dateRange}
|
2019-07-16 11:23:11 +02:00
|
|
|
/>
|
|
|
|
|
<br/><br/>
|
|
|
|
|
<hr/>
|
2019-06-17 20:10:57 +02:00
|
|
|
<br/>
|
2019-07-07 03:45:07 +02:00
|
|
|
<MemberIncidentsTables pendingIncidents={pendingIncidents} incidents={incidents} />
|
2019-06-17 12:45:23 +02:00
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
|
pendingIncidents: state.incidentsReport.pending,
|
|
|
|
|
incidents: state.incidentsReport.result,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2019-06-18 10:14:11 +02:00
|
|
|
fetchIncidents: (dateRange) => fetchIncidents(dispatch, dateRange),
|
2019-07-18 03:44:16 +02:00
|
|
|
addFeesToOrd: (dateRange, memberIds) => addFeesToOrd(dispatch, dateRange, memberIds),
|
2019-06-17 12:45:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(IncidentsReport);
|