|
| 1 | +// import PrintableItinerary from '@opentripplanner/printable-itinerary' |
| 2 | +import React, { Component } from 'react' |
| 3 | +import { Button } from 'react-bootstrap' |
| 4 | +import { connect } from 'react-redux' |
| 5 | + |
| 6 | +import * as callTakerActions from '../../actions/call-taker' |
| 7 | +import * as fieldTripActions from '../../actions/field-trip' |
| 8 | +import DefaultMap from '../map/default-map' |
| 9 | +// import TripDetails from '../narrative/connected-trip-details' |
| 10 | +// import { getTripFromRequest } from '../../util/call-taker' |
| 11 | +import { ComponentContext } from '../../util/contexts' |
| 12 | + |
| 13 | +import { |
| 14 | + Val |
| 15 | +} from './styled' |
| 16 | + |
| 17 | +class PrintFieldTripLayout extends Component { |
| 18 | + static contextType = ComponentContext |
| 19 | + |
| 20 | + constructor (props) { |
| 21 | + super(props) |
| 22 | + this.state = { |
| 23 | + mapVisible: true |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + _toggleMap = () => { |
| 28 | + this.setState({ mapVisible: !this.state.mapVisible }) |
| 29 | + } |
| 30 | + |
| 31 | + _print = () => { |
| 32 | + window.print() |
| 33 | + } |
| 34 | + |
| 35 | + componentDidMount () { |
| 36 | + const { initializeModules } = this.props |
| 37 | + // Add print-view class to html tag to ensure that iOS scroll fix only applies |
| 38 | + // to non-print views. |
| 39 | + const root = document.getElementsByTagName('html')[0] |
| 40 | + root.setAttribute('class', 'print-view') |
| 41 | + |
| 42 | + // Load call-taker/field-trip functionality (performs a fetch). |
| 43 | + initializeModules() |
| 44 | + } |
| 45 | + |
| 46 | + async componentDidUpdate (prevProps) { |
| 47 | + const { fetchFieldTrips, fetchFieldTripDetails, requestId, session } = this.props |
| 48 | + if (!prevProps.session && session) { |
| 49 | + // When session is set |
| 50 | + // Load all field trips |
| 51 | + await fetchFieldTrips() |
| 52 | + // Load details for field trip per request id. |
| 53 | + fetchFieldTripDetails(requestId) |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Remove class attribute from html tag on clean up. |
| 59 | + */ |
| 60 | + componentWillUnmount () { |
| 61 | + const root = document.getElementsByTagName('html')[0] |
| 62 | + root.removeAttribute('class') |
| 63 | + } |
| 64 | + |
| 65 | + render () { |
| 66 | + const { request } = this.props |
| 67 | + // const { LegIcon } = this.context |
| 68 | + if (!request) return null |
| 69 | + |
| 70 | + const { |
| 71 | + address, |
| 72 | + emailAddress, |
| 73 | + endLocation, |
| 74 | + faxNumber, |
| 75 | + grade, |
| 76 | + numChaperones, |
| 77 | + numFreeStudents, |
| 78 | + numStudents, |
| 79 | + phoneNumber, |
| 80 | + schoolName, |
| 81 | + teacherName, |
| 82 | + timeStamp |
| 83 | + } = request |
| 84 | + |
| 85 | + // const outboundTrip = getTripFromRequest(request, true) |
| 86 | + // const inboundTrip = getTripFromRequest(request, false) |
| 87 | + |
| 88 | + return ( |
| 89 | + <div className='otp print-layout'> |
| 90 | + {/* The header bar, including the Toggle Map and Print buttons */} |
| 91 | + <div className='header'> |
| 92 | + <div style={{ float: 'right' }}> |
| 93 | + <Button bsSize='small' onClick={this._toggleMap}> |
| 94 | + <i className='fa fa-map' /> Toggle Map |
| 95 | + </Button> |
| 96 | + {' '} |
| 97 | + <Button bsSize='small' onClick={this._print}> |
| 98 | + <i className='fa fa-print' /> Print |
| 99 | + </Button> |
| 100 | + </div> |
| 101 | + <h1>Field Trip Plan: {schoolName} to {endLocation}</h1> |
| 102 | + </div> |
| 103 | + <div> |
| 104 | + <ul style={{ listStyle: 'none', padding: 0 }}> |
| 105 | + <li><b>Teacher</b>: <Val>{teacherName}</Val> ({schoolName}, Grade: <Val>{grade}</Val>)</li> |
| 106 | + <li><b>Teacher Address</b>: <Val>{address}</Val></li> |
| 107 | + <li><b>Phone</b>: <Val>{phoneNumber}</Val> / Fax: <Val>{faxNumber}</Val></li> |
| 108 | + <li><b>Email</b>: <Val>{emailAddress}</Val></li> |
| 109 | + <li><b>Students Age 7 and Over</b>: {numStudents || 0}</li> |
| 110 | + <li><b>Students Age 6 and Under</b>: {numFreeStudents || 0}</li> |
| 111 | + <li><b>Chaperones</b>: {numChaperones || 0}</li> |
| 112 | + <li><i>Request submitted: {timeStamp}</i></li> |
| 113 | + </ul> |
| 114 | + </div> |
| 115 | + |
| 116 | + <div> |
| 117 | + <h2>Outbound Trip (to Destination)</h2> |
| 118 | + <p><i>No Outbound Trip Planned</i></p> |
| 119 | + {/* outboundTrip |
| 120 | + ? outboundTrip.groupItineraries?.map((groupItin, i) => { |
| 121 | + //const itinerary = JSON.parse(groupItin.itinData) |
| 122 | + return ( |
| 123 | + <div key={i}> |
| 124 | + <PrintableItinerary |
| 125 | + config={config} |
| 126 | + //itinerary={itinerary} |
| 127 | + LegIcon={LegIcon} |
| 128 | + /> |
| 129 | + <TripDetails itinerary={itinerary} /> |
| 130 | + </div> |
| 131 | + ) |
| 132 | + }) |
| 133 | + : <p><i>No Outbound Trip Planned</i></p> |
| 134 | + */} |
| 135 | + </div> |
| 136 | + <div> |
| 137 | + <h2>Inbound Trip (to Destination)</h2> |
| 138 | + <p><i>No Inbound Trip Planned</i></p> |
| 139 | + </div> |
| 140 | + |
| 141 | + {/* The map, if visible */} |
| 142 | + {this.state.mapVisible && |
| 143 | + <div className='map-container'> |
| 144 | + <DefaultMap /> |
| 145 | + </div> |
| 146 | + } |
| 147 | + </div> |
| 148 | + ) |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +// connect to the redux store |
| 153 | + |
| 154 | +const mapStateToProps = (state, ownProps) => { |
| 155 | + const requestId = parseInt(state.router.location.query.requestId) |
| 156 | + const { requests } = state.callTaker.fieldTrip |
| 157 | + const request = requests.data.find(req => req.id === requestId) |
| 158 | + return { |
| 159 | + request, |
| 160 | + requestId, |
| 161 | + session: state.callTaker.session |
| 162 | + } |
| 163 | +} |
| 164 | + |
| 165 | +const mapDispatchToProps = { |
| 166 | + fetchFieldTripDetails: fieldTripActions.fetchFieldTripDetails, |
| 167 | + fetchFieldTrips: fieldTripActions.fetchFieldTrips, |
| 168 | + initializeModules: callTakerActions.initializeModules |
| 169 | +} |
| 170 | + |
| 171 | +export default connect(mapStateToProps, mapDispatchToProps)(PrintFieldTripLayout) |
0 commit comments