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: