Merge branch 'allow-deleting-incident-fees' into 'master'
Allow deleting incident fees See merge request saburly/psihologija!66
This commit was merged in pull request #66.
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
import React from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Loader } from 'semantic-ui-react';
|
import { connect } from 'react-redux';
|
||||||
import ReactTable from 'react-table';
|
import { Loader, Button } from 'semantic-ui-react';
|
||||||
import 'react-table/react-table.css';
|
import 'react-table/react-table.css';
|
||||||
import { NavLink } from 'react-router-dom';
|
import { NavLink } from 'react-router-dom';
|
||||||
|
|
||||||
|
import SelectTable from "../../SelectTable";
|
||||||
|
|
||||||
import {incidentsReportHeaderTitles} from '../../../constants/constants';
|
import {incidentsReportHeaderTitles} from '../../../constants/constants';
|
||||||
import {
|
import {
|
||||||
incidentTableTypes,
|
incidentTableTypes,
|
||||||
@@ -13,155 +15,244 @@ import {
|
|||||||
UNSCHEDULED_INCIDENT_BEFORE_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE
|
UNSCHEDULED_INCIDENT_BEFORE_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE
|
||||||
} from '../../../constants/enums';
|
} from '../../../constants/enums';
|
||||||
import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants';
|
import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants';
|
||||||
|
import { deleteIncidents } from "../../../store/actions";
|
||||||
|
|
||||||
|
class SingleIncidentsTable extends Component {
|
||||||
|
state = {
|
||||||
|
selectedUnlockedIncidentIds: [],
|
||||||
|
selectedUnscheduledIncidentIds: [],
|
||||||
|
selectedBookingChangeIncidentIds: []
|
||||||
|
};
|
||||||
|
|
||||||
const SingleIncidentsTable = props => {
|
onSelectChange = (selectedIncidents) => {
|
||||||
const {
|
const newSelectedUnlockedIncidentIds = [];
|
||||||
loading,
|
const newSelectedUnscheduledIncidentIds = [];
|
||||||
title,
|
const newSelectedBookingChangeIncidentIds = [];
|
||||||
openMemberSummaryOnMemberClick,
|
|
||||||
hideMemberName,
|
|
||||||
tableType
|
|
||||||
} = props;
|
|
||||||
const incidents = props.incidents ? props.incidents : [];
|
|
||||||
const columns = [];
|
|
||||||
|
|
||||||
if (incidents && incidents.length > 0){
|
selectedIncidents.forEach(incident => {
|
||||||
let tableHeaders;
|
const incidentDetails = incident.split('-');
|
||||||
switch (tableType) {
|
// incident is described as : select-incidentType-incidentId
|
||||||
case incidentTableTypes.INCIDENTS_RELATED_TO_RESERVATIONS:
|
if (Array.isArray(incidentDetails) && incidentDetails.length > 2){
|
||||||
tableHeaders = doorLockRelatedWithReservationIncidentHeaders;
|
const incidentType = parseInt(incidentDetails[1]);
|
||||||
break;
|
const incidentId = parseInt(incidentDetails[2]);
|
||||||
case incidentTableTypes.STANDALONE_INCIDENTS:
|
|
||||||
tableHeaders = standaloneDoorLockIncidentHeaders;
|
|
||||||
break;
|
|
||||||
case incidentTableTypes.BOOKING_CHANGE_INCIDENTS:
|
|
||||||
tableHeaders = bookingChangeIncidentHeaders;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
tableHeaders.forEach((header) => {
|
switch (incidentType) {
|
||||||
const columnTitle = incidentsReportHeaderTitles[header];
|
case 2:
|
||||||
|
case 5:
|
||||||
let showColumn = true;
|
newSelectedUnlockedIncidentIds.push(incidentId);
|
||||||
if (header === 'memberName' && hideMemberName){
|
break;
|
||||||
showColumn = false;
|
case 3:
|
||||||
}
|
case 4:
|
||||||
|
case 6:
|
||||||
if (columnTitle && showColumn){
|
newSelectedUnscheduledIncidentIds.push(incidentId);
|
||||||
const columnAlignments = {
|
break;
|
||||||
left: 'left',
|
case 7:
|
||||||
right: 'right',
|
case 8:
|
||||||
};
|
case 9:
|
||||||
let columnContentsAlignment = columnAlignments.left;
|
newSelectedBookingChangeIncidentIds.push(incidentId);
|
||||||
|
break;
|
||||||
columns.push({
|
default:
|
||||||
Header: incidentsReportHeaderTitles[header],
|
break;
|
||||||
accessor: header,
|
}
|
||||||
Cell: props => {
|
|
||||||
let cellValue = '';
|
|
||||||
let urlValue = undefined;
|
|
||||||
|
|
||||||
switch (props.column.id) {
|
|
||||||
case 'memberName':
|
|
||||||
const memberId = props.row['_original'].memberId;
|
|
||||||
urlValue = `/specific-member-incidents-report/${memberId}`;
|
|
||||||
cellValue = props.value;
|
|
||||||
break;
|
|
||||||
case 'resourceName':
|
|
||||||
if (props.row['_original'].resourceName){
|
|
||||||
cellValue = props.row['_original'].resourceName || '---';
|
|
||||||
}else{
|
|
||||||
const oldResourceName = props.row['_original'].oldResourceName || '---';
|
|
||||||
const newResourceName = props.row['_original'].newResourceName || '---';
|
|
||||||
if (oldResourceName !== newResourceName){
|
|
||||||
cellValue = `${oldResourceName}\n${newResourceName}`;
|
|
||||||
}else{
|
|
||||||
cellValue = oldResourceName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'reservation':
|
|
||||||
const bookingStart = props.row['_original'].bookingStart;
|
|
||||||
const bookingEnd = props.row['_original'].bookingEnd;
|
|
||||||
cellValue = `${bookingStart}\n${bookingEnd}`;
|
|
||||||
break;
|
|
||||||
case 'doorLockTimestamps':
|
|
||||||
const unlockTimestamp = props.row['_original'].unlockTimestamp;
|
|
||||||
const lockTimestamp = props.row['_original'].lockTimestamp;
|
|
||||||
cellValue = `${unlockTimestamp ? unlockTimestamp : '---'}\n${lockTimestamp ? lockTimestamp : '---'}`;
|
|
||||||
break;
|
|
||||||
case 'incidentType':
|
|
||||||
cellValue = incidentDescriptions[props.value];
|
|
||||||
break;
|
|
||||||
case 'incidentLevel':
|
|
||||||
cellValue = incidentLevelDescriptions[props.value];
|
|
||||||
break;
|
|
||||||
case 'feeDescription':
|
|
||||||
const { incidentType, incidentLevel, timeIntervalsToCharge } = props.row['_original'];
|
|
||||||
|
|
||||||
switch (incidentType) {
|
|
||||||
case UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
|
||||||
case UNLOCKED_INCIDENT_STANDALONE:
|
|
||||||
cellValue = `${incidentLevelDescriptions[incidentLevel]}`;
|
|
||||||
break;
|
|
||||||
case UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
|
||||||
case UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
|
||||||
case UNSCHEDULED_INCIDENT_STANDALONE:
|
|
||||||
cellValue = `${timeIntervalsToCharge} x 5 min`;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
cellValue = '';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'totalChargeFee':
|
|
||||||
const totalFee = (props.row['_original'].incidentPrice || props.value) || 0;
|
|
||||||
const totalFeeFormatted = parseFloat(totalFee).toFixed(2);
|
|
||||||
cellValue = `$ ${totalFeeFormatted}`;
|
|
||||||
columnContentsAlignment = columnAlignments.right;
|
|
||||||
break;
|
|
||||||
case 'oldReservation':
|
|
||||||
const oldBookingStart = props.row['_original'].oldBookingStart;
|
|
||||||
const oldBookingEnd = props.row['_original'].oldBookingEnd;
|
|
||||||
cellValue = `${oldBookingStart}\n${oldBookingEnd}`;
|
|
||||||
break;
|
|
||||||
case 'newReservation':
|
|
||||||
const newBookingStart = props.row['_original'].newBookingStart || '---';
|
|
||||||
const newBookingEnd = props.row['_original'].newBookingEnd || '---';
|
|
||||||
cellValue = `${newBookingStart}\n${newBookingEnd}`;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
cellValue = props.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (openMemberSummaryOnMemberClick && urlValue){
|
|
||||||
return <NavLink to={urlValue}>{cellValue}</NavLink>
|
|
||||||
}else{
|
|
||||||
return <div style={{ textAlign: columnContentsAlignment, whiteSpace: 'pre' }}>{cellValue}</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
this.setState({
|
||||||
<div>
|
selectedUnlockedIncidentIds: newSelectedUnlockedIncidentIds,
|
||||||
<h4>{title}</h4>
|
selectedUnscheduledIncidentIds: newSelectedUnscheduledIncidentIds,
|
||||||
<Loader active={loading} />
|
selectedBookingChangeIncidentIds: newSelectedBookingChangeIncidentIds
|
||||||
{
|
});
|
||||||
!loading && incidents &&
|
};
|
||||||
<ReactTable
|
|
||||||
data={incidents}
|
deleteSelectedFees = () => {
|
||||||
multiSort={false}
|
const { dateRange, deleteIncidentsById } = this.props;
|
||||||
columns={columns}
|
const { selectedUnlockedIncidentIds, selectedUnscheduledIncidentIds, selectedBookingChangeIncidentIds } = this.state;
|
||||||
/>
|
|
||||||
|
const incidentsToDelete = {
|
||||||
|
unlockedIncidentIds: selectedUnlockedIncidentIds,
|
||||||
|
unscheduledIncidentIds: selectedUnscheduledIncidentIds,
|
||||||
|
bookingChangeIncidentIds: selectedBookingChangeIncidentIds
|
||||||
|
};
|
||||||
|
|
||||||
|
deleteIncidentsById(dateRange, incidentsToDelete);
|
||||||
|
this.setState({
|
||||||
|
selectedUnlockedIncidentIds: [],
|
||||||
|
selectedUnscheduledIncidentIds: [],
|
||||||
|
selectedBookingChangeIncidentIds: []
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
render(){
|
||||||
|
const {
|
||||||
|
loading,
|
||||||
|
title,
|
||||||
|
openMemberSummaryOnMemberClick,
|
||||||
|
hideMemberName,
|
||||||
|
tableType
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
const {
|
||||||
|
selectedUnlockedIncidentIds,
|
||||||
|
selectedUnscheduledIncidentIds,
|
||||||
|
selectedBookingChangeIncidentIds
|
||||||
|
} = this.state;
|
||||||
|
|
||||||
|
const totalSelected = selectedUnlockedIncidentIds.length + selectedUnscheduledIncidentIds.length + selectedBookingChangeIncidentIds.length;
|
||||||
|
const numberOfSelectedText = totalSelected > 0 ? ` (${totalSelected})` : '';
|
||||||
|
|
||||||
|
const incidents = this.props.incidents ? this.props.incidents : [];
|
||||||
|
incidents.forEach(incident => {
|
||||||
|
incident.id = `${incident.incidentType}-${incident.incidentId}`;
|
||||||
|
});
|
||||||
|
const columns = [];
|
||||||
|
|
||||||
|
if (incidents && incidents.length > 0){
|
||||||
|
let tableHeaders;
|
||||||
|
switch (tableType) {
|
||||||
|
case incidentTableTypes.INCIDENTS_RELATED_TO_RESERVATIONS:
|
||||||
|
tableHeaders = doorLockRelatedWithReservationIncidentHeaders;
|
||||||
|
break;
|
||||||
|
case incidentTableTypes.STANDALONE_INCIDENTS:
|
||||||
|
tableHeaders = standaloneDoorLockIncidentHeaders;
|
||||||
|
break;
|
||||||
|
case incidentTableTypes.BOOKING_CHANGE_INCIDENTS:
|
||||||
|
tableHeaders = bookingChangeIncidentHeaders;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SingleIncidentsTable;
|
tableHeaders.forEach((header) => {
|
||||||
|
const columnTitle = incidentsReportHeaderTitles[header];
|
||||||
|
|
||||||
|
let showColumn = true;
|
||||||
|
if (header === 'memberName' && hideMemberName){
|
||||||
|
showColumn = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (columnTitle && showColumn){
|
||||||
|
const columnAlignments = {
|
||||||
|
left: 'left',
|
||||||
|
right: 'right',
|
||||||
|
};
|
||||||
|
let columnContentsAlignment = columnAlignments.left;
|
||||||
|
|
||||||
|
columns.push({
|
||||||
|
Header: incidentsReportHeaderTitles[header],
|
||||||
|
accessor: header,
|
||||||
|
Cell: props => {
|
||||||
|
let cellValue = '';
|
||||||
|
let urlValue = undefined;
|
||||||
|
|
||||||
|
switch (props.column.id) {
|
||||||
|
case 'memberName':
|
||||||
|
const memberId = props.row['_original'].memberId;
|
||||||
|
urlValue = `/specific-member-incidents-report/${memberId}`;
|
||||||
|
cellValue = props.value;
|
||||||
|
break;
|
||||||
|
case 'resourceName':
|
||||||
|
if (props.row['_original'].resourceName){
|
||||||
|
cellValue = props.row['_original'].resourceName || '---';
|
||||||
|
}else{
|
||||||
|
const oldResourceName = props.row['_original'].oldResourceName || '---';
|
||||||
|
const newResourceName = props.row['_original'].newResourceName || '---';
|
||||||
|
if (oldResourceName !== newResourceName){
|
||||||
|
cellValue = `${oldResourceName}\n${newResourceName}`;
|
||||||
|
}else{
|
||||||
|
cellValue = oldResourceName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'reservation':
|
||||||
|
const bookingStart = props.row['_original'].bookingStart;
|
||||||
|
const bookingEnd = props.row['_original'].bookingEnd;
|
||||||
|
cellValue = `${bookingStart}\n${bookingEnd}`;
|
||||||
|
break;
|
||||||
|
case 'doorLockTimestamps':
|
||||||
|
const unlockTimestamp = props.row['_original'].unlockTimestamp;
|
||||||
|
const lockTimestamp = props.row['_original'].lockTimestamp;
|
||||||
|
cellValue = `${unlockTimestamp ? unlockTimestamp : '---'}\n${lockTimestamp ? lockTimestamp : '---'}`;
|
||||||
|
break;
|
||||||
|
case 'incidentType':
|
||||||
|
cellValue = incidentDescriptions[props.value];
|
||||||
|
break;
|
||||||
|
case 'incidentLevel':
|
||||||
|
cellValue = incidentLevelDescriptions[props.value];
|
||||||
|
break;
|
||||||
|
case 'feeDescription':
|
||||||
|
const { incidentType, incidentLevel, timeIntervalsToCharge } = props.row['_original'];
|
||||||
|
|
||||||
|
switch (incidentType) {
|
||||||
|
case UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
||||||
|
case UNLOCKED_INCIDENT_STANDALONE:
|
||||||
|
cellValue = `${incidentLevelDescriptions[incidentLevel]}`;
|
||||||
|
break;
|
||||||
|
case UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
||||||
|
case UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
||||||
|
case UNSCHEDULED_INCIDENT_STANDALONE:
|
||||||
|
cellValue = `${timeIntervalsToCharge} x 5 min`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cellValue = '';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'totalChargeFee':
|
||||||
|
const totalFee = (props.row['_original'].incidentPrice || props.value) || 0;
|
||||||
|
const totalFeeFormatted = parseFloat(totalFee).toFixed(2);
|
||||||
|
cellValue = `$ ${totalFeeFormatted}`;
|
||||||
|
columnContentsAlignment = columnAlignments.right;
|
||||||
|
break;
|
||||||
|
case 'oldReservation':
|
||||||
|
const oldBookingStart = props.row['_original'].oldBookingStart;
|
||||||
|
const oldBookingEnd = props.row['_original'].oldBookingEnd;
|
||||||
|
cellValue = `${oldBookingStart}\n${oldBookingEnd}`;
|
||||||
|
break;
|
||||||
|
case 'newReservation':
|
||||||
|
const newBookingStart = props.row['_original'].newBookingStart || '---';
|
||||||
|
const newBookingEnd = props.row['_original'].newBookingEnd || '---';
|
||||||
|
cellValue = `${newBookingStart}\n${newBookingEnd}`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cellValue = props.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (openMemberSummaryOnMemberClick && urlValue){
|
||||||
|
return <NavLink to={urlValue}>{cellValue}</NavLink>
|
||||||
|
}else{
|
||||||
|
return <div style={{ textAlign: columnContentsAlignment, whiteSpace: 'pre' }}>{cellValue}</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h4>{title}</h4>
|
||||||
|
<Loader active={loading} />
|
||||||
|
{
|
||||||
|
<Button disabled={loading || totalSelected === 0} onClick={this.deleteSelectedFees}>{`Delete selected ${numberOfSelectedText}`}</Button>
|
||||||
|
}
|
||||||
|
<br/><br/>
|
||||||
|
{
|
||||||
|
!loading && incidents &&
|
||||||
|
<SelectTable
|
||||||
|
data={incidents}
|
||||||
|
multiSort={false}
|
||||||
|
columns={columns}
|
||||||
|
keyField="id"
|
||||||
|
onSelectChange={this.onSelectChange}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
deleteIncidentsById: (dateRange, incidentsToDelete) => deleteIncidents(dispatch, {dateRange, incidentsToDelete})
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(null, mapDispatchToProps)(SingleIncidentsTable);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from '../../constants/enums';
|
} from '../../constants/enums';
|
||||||
|
|
||||||
export default function MemberIncidentsTables (props) {
|
export default function MemberIncidentsTables (props) {
|
||||||
const { pendingIncidents, incidents, hideMemberName } = props;
|
const { pendingIncidents, incidents, hideMemberName, dateRange } = props;
|
||||||
|
|
||||||
const incidentsRelatedToReservations = [];
|
const incidentsRelatedToReservations = [];
|
||||||
const standaloneIncidents = [];
|
const standaloneIncidents = [];
|
||||||
@@ -46,6 +46,7 @@ export default function MemberIncidentsTables (props) {
|
|||||||
openMemberSummaryOnMemberClick
|
openMemberSummaryOnMemberClick
|
||||||
hideMemberName={hideMemberName}
|
hideMemberName={hideMemberName}
|
||||||
tableType={incidentTableTypes.INCIDENTS_RELATED_TO_RESERVATIONS}
|
tableType={incidentTableTypes.INCIDENTS_RELATED_TO_RESERVATIONS}
|
||||||
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ export default function MemberIncidentsTables (props) {
|
|||||||
openMemberSummaryOnMemberClick
|
openMemberSummaryOnMemberClick
|
||||||
hideMemberName={hideMemberName}
|
hideMemberName={hideMemberName}
|
||||||
tableType={incidentTableTypes.STANDALONE_INCIDENTS}
|
tableType={incidentTableTypes.STANDALONE_INCIDENTS}
|
||||||
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -66,6 +68,7 @@ export default function MemberIncidentsTables (props) {
|
|||||||
openMemberSummaryOnMemberClick
|
openMemberSummaryOnMemberClick
|
||||||
hideMemberName={hideMemberName}
|
hideMemberName={hideMemberName}
|
||||||
tableType={incidentTableTypes.BOOKING_CHANGE_INCIDENTS}
|
tableType={incidentTableTypes.BOOKING_CHANGE_INCIDENTS}
|
||||||
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
111
client/src/components/SelectTable/index.js
Normal file
111
client/src/components/SelectTable/index.js
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
import Table from 'react-table';
|
||||||
|
import SelectTableHOC from 'react-table/lib/hoc/selectTable';
|
||||||
|
|
||||||
|
const SelectTableElement = SelectTableHOC(Table);
|
||||||
|
|
||||||
|
class SelectTable extends Component {
|
||||||
|
static defaultProps = {
|
||||||
|
keyField: "id"
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle a single checkbox for select table
|
||||||
|
*/
|
||||||
|
toggleSelection = (key, shift, row) => {
|
||||||
|
// start off with the existing state
|
||||||
|
let selection = [...this.state.selection];
|
||||||
|
const keyIndex = selection.indexOf(key);
|
||||||
|
|
||||||
|
// check to see if the key exists
|
||||||
|
if (keyIndex >= 0) {
|
||||||
|
// it does exist so we will remove it using destructing
|
||||||
|
selection = [
|
||||||
|
...selection.slice(0, keyIndex),
|
||||||
|
...selection.slice(keyIndex + 1)
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// it does not exist so add it
|
||||||
|
selection.push(key);
|
||||||
|
}
|
||||||
|
// update the state
|
||||||
|
this.props.onSelectChange(selection);
|
||||||
|
this.setState({ selection });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle all checkboxes for select table
|
||||||
|
*/
|
||||||
|
toggleAll = () => {
|
||||||
|
const { keyField } = this.props;
|
||||||
|
const selectAll = !this.state.selectAll;
|
||||||
|
const selection = [];
|
||||||
|
|
||||||
|
if (selectAll) {
|
||||||
|
// we need to get at the internals of ReactTable
|
||||||
|
const wrappedInstance = this.checkboxTable.getWrappedInstance();
|
||||||
|
// the 'sortedData' property contains the currently accessible records based on the filter and sort
|
||||||
|
const currentRecords = wrappedInstance.getResolvedState().sortedData;
|
||||||
|
// we just push all the IDs onto the selection array
|
||||||
|
currentRecords.forEach(item => {
|
||||||
|
selection.push(`select-${item._original[keyField]}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.props.onSelectChange(selection);
|
||||||
|
this.setState({ selectAll, selection });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not a row is selected for select table
|
||||||
|
*/
|
||||||
|
isSelected = key => {
|
||||||
|
return this.state.selection.includes(`select-${key}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
rowFn = (state, rowInfo, column, instance) => {
|
||||||
|
const { selection } = this.state;
|
||||||
|
|
||||||
|
return {
|
||||||
|
onClick: (e, handleOriginal) => {
|
||||||
|
// console.log("It was in this row:", rowInfo);
|
||||||
|
|
||||||
|
// IMPORTANT! React-Table uses onClick internally to trigger
|
||||||
|
// events like expanding SubComponents and pivots.
|
||||||
|
// By default a custom 'onClick' handler will override this functionality.
|
||||||
|
// If you want to fire the original onClick handler, call the
|
||||||
|
// 'handleOriginal' function.
|
||||||
|
if (handleOriginal) {
|
||||||
|
handleOriginal();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
background:
|
||||||
|
rowInfo &&
|
||||||
|
selection.includes(`select-${rowInfo.original.id}`) &&
|
||||||
|
"lightgreen"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
state = {
|
||||||
|
selectAll: false,
|
||||||
|
selection: []
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<SelectTableElement
|
||||||
|
{...this.props}
|
||||||
|
ref={r => (this.checkboxTable = r)}
|
||||||
|
toggleSelection={this.toggleSelection}
|
||||||
|
selectAll={this.state.selectAll}
|
||||||
|
selectType="checkbox"
|
||||||
|
toggleAll={this.toggleAll}
|
||||||
|
isSelected={this.isSelected}
|
||||||
|
getTrProps={this.rowFn}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SelectTable;
|
||||||
@@ -47,7 +47,7 @@ class IncidentsReport extends Component {
|
|||||||
<br/><br/>
|
<br/><br/>
|
||||||
<hr/>
|
<hr/>
|
||||||
<br/>
|
<br/>
|
||||||
<MemberIncidentsTables pendingIncidents={loading} incidents={incidents} />
|
<MemberIncidentsTables pendingIncidents={loading} incidents={incidents} dateRange={dateRange} />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,17 @@ export const fetchIncidents = (dispatch, dateRange) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deleteIncidents = (dispatch, deleteData) => {
|
||||||
|
dispatch({type: FETCH_INCIDENTS_PENDING});
|
||||||
|
API.delete(`/integration/fees`, { data: deleteData })
|
||||||
|
.then(response => {
|
||||||
|
dispatch({type: FETCH_INCIDENTS_SUCCESS, payload: response.data});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
dispatch({type: FETCH_INCIDENTS_FAILED, payload: error.response});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const fetchMembersList = (dispatch) => {
|
export const fetchMembersList = (dispatch) => {
|
||||||
dispatch({type: FETCH_MEMBERS_PENDING});
|
dispatch({type: FETCH_MEMBERS_PENDING});
|
||||||
API.get('officeRnD/membersList')
|
API.get('officeRnD/membersList')
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees'
|
|||||||
const { reformatMembershipsName } = require('../services/officeRnD/memberships');
|
const { reformatMembershipsName } = require('../services/officeRnD/memberships');
|
||||||
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
|
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
|
||||||
const { checkIfProcessing } = require('../services/integration/processingStatus');
|
const { checkIfProcessing } = require('../services/integration/processingStatus');
|
||||||
|
const { deleteUnlockedIncidentsById, deleteUnscheduledIncidentsById } = require('../services/integration/doorLockCharges');
|
||||||
|
const { deleteBookingChangeIncidentsById } = require('../services/integration/bookingChangeCharges');
|
||||||
|
|
||||||
const { UI_TIMEZONE, DEFAULT_DATE_FORMAT, ALLOW_SENDING_FEES, integrationServiceErrors } = require('../constants/constants');
|
const { UI_TIMEZONE, DEFAULT_DATE_FORMAT, ALLOW_SENDING_FEES, integrationServiceErrors } = require('../constants/constants');
|
||||||
|
|
||||||
@@ -175,6 +177,38 @@ const addFees = (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteFees= (req, res) => {
|
||||||
|
const deleteData = req.body;
|
||||||
|
const dateRange = deleteData.dateRange ? deleteData.dateRange : null;
|
||||||
|
const incidents = deleteData.incidentsToDelete ? deleteData.incidentsToDelete : null;
|
||||||
|
|
||||||
|
const unlockedIncidentIds = incidents.unlockedIncidentIds ? incidents.unlockedIncidentIds : [];
|
||||||
|
const unscheduledIncidentIds = incidents.unscheduledIncidentIds ? incidents.unscheduledIncidentIds : [];
|
||||||
|
const bookingChangeIncidentIds = incidents.bookingChangeIncidentIds ? incidents.bookingChangeIncidentIds : [];
|
||||||
|
|
||||||
|
req.params.startDate = dateRange.startDate ? dateRange.startDate : null;
|
||||||
|
req.params.endDate = dateRange.endDate ? dateRange.endDate : null;
|
||||||
|
|
||||||
|
if (Array.isArray(unlockedIncidentIds) && Array.isArray(unscheduledIncidentIds) && Array.isArray(bookingChangeIncidentIds)){
|
||||||
|
const asyncDeleteActions = [
|
||||||
|
deleteUnlockedIncidentsById(unlockedIncidentIds),
|
||||||
|
deleteUnscheduledIncidentsById(unscheduledIncidentIds),
|
||||||
|
deleteBookingChangeIncidentsById(bookingChangeIncidentIds)
|
||||||
|
];
|
||||||
|
|
||||||
|
Promise.all(asyncDeleteActions)
|
||||||
|
.then(() => {
|
||||||
|
getAllIncidentsController(req, res);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error deleting incidents : ', error);
|
||||||
|
res.status(500).send();
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
getAllIncidentsController(req, res);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const checkProcessingStatus = (req, res) => {
|
const checkProcessingStatus = (req, res) => {
|
||||||
checkIfProcessing()
|
checkIfProcessing()
|
||||||
.then((processing) => {
|
.then((processing) => {
|
||||||
@@ -227,4 +261,5 @@ module.exports = {
|
|||||||
addFees,
|
addFees,
|
||||||
checkProcessingStatus,
|
checkProcessingStatus,
|
||||||
getPracticeSummaryReport,
|
getPracticeSummaryReport,
|
||||||
|
deleteFees
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: (queryInterface, Sequelize) => {
|
||||||
|
return queryInterface.addColumn('unlockedIncidents', 'deleted', {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
down: (queryInterface, Sequelize) => {
|
||||||
|
return queryInterface.removeColumn('unlockedIncidents', 'deleted');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: (queryInterface, Sequelize) => {
|
||||||
|
return queryInterface.addColumn('unscheduledIncidents', 'deleted', {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
down: (queryInterface, Sequelize) => {
|
||||||
|
return queryInterface.removeColumn('unscheduledIncidents', 'deleted');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -22,6 +22,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
incidentLevelPrice: DataTypes.FLOAT,
|
incidentLevelPrice: DataTypes.FLOAT,
|
||||||
unlockTimestamp: DataTypes.DATE,
|
unlockTimestamp: DataTypes.DATE,
|
||||||
|
deleted: DataTypes.BOOLEAN
|
||||||
}, {});
|
}, {});
|
||||||
unlockedIncident.associate = function(models) {
|
unlockedIncident.associate = function(models) {
|
||||||
// associations can be defined here
|
// associations can be defined here
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
totalChargeFee: DataTypes.FLOAT,
|
totalChargeFee: DataTypes.FLOAT,
|
||||||
unlockTimestamp: DataTypes.DATE,
|
unlockTimestamp: DataTypes.DATE,
|
||||||
lockTimestamp: DataTypes.DATE,
|
lockTimestamp: DataTypes.DATE,
|
||||||
|
deleted: DataTypes.BOOLEAN
|
||||||
}, {});
|
}, {});
|
||||||
unscheduledIncident.associate = function(models) {
|
unscheduledIncident.associate = function(models) {
|
||||||
// associations can be defined here
|
// associations can be defined here
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const {
|
|||||||
addFees,
|
addFees,
|
||||||
checkProcessingStatus,
|
checkProcessingStatus,
|
||||||
getPracticeSummaryReport,
|
getPracticeSummaryReport,
|
||||||
|
deleteFees
|
||||||
} = require('../controllers/integration');
|
} = require('../controllers/integration');
|
||||||
|
|
||||||
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
||||||
@@ -34,6 +35,7 @@ router.get('/integration/report/allIncidents/:startDate/:endDate', getAllInciden
|
|||||||
router.get('/officeRnD/membersList', fetchMembersList);
|
router.get('/officeRnD/membersList', fetchMembersList);
|
||||||
|
|
||||||
router.post('/integration/addFees', addFees);
|
router.post('/integration/addFees', addFees);
|
||||||
|
router.delete('/integration/fees', deleteFees);
|
||||||
|
|
||||||
router.get('/integration/processing', checkProcessingStatus);
|
router.get('/integration/processing', checkProcessingStatus);
|
||||||
|
|
||||||
|
|||||||
@@ -274,6 +274,15 @@ const deleteBookingChangeIncidents = (incidents) => {
|
|||||||
return Promise.all(asyncActions);
|
return Promise.all(asyncActions);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteBookingChangeIncidentsById = (incidentIds) => {
|
||||||
|
const filters = {
|
||||||
|
id: {
|
||||||
|
[Op.in]: incidentIds
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return db.bookingChangeIncident.update({deleted: true},{where: filters});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getChargedCanceledReservations,
|
getChargedCanceledReservations,
|
||||||
getIncidentsFromChanges,
|
getIncidentsFromChanges,
|
||||||
@@ -281,4 +290,5 @@ module.exports = {
|
|||||||
getShorteningIncidentsForReservationId,
|
getShorteningIncidentsForReservationId,
|
||||||
getReservationsIncidentsForRemoval,
|
getReservationsIncidentsForRemoval,
|
||||||
deleteBookingChangeIncidents,
|
deleteBookingChangeIncidents,
|
||||||
|
deleteBookingChangeIncidentsById
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
const db = require('../../models/index');
|
const db = require('../../models/index');
|
||||||
|
const Op = require('sequelize').Op;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
doorLockEvents,
|
doorLockEvents,
|
||||||
@@ -18,7 +19,8 @@ const { getAllFinishedBookings, getFirstPreviousBooking, getFirstNextBooking } =
|
|||||||
const getSortedIncidentsForMember = (memberId) => {
|
const getSortedIncidentsForMember = (memberId) => {
|
||||||
const attributes = ['bookingStart', 'incidentLevel', 'incidentLevelPrice', 'unlockTimestamp'];
|
const attributes = ['bookingStart', 'incidentLevel', 'incidentLevelPrice', 'unlockTimestamp'];
|
||||||
const filters = {
|
const filters = {
|
||||||
memberId
|
memberId,
|
||||||
|
deleted: false
|
||||||
};
|
};
|
||||||
const order = [['unlockTimestamp', 'DESC']];
|
const order = [['unlockTimestamp', 'DESC']];
|
||||||
|
|
||||||
@@ -59,6 +61,7 @@ const insertUnscheduledIncidents = (incidents) => {
|
|||||||
bookingEnd: end,
|
bookingEnd: end,
|
||||||
unlockTimestamp,
|
unlockTimestamp,
|
||||||
lockTimestamp,
|
lockTimestamp,
|
||||||
|
deleted: false
|
||||||
},
|
},
|
||||||
defaults: {...incidentForDB},
|
defaults: {...incidentForDB},
|
||||||
}));
|
}));
|
||||||
@@ -67,6 +70,15 @@ const insertUnscheduledIncidents = (incidents) => {
|
|||||||
return Promise.all(asyncJobs);
|
return Promise.all(asyncJobs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteUnscheduledIncidentsById = (incidentIds) => {
|
||||||
|
const filters = {
|
||||||
|
id: {
|
||||||
|
[Op.in]: incidentIds
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return db.unscheduledIncident.update({deleted: true},{where: filters});
|
||||||
|
};
|
||||||
|
|
||||||
const insertUnlockedIncidents = (incidents) => {
|
const insertUnlockedIncidents = (incidents) => {
|
||||||
const asyncJobs = [];
|
const asyncJobs = [];
|
||||||
incidents.forEach((incident) => {
|
incidents.forEach((incident) => {
|
||||||
@@ -93,6 +105,7 @@ const insertUnlockedIncidents = (incidents) => {
|
|||||||
bookingEnd: end,
|
bookingEnd: end,
|
||||||
unlockTimestamp,
|
unlockTimestamp,
|
||||||
incidentLevel,
|
incidentLevel,
|
||||||
|
deleted: false
|
||||||
},
|
},
|
||||||
defaults: {...incidentForDB},
|
defaults: {...incidentForDB},
|
||||||
}));
|
}));
|
||||||
@@ -101,6 +114,15 @@ const insertUnlockedIncidents = (incidents) => {
|
|||||||
return Promise.all(asyncJobs);
|
return Promise.all(asyncJobs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteUnlockedIncidentsById = (incidentIds) => {
|
||||||
|
const filters = {
|
||||||
|
id: {
|
||||||
|
[Op.in]: incidentIds
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return db.unlockedIncident.update({deleted: true},{where: filters});
|
||||||
|
};
|
||||||
|
|
||||||
const setUnlockedIncidentsLevel = (incidents) => {
|
const setUnlockedIncidentsLevel = (incidents) => {
|
||||||
return new Promise ((resolve, reject) => {
|
return new Promise ((resolve, reject) => {
|
||||||
const sortingFunction = (incidentA, incidentB) => {
|
const sortingFunction = (incidentA, incidentB) => {
|
||||||
@@ -573,5 +595,7 @@ const calculateDoorLockCharges = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
calculateDoorLockCharges
|
calculateDoorLockCharges,
|
||||||
|
deleteUnlockedIncidentsById,
|
||||||
|
deleteUnscheduledIncidentsById
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ const { getChargedCanceledReservations } = require('../integration/bookingChange
|
|||||||
const getUnlockedIncidents = (startDate, endDate, memberIds) => {
|
const getUnlockedIncidents = (startDate, endDate, memberIds) => {
|
||||||
const attributes = ['id', 'reservationId', 'memberId', 'resourceId', 'bookingStart', 'bookingEnd', 'unlockTimestamp', 'incidentLevel', 'incidentLevelPrice'];
|
const attributes = ['id', 'reservationId', 'memberId', 'resourceId', 'bookingStart', 'bookingEnd', 'unlockTimestamp', 'incidentLevel', 'incidentLevelPrice'];
|
||||||
|
|
||||||
const filters = {};
|
const filters = {
|
||||||
|
deleted: false
|
||||||
|
};
|
||||||
|
|
||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
const bookingStartCondition = {
|
const bookingStartCondition = {
|
||||||
@@ -76,7 +78,9 @@ const getUnscheduledIncidents = (startDate, endDate, memberIds) => {
|
|||||||
'totalChargeFee'
|
'totalChargeFee'
|
||||||
];
|
];
|
||||||
|
|
||||||
const filters = {};
|
const filters = {
|
||||||
|
deleted: false
|
||||||
|
};
|
||||||
|
|
||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
const bookingStartCondition = {
|
const bookingStartCondition = {
|
||||||
|
|||||||
Reference in New Issue
Block a user