From 1e1c61882f2833a16874c40e6f8c05f300b85cfd Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Sun, 7 Jul 2019 07:02:42 +0200 Subject: [PATCH] Fixed column names and the report --- .../components/SingleIncidentsTable.js | 119 ++++++++++++ .../components/MemberIncidentsTables/index.js | 78 ++++++++ client/src/constants/enums.js | 15 +- client/src/constants/menuItems.js | 2 + client/src/scenes/IncidentsReport/index.js | 4 +- .../components/MemberSelector.js | 3 +- .../components/MemberSummary.js | 13 +- .../src/scenes/PracticeSummaryReport/index.js | 11 +- constants/constants.js | 7 +- ...y-column-to-the-unlockedIncidents-table.js | 14 ++ ...lumns-to-the-unscheduledIncidents-table.js | 27 +++ models/unlockedIncident.js | 1 + models/unscheduledIncident.js | 2 + services/doorLock/doorLock.js | 3 - services/integration/doorLockCharges.js | 183 ++++++++++-------- services/integration/reports.js | 88 +++++++-- 16 files changed, 455 insertions(+), 115 deletions(-) create mode 100644 client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js create mode 100644 client/src/components/MemberIncidentsTables/index.js create mode 100644 migrations/20190705054346-add-door-lock-entry-column-to-the-unlockedIncidents-table.js create mode 100644 migrations/20190705065019-add-door-lock-entry-columns-to-the-unscheduledIncidents-table.js diff --git a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js new file mode 100644 index 0000000..5c1d91e --- /dev/null +++ b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js @@ -0,0 +1,119 @@ +import React from 'react'; +import { Loader } from 'semantic-ui-react'; +import ReactTable from 'react-table'; +import 'react-table/react-table.css'; +import { NavLink } from 'react-router-dom'; + +import {incidentsReportHeaderTitles} from '../../../constants/menuItems'; +import { + incidentDescriptions, + incidentLevelDescriptions, + UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION, UNLOCKED_INCIDENT_STANDALONE, UNSCHEDULED_INCIDENT_AFTER_RESERVATION, + UNSCHEDULED_INCIDENT_BEFORE_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE +} from '../../../constants/enums'; + + +const SingleIncidentsTable = props => { + const { loading, title, openMemberSummaryOnMemberClick, showBookingTimes, showDoorLockEntryTimes, hideMemberName } = props; + const incidents = props.incidents ? props.incidents : []; + + const columns = []; + if (incidents && incidents.length > 0){ + const incidentHeaders = Object.keys(incidentsReportHeaderTitles); + + incidentHeaders.forEach((header) => { + const columnTitle = incidentsReportHeaderTitles[header]; + + let showColumn = true; + if ((header === 'bookingStart' || header === 'bookingEnd') && !showBookingTimes){ + showColumn = false; + } + if ((header === 'unlockTimestamp' || header === 'lockTimestamp') && !showDoorLockEntryTimes){ + showColumn = false; + } + 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 = `/practice-summary-report/${memberId}`; + cellValue = props.value; + 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.value ? props.value : props.row['_original'].incidentPrice; + const totalFeeFormatted = parseFloat(totalFee).toFixed(2); + cellValue = `$ ${totalFeeFormatted}`; + columnContentsAlignment = columnAlignments.right; + break; + default: + cellValue = props.value; + } + + if (openMemberSummaryOnMemberClick && urlValue){ + return {cellValue} + }else{ + return
{cellValue}
+ } + } + }); + } + }); + } + + return ( +
+

{title}

+ + { + !loading && incidents && + + } +
+ ); +}; + +export default SingleIncidentsTable; diff --git a/client/src/components/MemberIncidentsTables/index.js b/client/src/components/MemberIncidentsTables/index.js new file mode 100644 index 0000000..ed05541 --- /dev/null +++ b/client/src/components/MemberIncidentsTables/index.js @@ -0,0 +1,78 @@ +import React from 'react'; +import {Accordion, Label} from 'semantic-ui-react'; +import SingleIncidentsTable from './components/SingleIncidentsTable'; +import { + UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION, UNLOCKED_INCIDENT_STANDALONE, UNSCHEDULED_INCIDENT_AFTER_RESERVATION, + UNSCHEDULED_INCIDENT_BEFORE_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE +} from '../../constants/enums'; + +export default function MemberIncidentsTables (props) { + const { pendingIncidents, incidents, hideMemberName } = props; + + 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 = ( + + ); + + const standaloneIncidentsTable = ( + + ); + + const accordionPanels = [ + { + key: 'related-door-lock-incidents', + title : { content: