diff --git a/src/client.js b/src/client.js index 7487e93..4cbe069 100644 --- a/src/client.js +++ b/src/client.js @@ -8,6 +8,10 @@ import { Router, hashHistory, browserHistory } from 'react-router'; import { syncHistoryWithStore, routerMiddleware } from 'react-router-redux'; import reducers from './reducers'; import Instance from './components/Connection'; +import { + loggedUser, + visitReporter, +} from 'utils/authorization'; const middleware = routerMiddleware(hashHistory); const store = createStore( @@ -55,7 +59,15 @@ const rootRoute = { onChange: requireAuth, onEnter: requireAuth, component: require('./containers/App'), - indexRoute: { onEnter: (nextState, replace) => replace('/app/table/rides') }, + indexRoute: { + onEnter: (nextState, replace) => { + if (loggedUser.anyOf(visitReporter)) { + replace('/app/form/visit/' + loggedUser.useruuid) + } else { + replace('/app/table/rides'); + } + } + }, childRoutes: [ require('./routes/app'), require('./routes/404'), diff --git a/src/components/Header/NavRightList.js b/src/components/Header/NavRightList.js index 7979607..1e1f6c1 100644 --- a/src/components/Header/NavRightList.js +++ b/src/components/Header/NavRightList.js @@ -4,6 +4,13 @@ import MenuItem from 'material-ui/MenuItem'; import IconButton from 'material-ui/IconButton/IconButton'; import { hashHistory } from 'react-router'; +import { + loggedUser, + planScheduler, + providerScheduler, + visitReporter, +} from 'utils/authorization'; + const ImgIconButtonStyle = { width: '60px', height: '60px' @@ -28,6 +35,7 @@ class NavRightList extends React.Component { handleChange = (event, value) => { hashHistory.push(value); } + componentDidMount() { const user = JSON.parse(localStorage.getItem('loggedUser')); if (user) { @@ -40,6 +48,8 @@ class NavRightList extends React.Component { - ); - } -} - -module.exports = NavRightList; + ); + } + } + + module.exports = NavRightList; diff --git a/src/components/Shared/ValidationErrorsInfoDialog.js b/src/components/Shared/ValidationErrorsInfoDialog.js index f0efe0c..c3ed35a 100644 --- a/src/components/Shared/ValidationErrorsInfoDialog.js +++ b/src/components/Shared/ValidationErrorsInfoDialog.js @@ -8,11 +8,17 @@ export class ValidationErrorsInfoDialog extends React.Component { this.props = props; this.state = { open: this.props.open, + title: "Errors", } } componentWillReceiveProps(newProps) { - this.setState({ open: newProps.open }); + let title = this.state.title; + if (newProps.errorTitle) { + title = newProps.errorTitle; + } + + this.setState({ open: newProps.open, title: title }); } handleOpen = () => { @@ -38,7 +44,7 @@ export class ValidationErrorsInfoDialog extends React.Component { return (
{ this.nav = c; }}> {loggedUser.anyOf(visitReporter) && -
  • Create Visit
  • +
  • + scheduleVisits +
      +
    • Add Visit
    • +
    +
  • } + + {!loggedUser.anyOf(visitReporter) && +
  • directions_carRides
      @@ -158,6 +166,8 @@ class SidebarContent extends React.Component { }
    • +
    • Log Out
    • +
    ); } diff --git a/src/routes/app/components/MainApp.js b/src/routes/app/components/MainApp.js index 6b79472..acdbfd4 100644 --- a/src/routes/app/components/MainApp.js +++ b/src/routes/app/components/MainApp.js @@ -5,6 +5,10 @@ import Footer from 'components/Footer'; import Notifications from 'components/Notifications'; import Notification from 'components/Shared/Notification'; import GeolocationService from './Geolocation'; +import { + loggedUser, + visitReporter, +} from 'utils/authorization'; class MainApp extends React.Component { constructor(props) { @@ -53,8 +57,9 @@ class MainApp extends React.Component {
  • - - {/* */} + {!loggedUser.anyOf(visitReporter) && + + } ); } diff --git a/src/routes/app/components/NEMTLocation.js b/src/routes/app/components/NEMTLocation.js index b2120f3..005f8db 100644 --- a/src/routes/app/components/NEMTLocation.js +++ b/src/routes/app/components/NEMTLocation.js @@ -151,7 +151,9 @@ export class NEMTLocation extends React.Component { long: 0, name: '', address: '', - } + }, + searchingProvider: false, + providerList: [], } this.addCustomLabel = this.addCustomLabel.bind(this); @@ -257,7 +259,7 @@ export class NEMTLocation extends React.Component { return p; }); - this.setState(Object.assign(this.state, { nearbyPlaces: nearByPlaces, providers: providers })); + this.setState(Object.assign(this.state, { nearbyPlaces: nearByPlaces, providers: providers, providerList: nearByPlaces })); } }); } else { @@ -343,7 +345,7 @@ export class NEMTLocation extends React.Component { buttonText = buttonText.substring(0, self.state.textSize); buttonText += '...'; } - self.setState(Object.assign(self.state, { buttonValue: buttonText, inputValue: name.address })); + self.setState(Object.assign(self.state, { buttonValue: buttonText, inputValue: name.address, searchingProvider: false, providerList: [] })); }).catch(console.error); } @@ -569,7 +571,7 @@ export class NEMTLocation extends React.Component { updateTextSearch(searchText, dtSource, params) { let self = this; - self.setState(Object.assign(self.state, { inputValue: searchText })); + self.setState(Object.assign(self.state, { inputValue: searchText, searchingProvider: true })); if (searchText.length >= 3) { let lat = 0; let long = 0; @@ -618,9 +620,11 @@ export class NEMTLocation extends React.Component { clickResult.npi = p.fivePartKeyGroups[0].providerNum; } - return p; + var listItem = (} onClick={(event) => this.handlePlaceChanged(clickResult)} />) + return listItem; }); - this.setState(Object.assign(this.state, { providers: providers })); + + this.setState(Object.assign(this.state, { providerList: providers })); dtSource = self.state.providers; } }); @@ -1331,14 +1335,14 @@ export class NEMTLocation extends React.Component { {customAddresses} } leftIcon={} onClick={(e) => this.handleAddAddress(e, 'custom')} /> ) - autosuggest = () + autosuggest = () } else { - autosuggest = () + autosuggest = () } let listItem = (
    - + {autosuggest} {this.state.currentLocation} @@ -1352,8 +1356,21 @@ export class NEMTLocation extends React.Component { {this.state.nearbyPlaces} -
    + ) + + if (this.state.searchingProvider) { + listItem = ( +
    + + {autosuggest} + + {this.state.providerList} + +
    + ) + } + if (this.state.addLocation) { listItem = (
    diff --git a/src/routes/app/routes/forms/routes/visit/components/VerticalNonLinear.js b/src/routes/app/routes/forms/routes/visit/components/VerticalNonLinear.js index 938fd7b..a8a7f15 100644 --- a/src/routes/app/routes/forms/routes/visit/components/VerticalNonLinear.js +++ b/src/routes/app/routes/forms/routes/visit/components/VerticalNonLinear.js @@ -715,18 +715,42 @@ class VerticalNonLinear extends React.Component { "gender": self.state.user.gender, "member": self.state.user.member, "birthdate": self.state.user.birthdate, - "type": self.state.user.type, + "type": "S", "email": self.state.user.email, "phonenumber": self.state.user.phonenumber }, "visit_datetime": self.state.visitTime, "pickup_datetime": self.state.pickupTime, "external_id": self.state.visit_external_id, - "provider": self.state.destination.raw + "raw_provider": self.state.destination.raw }; Instance.getRawConn().post('/v1/nemt/visits/', visit).then(function (res) { - window.location.href = '/#/app/table/visits'; + const returnMessage = [ + { + message: `Member: ${res.data.user.name} (${res.data.user.member}` + }, + { + message: `Gender: ${res.data.user.gender}` + }, + { + message: `Birth date: ${visit.user.type}` + }, + { + message: `Member Type: ${res.data.user.birthdate}` + }, + { + message: `Provider: ${res.data.provider.name}` + }, + { + message: `Date: ${res.data.visit_datetime}` + }] + + self.setState(Object.assign(self.state, { + showValidationErrors: true, + validationErrors: returnMessage, + errorTitle: "Visit Added" + })); }).catch(console.error); break; default: @@ -860,7 +884,7 @@ class VerticalNonLinear extends React.Component { )} {step === 2 && (
    - + */} - {this.renderStepActions(1, this)} + {this.renderStepActions(2, this)} diff --git a/src/routes/app/routes/tables/routes/visits/components/Datatable.js b/src/routes/app/routes/tables/routes/visits/components/Datatable.js index edc66b8..a440c38 100644 --- a/src/routes/app/routes/tables/routes/visits/components/Datatable.js +++ b/src/routes/app/routes/tables/routes/visits/components/Datatable.js @@ -40,7 +40,7 @@ const getDTList = function (member) { member.forEach((r, i) => { let bookRide = ''; if (r.trip_type.key === 'no_trip') { - bookRide = (Book Ride) + bookRide = (Book Ride ) } list.push( @@ -48,8 +48,8 @@ const getDTList = function (member) { {moment(r.visit_datetime).format('MM/DD/YYYY - h:mm a')} {r.provider.name} {r.user.name} - {bookRide} - + + {bookRide} {r.user.member} {r.provider.provider_uuid} {r.visit_uuid} @@ -236,7 +236,7 @@ class DatatableComponent extends React.Component { Visit Time Provider Member - Ride + {/* Ride */} Rides Subscriber ID Provider ID diff --git a/src/routes/login/components/Login.js b/src/routes/login/components/Login.js index 3c0d438..5102e9b 100644 --- a/src/routes/login/components/Login.js +++ b/src/routes/login/components/Login.js @@ -8,6 +8,10 @@ import Dialog from 'material-ui/Dialog'; import Instance from '../../../components/Connection'; +import { + loggedUser +} from 'utils/authorization'; + class Login extends React.Component { constructor(props) { super(props); @@ -75,9 +79,10 @@ class Login extends React.Component { let auth = res.data; state.setCookie('token', auth.token, auth.valid_time); localStorage.setItem('loggedUser', JSON.stringify(auth.user)); - Instance.setToken(auth.token); + loggedUser.update(); + location.href = '/#/'; }).catch(function (err) { state.setState(Object.assign(state.state, { diff --git a/src/utils/authorization/loggedUser.js b/src/utils/authorization/loggedUser.js index 7869a25..36894a3 100644 --- a/src/utils/authorization/loggedUser.js +++ b/src/utils/authorization/loggedUser.js @@ -3,11 +3,11 @@ import { contains } from 'ramda'; import normalizeRoles from './normalizeRoles'; -const loggedUser = JSON.parse(window.localStorage.getItem('loggedUser')); +const loggedUser = () => { + let user = JSON.parse(window.localStorage.getItem('loggedUser')); -if (loggedUser) { - loggedUser.anyOf = (...profiles) => { - const userRole = loggedUser.profiles[0]; + const anyOf = (...profiles) => { + const userRole = user.profiles[0]; const userOrgType = userRole.organization.type.key; const roles = normalizeRoles(profiles); @@ -22,7 +22,18 @@ if (loggedUser) { } return false; - }; + } + + const update = () => { + user = JSON.parse(window.localStorage.getItem('loggedUser')); + return user; + } + + return { + user, + anyOf: anyOf, + update: update, + } } -export default loggedUser; +export default loggedUser();