2019-06-17 12:45:23 +02:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
2019-07-07 02:44:34 +02:00
|
|
|
import { Container, Accordion, Label } 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-06-18 15:27:18 +02:00
|
|
|
import MemberIncidentsTable from '../../components/MemberIncidentsTable';
|
2019-06-17 20:10:57 +02:00
|
|
|
|
2019-06-17 12:45:23 +02:00
|
|
|
import { fetchIncidents } from '../../store/actions';
|
|
|
|
|
|
2019-07-07 02:44:34 +02:00
|
|
|
import {
|
|
|
|
|
UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
|
|
|
|
|
UNLOCKED_INCIDENT_STANDALONE, UNSCHEDULED_INCIDENT_AFTER_RESERVATION,
|
|
|
|
|
UNSCHEDULED_INCIDENT_BEFORE_RESERVATION,
|
|
|
|
|
UNSCHEDULED_INCIDENT_STANDALONE
|
|
|
|
|
} from '../../constants/enums';
|
|
|
|
|
|
2019-06-17 12:45:23 +02:00
|
|
|
class IncidentsReport extends Component {
|
2019-06-17 20:10:57 +02:00
|
|
|
onDatesUpdate(dateRange) {
|
2019-06-17 12:45:23 +02:00
|
|
|
const { fetchIncidents } = this.props;
|
2019-06-17 20:10:57 +02:00
|
|
|
fetchIncidents(dateRange);
|
2019-06-17 12:45:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
|
const { pendingIncidents, incidents } = this.props;
|
|
|
|
|
|
2019-07-07 02:44:34 +02:00
|
|
|
const incidentsRelatedToReservations = [];
|
|
|
|
|
const standaloneIncidents = [];
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(incidents)){
|
|
|
|
|
incidents.forEach((incident) => {
|
|
|
|
|
if (incident && incident.incidentType){
|
|
|
|
|
switch (incident.incidentType) {
|
|
|
|
|
case UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
|
|
|
|
case UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
|
|
|
|
case UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
|
|
|
|
incidentsRelatedToReservations.push(incident);
|
|
|
|
|
break;
|
|
|
|
|
case UNLOCKED_INCIDENT_STANDALONE:
|
|
|
|
|
case UNSCHEDULED_INCIDENT_STANDALONE:
|
|
|
|
|
standaloneIncidents.push(incident);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const incidentsRelatedToReservationsTable = (
|
|
|
|
|
<MemberIncidentsTable
|
|
|
|
|
loading={pendingIncidents}
|
|
|
|
|
incidents={incidentsRelatedToReservations}
|
|
|
|
|
openMemberSummaryOnMemberClick
|
|
|
|
|
showBookingTimes
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const standaloneIncidentsTable = (
|
|
|
|
|
<MemberIncidentsTable
|
|
|
|
|
loading={pendingIncidents}
|
|
|
|
|
incidents={standaloneIncidents}
|
|
|
|
|
openMemberSummaryOnMemberClick
|
|
|
|
|
showDoorLockEntryTimes
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const accordionPanels = [
|
|
|
|
|
{
|
|
|
|
|
key: 'related-door-lock-incidents',
|
|
|
|
|
title : { content: <Label color='blue' content={'Door Lock Charges - Related to reservations'} /> },
|
|
|
|
|
content: { content : incidentsRelatedToReservationsTable },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'standalone-door-lock-incidents',
|
|
|
|
|
title : { content: <Label color='blue' content={'Door Lock Charges - Standalone'} /> },
|
|
|
|
|
content: { content: standaloneIncidentsTable },
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'reservation-modification-incidents',
|
|
|
|
|
title: {content: <Label color='blue' content={'Cancellation charges'}/>},
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2019-06-17 12:45:23 +02:00
|
|
|
return (
|
|
|
|
|
<Container>
|
|
|
|
|
<MainMenu/>
|
|
|
|
|
<h3>Incidents Report</h3>
|
|
|
|
|
<hr/>
|
2019-06-17 20:10:57 +02:00
|
|
|
<DateRangePicker buttonLabel="Show report" onDatesUpdate={this.onDatesUpdate.bind(this)} />
|
|
|
|
|
<br/>
|
2019-07-07 02:44:34 +02:00
|
|
|
<Accordion
|
|
|
|
|
panels={accordionPanels}
|
|
|
|
|
exclusive={false}
|
|
|
|
|
defaultActiveIndex={[0]}
|
|
|
|
|
fluid
|
|
|
|
|
/>
|
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-06-17 12:45:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(IncidentsReport);
|