diff --git a/src/client.js b/src/client.js index c093ba0..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( @@ -29,8 +33,8 @@ const isFunction = (functionToCheck) => { }; const requireAuth = (nextState, replace, next) => { - if (nextState.location.pathname === '/login' || nextState.location.pathname === '/sign-up' || (nextState.location.pathname.indexOf('/ride') > -1 && nextState.params.ride_uuid !== undefined && nextState.params.user_uuid !== undefined) - || (!isFunction(replace) && (replace.location.pathname === '/login' || replace.location.pathname === '/sign-up' || (replace.location.pathname.indexOf('/ride') > -1 && replace.params.ride_uuid !== undefined && replace.params.user_uuid !== undefined)))) { + if (nextState.location.pathname === '/login' || nextState.location.pathname === '/sign-up' || nextState.location.pathname === '/selfRegister' || (nextState.location.pathname.indexOf('/ride') > -1 && nextState.params.ride_uuid !== undefined && nextState.params.user_uuid !== undefined) + || (!isFunction(replace) && (replace.location.pathname === '/login' || replace.location.pathname === '/sign-up' || nextState.location.pathname === '/selfRegister' || (replace.location.pathname.indexOf('/ride') > -1 && replace.params.ride_uuid !== undefined && replace.params.user_uuid !== undefined)))) { next(); } @@ -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 0adb952..005f8db 100644 --- a/src/routes/app/components/NEMTLocation.js +++ b/src/routes/app/components/NEMTLocation.js @@ -115,6 +115,7 @@ export class NEMTLocation extends React.Component { long: 0 }, providers: [], + locations: [], currentSelection: { id: 0, name: "", @@ -125,6 +126,7 @@ export class NEMTLocation extends React.Component { saved: false, }, inputValue: "", + locationValue: "", addLocation: false, searchAddresses: [], addLocationText: '', @@ -143,7 +145,15 @@ export class NEMTLocation extends React.Component { id: '', name: '', address: '', - } + }, + centerLocation: { + lat: 0, + long: 0, + name: '', + address: '', + }, + searchingProvider: false, + providerList: [], } this.addCustomLabel = this.addCustomLabel.bind(this); @@ -164,6 +174,8 @@ export class NEMTLocation extends React.Component { this.updateLocation = this.updateLocation.bind(this); this.handleGetClosestPlace = this.handleGetClosestPlace.bind(this); + this.updateLocationValue = this.updateLocationValue.bind(this); + this.handleAutoCompleteLocation = this.handleAutoCompleteLocation.bind(this); // this.updateLocation().then(console.log); @@ -184,52 +196,71 @@ export class NEMTLocation extends React.Component { } geoSuccess = (position) => { + let lat = 0; + let long = 0; + if (this.state.centerLocation.lat !== 0 && this.state.centerLocation.long !== 0) { + lat = this.state.centerLocation.lat; + long = this.state.centerLocation.long; + } else { + const geo = GeolocationService.GetCoordinates(); + lat = geo.lat; + long = geo.long; + } - const geo = GeolocationService.GetCoordinates(); - // self.updateLocation().then(p => { - let lat = geo.lat; - let long = geo.long; + if (lat === 0 || long === 0) { + lat = 41.886406; + long = -87.624225; + } this.locateNearby(lat, long) } locateNearby = (lat, long) => { + if (lat === 0 || long === 0) { lat = 41.886406; long = -87.624225; } + if (this.state.locationType === 'provider') { - Instance.getRawConn().get(`/v1/nemt/provider/participating?sort=distance&lat=${lat}&long=${long}`).then(res => { + let url = `/v1/nemt/provider?lat=${lat}&long=${long}&limit=50&sortby=distance` + Instance.getRawConn().get(url).then(res => { let nearByPlaces = []; - let providers = res.data.map(p => { - if (p.address.street_address_1) { - const streetNumber = p.address.street_address_1.split(' ')[0] + if (res.data.resultStatus === 'SUCCESS') { + let providers = res.data.providers.map(p => { + const streetNumber = p.streetName_1.split(' ')[0] let clickResult = { - id: p.muk_id, - address: `${p.address.street_address_1}, ${p.address.city}, ${p.address.state} (${p.address.zipcode})`, - lat: p.address.lat, - lng: p.address.long, - name: p.name, - type: "provider", + id: p.mukId, + muk_id: p.mukId, + address: `${p.streetName_1}, ${p.cityName}, ${p.state} (${p.zipCode.substr(0, 5)})`, + lat: parseFloat(p.latitude), + lng: parseFloat(p.longitude), + name: p.providerName, + type: 'provider', raw: p, street_number: streetNumber, - street: p.address.street_address_1.replace(streetNumber, '').trim(), - city: p.address.city, - state: p.address.state, - zipcode: p.address.zipcode.substring(0, 5), - country: p.address.country, + street: p.streetName_1.replace(streetNumber, '').trim(), + city: p.cityName, + state: p.state, + zipcode: p.zipCode.substr(0, 5), + country: p.country, saved: false, } - clickResult.address = `${clickResult.street_number} ${clickResult.street}, ${clickResult.city}` - var listItem = (} onClick={(event) => this.handlePlaceChanged(clickResult)} />) + if (p.fivePartKeyGroups.length > 0) { + clickResult.npi = p.fivePartKeyGroups[0].providerNum; + } + + var listItem = (} onClick={(event) => this.handlePlaceChanged(clickResult)} />) nearByPlaces.push(listItem); - p.providerText = `${p.name} - ${p.address.street_address_1}, ${p.address.city}, ${p.address.state} (${p.address.zipcode}) (${p.address.phone_number})` - } - return p; - }); + p.providerText = `${p.providerName} - ${p.streetName_1}, ${p.cityName}, ${p.state} (${p.zipCode.substr(0, 5)}) (${p.phoneNumber})` + p.muk_id = p.mukId - this.setState(Object.assign(this.state, { nearbyPlaces: nearByPlaces, providers: providers })); + return p; + }); + + this.setState(Object.assign(this.state, { nearbyPlaces: nearByPlaces, providers: providers, providerList: nearByPlaces })); + } }); } else { var pyrmont = new google.maps.LatLng(lat, long); @@ -314,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); } @@ -495,28 +526,105 @@ export class NEMTLocation extends React.Component { this.locateNearby(41.886406, -87.624225); } + updateLocationValue(searchText, dtSource, params) { + let self = this; + self.setState(Object.assign(self.state, { locationValue: searchText })); + + if (searchText.length >= 3) { + let lat = 0; + let long = 0; + if (this.state.centerLocation.lat !== 0 && this.state.centerLocation.long !== 0) { + lat = this.state.centerLocation.lat; + long = this.state.centerLocation.long; + } else { + const geo = GeolocationService.GetCoordinates(); + lat = geo.lat; + long = geo.long; + } + + if (lat === 0 || long === 0) { + lat = 41.886406; + long = -87.624225; + } + + var location = new google.maps.LatLng(lat, long); + var request = { + location: location, + radius: '500', + input: searchText, + componentRestrictions: { country: 'us' }, + }; + const callback = (results, status) => { + if (status == google.maps.places.PlacesServiceStatus.OK) { + var googlePlaces = results.map(place => { + place.providerText = place.description; + place.muk_id = place.id; + place.saved = false; + return place; + }); + self.setState(Object.assign(self.state, { locations: googlePlaces })); + } + } + service.getPlacePredictions(request, callback); + } + } + 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 = self.state.geolocation.lat; - let long = self.state.geolocation.long; + let lat = 0; + let long = 0; + if (this.state.centerLocation.lat !== 0 && this.state.centerLocation.long !== 0) { + lat = this.state.centerLocation.lat; + long = this.state.centerLocation.long; + } else { + const geo = GeolocationService.GetCoordinates(); + lat = geo.lat; + long = geo.long; + } + if (lat === 0 || long === 0) { lat = 41.886406; long = -87.624225; } if (self.state.locationType === 'provider') { - //let url = `/v1/nemt/provider?lat=${lat}&long=${long}&limit=20&name=${searchText}&sortby=distance` - let url = `/v1/nemt/provider/participating?lat=${lat}&long=${long}&query=${searchText}&sortby=distance` + let url = `/v1/nemt/provider?lat=${lat}&long=${long}&limit=50&name=${searchText}&sortby=distance` Instance.getRawConn().get(encodeURI(url)).then(res => { - if (res.data.length > 0) { - let places = res.data.map(p => { - p.providerText = `${p.name} - ${p.address.street_address_1}, ${p.address.city}, ${p.address.state} (${p.address.zipcode}) (${p.address.phone_number})` - p.saved = false - return p; - }) - self.setState(Object.assign(self.state, { providers: places })); + if (res.data.resultStatus === 'SUCCESS') { + let providers = res.data.providers.map(p => { + const streetNumber = p.streetName_1.split(' ')[0] + p.providerText = `${p.providerName} - ${p.streetName_1}, ${p.cityName}, ${p.state} (${p.zipCode.substr(0, 5)}) (${p.phoneNumber})` + p.muk_id = p.mukId + + let clickResult = { + id: p.mukId, + muk_id: p.mukId, + address: `${p.streetName_1}, ${p.cityName}, ${p.state} (${p.zipCode.substr(0, 5)})`, + lat: parseFloat(p.latitude), + lng: parseFloat(p.longitude), + name: p.providerName, + type: 'provider', + raw: p, + street_number: streetNumber, + street: p.streetName_1.replace(streetNumber, '').trim(), + city: p.cityName, + state: p.state, + zipcode: p.zipCode.substr(0, 5), + country: p.country, + saved: false, + } + + if (p.fivePartKeyGroups.length > 0) { + clickResult.npi = p.fivePartKeyGroups[0].providerNum; + } + + var listItem = (} onClick={(event) => this.handlePlaceChanged(clickResult)} />) + return listItem; + }); + + this.setState(Object.assign(this.state, { providerList: providers })); dtSource = self.state.providers; } }); @@ -554,42 +662,59 @@ export class NEMTLocation extends React.Component { this.setState(Object.assign(this.state, { addLocationTextValue: providerSearch })); if (providerSearch.length >= 3) { - const geo = GeolocationService.GetCoordinates(); - let lat = geo.lat; - let long = geo.long; + + let lat = 0; + let long = 0; + if (this.state.centerLocation.lat !== 0 && this.state.centerLocation.long !== 0) { + lat = this.state.centerLocation.lat; + long = this.state.centerLocation.long; + } else { + const geo = GeolocationService.GetCoordinates(); + lat = geo.lat; + long = geo.long; + } + if (lat === 0 || long === 0) { lat = 41.886406; long = -87.624225; } + if (this.state.locationType === 'provider') { - let url = `/v1/nemt/provider/participating?lat=${lat}&long=${long}&query=${providerSearch}&sortby=distance` + let url = `/v1/nemt/provider?lat=${lat}&long=${long}&limit=50&name=${providerSearch}&sortby=distance` Instance.getRawConn().get(encodeURI(url)).then(res => { - let places = res.data.map(p => { - const streetNumber = p.address.street_address_1.split(' ')[0] - p.providerText = `${p.name} - ${p.address.street_address_1}, ${p.address.city}, ${p.address.state} (${p.address.zipcode}) (${p.address.phone_number})` - let clickResult = { - id: p.muk_id, - address: `${p.address.street_address_1}, ${p.address.city}, ${p.address.state} (${p.address.zipcode})`, - lat: p.address.lat, - lng: p.address.long, - name: p.name, - type: "provider", - raw: p, - street_number: streetNumber, - street: p.address.street_address_1.replace(streetNumber, '').trim(), - city: p.address.city, - state: p.address.state, - zipcode: p.address.zipcode.substring(0, 5), - country: p.address.country, - saved: false, - } - clickResult.address = `${clickResult.street_number} ${clickResult.street}, ${clickResult.city}` + if (res.data.resultStatus === 'SUCCESS') { + let providers = res.data.providers.map(p => { + const streetNumber = p.streetName_1.split(' ')[0] + p.providerText = `${p.providerName} - ${p.streetName_1}, ${p.cityName}, ${p.state} (${p.zipCode.substr(0, 5)}) (${p.phoneNumber})` + p.muk_id = p.mukId - var listItem = (} onClick={(event) => this.handleSaveAddress(clickResult, this)} />) - return listItem; - }); + let clickResult = { + id: p.mukId, + muk_id: p.mukId, + address: `${p.streetName_1}, ${p.cityName}, ${p.state} (${p.zipCode.substr(0, 5)})`, + lat: parseFloat(p.latitude), + lng: parseFloat(p.longitude), + name: p.providerName, + type: 'provider', + raw: p, + street_number: streetNumber, + street: p.streetName_1.replace(streetNumber, '').trim(), + city: p.cityName, + state: p.state, + zipcode: p.zipCode.substr(0, 5), + country: p.country, + saved: false, + } - this.setState(Object.assign(this.state, { searchAddresses: places })); + if (p.fivePartKeyGroups.length > 0) { + clickResult.npi = p.fivePartKeyGroups[0].providerNum; + } + + var listItem = (} onClick={(event) => this.handleSaveAddress(clickResult)} />) + return listItem; + }); + this.setState(Object.assign(this.state, { searchAddresses: providers })); + } }); } else { var location = new google.maps.LatLng(lat, long); @@ -716,6 +841,68 @@ export class NEMTLocation extends React.Component { } } + handleAutoCompleteLocation = (location) => { + const self = this; + placeService.getDetails(location, (result, status) => { + if (status == google.maps.places.PlacesServiceStatus.OK) { + let clickResult = { + id: result.place_id, + placeId: result.place_id, + address: result.formatted_address ? result.formatted_address : result.vicinity, + lat: result.geometry.location.lat(), + lng: result.geometry.location.lng(), + name: result.name, + type: "google", + raw: result, + street_number: '', + street: '', + city: '', + state: '', + zipcode: '', + country: '', + saved: false, + } + + result.address_components.forEach(a => { + a.types.forEach(c => { + switch (c) { + case "street_number": + clickResult.street_number = a.short_name; + break; + case "route": + clickResult.street = a.short_name; + break; + case "locality": + clickResult.city = a.short_name; + break; + case "administrative_area_level_1": + clickResult.state = a.short_name; + break; + case "country": + clickResult.country = a.short_name; + break; + case "postal_code": + clickResult.zipcode = a.short_name; + break; + } + }, this) + }, this); + clickResult.address = `${clickResult.street_number} ${clickResult.street}, ${clickResult.city}` + + + const centerLocation = { + lat: clickResult.lat, + long: clickResult.lng, + name: clickResult.name, + address: clickResult.address + } + + self.setState(Object.assign(self.state, { centerLocation: centerLocation })); + self.locateNearby(clickResult.lat, clickResult.lng); + } + }); + } + handleAutocomplete = (provider) => { const sendInfo = (clickResult) => { this.setState(Object.assign(this.state, { currentSelection: clickResult })); @@ -735,24 +922,32 @@ export class NEMTLocation extends React.Component { } if (this.state.locationType === "provider") { - const streetNumber = provider.address.street_address_1.split(' ')[0] + const p = provider; + const streetNumber = p.streetName_1.split(' ')[0] + p.providerText = `${p.providerName} - ${p.streetName_1}, ${p.cityName}, ${p.state} (${p.zipCode.substr(0, 5)}) (${p.phoneNumber})` + p.muk_id = p.mukId + let clickResult = { - id: provider.muk_id, - address: `${provider.address.street_address_1}, ${provider.address.city}, ${provider.address.state} (${provider.address.zipcode})`, - lat: provider.address.lat, - lng: provider.address.long, - name: provider.name, - type: "provider", - raw: provider, + id: p.mukId, + muk_id: p.mukId, + address: `${p.streetName_1}, ${p.cityName}, ${p.state} (${p.zipCode.substr(0, 5)})`, + lat: parseFloat(p.latitude), + lng: parseFloat(p.longitude), + name: p.providerName, + type: 'provider', + raw: p, street_number: streetNumber, - street: provider.address.street_address_1.replace(streetNumber, '').trim(), - city: provider.address.city, - state: provider.address.state, - zipcode: provider.address.zipcode.substring(0, 5), - country: provider.address.country, + street: p.streetName_1.replace(streetNumber, '').trim(), + city: p.cityName, + state: p.state, + zipcode: p.zipCode.substr(0, 5), + country: p.country, saved: false, } - clickResult.address = `${clickResult.street_number} ${clickResult.street}, ${clickResult.city}` + + if (p.fivePartKeyGroups.length > 0) { + clickResult.npi = p.fivePartKeyGroups[0].providerNum; + } sendInfo(clickResult); } else { @@ -842,42 +1037,51 @@ export class NEMTLocation extends React.Component { handleCurrentLocation(e) { const self = this; - const geo = GeolocationService.GetCoordinates(); - // self.updateLocation().then(p => { - let lat = geo.lat; - let long = geo.long; + + let lat = 0; + let long = 0; + if (this.state.centerLocation.lat !== 0 && this.state.centerLocation.long !== 0) { + lat = this.state.centerLocation.lat; + long = this.state.centerLocation.long; + } else { + const geo = GeolocationService.GetCoordinates(); + lat = geo.lat; + long = geo.long; + } + if (lat === 0 || long === 0) { lat = 41.886406; long = -87.624225; } if (self.state.locationType === 'provider') { - Instance.getRawConn().get(`/v1/nemt/provider/participating?sort=distance&lat=${lat}&long=${long}`).then(res => { + let url = `/v1/nemt/provider?lat=${lat}&long=${long}&limit=50&sortby=distance` + Instance.getRawConn().get(url).then(res => { let listItem = (} onClick={self.handleCurrentLocation} />) - if (res.data.length > 0) { - const result = res.data[0]; - const streetNumber = result.address.street_address_1.split(' ')[0] + if (res.data.resultStatus === 'SUCCESS') { + const p = res.data.providers[0]; + const streetNumber = p.streetName_1.split(' ')[0] let clickResult = { - id: result.muk_id, - address: `${result.address.street_address_1}, ${result.address.city}, ${result.address.state} (${result.address.zipcode})`, - lat: result.address.lat, - lng: result.address.long, - name: result.name, - type: "provider", - raw: result, + id: p.mukId, + address: `${p.streetName_1}, ${p.cityName}, ${p.state} (${p.zipCode.substr(0, 5)})`, + lat: parseFloat(p.latitude), + lng: parseFloat(p.longitude), + name: p.providerName, + type: 'provider', + raw: p, street_number: streetNumber, - street: result.address.street_address_1.replace(streetNumber, '').trim(), - city: result.address.city, - state: result.address.state, - zipcode: result.address.zipcode.substring(0, 5), - country: result.address.country, + street: p.streetName_1.replace(streetNumber, '').trim(), + city: p.cityName, + state: p.state, + zipcode: p.zipCode.substr(0, 5), + country: p.country, saved: false, } - clickResult.address = `${clickResult.street_number} ${clickResult.street}, ${clickResult.city}` + if (p.fivePartKeyGroups.length > 0) { + clickResult.npi = p.fivePartKeyGroups[0].providerNum; + } self.handlePlaceChanged(clickResult) - //listItem = (} onClick={(event) => self.handlePlaceChanged(clickResult)} />) } - //self.setState(Object.assign(self.state, { currentLocation: listItem })); }).catch(console.error); } else { var location = new google.maps.LatLng(lat, long); @@ -1131,13 +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} @@ -1151,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 = (
    @@ -1195,4 +1413,4 @@ export class NEMTLocation extends React.Component {
    ); } -} \ No newline at end of file +} \ No newline at end of file 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 81e75f0..a8a7f15 100644 --- a/src/routes/app/routes/forms/routes/visit/components/VerticalNonLinear.js +++ b/src/routes/app/routes/forms/routes/visit/components/VerticalNonLinear.js @@ -156,14 +156,8 @@ class SignUp extends React.Component { }; handlePhone = (event) => { - let phone = event.target.value; - if (phone.indexOf("+1") < 0 && phone.length == 10) { - phone = "+1" + phone; - phone = phone.substring(0, 12); - } - const user = this.props.user; - user.phonenumber = phone; + user.phonenumber = event.target.value;; if (this.props.onUserChanged) { this.props.onUserChanged(user); } @@ -674,10 +668,14 @@ class VerticalNonLinear extends React.Component { let self = state; const { stepIndex } = self.state; - console.log('Step Index: ', stepIndex) + //console.log('Step Index: ', stepIndex) switch (stepIndex) { - case 0: + case 1: const eligibility = { + "provider": { + "provider_npi": self.state.destination.raw.fivePartKeyGroups[0].providerNum, + "provider_name": self.state.destination.raw.providerName + }, "subscriber": { "patient_type": self.state.user.type, "subscriber_id": self.state.user.member, @@ -688,10 +686,12 @@ class VerticalNonLinear extends React.Component { "demographic_info": { "date_of_birth": self.state.user.birthdate, "gender": self.state.user.gender - } + }, + "user": self.state.user, } }; + console.log(JSON.stringify(eligibility)); Instance.getRawConn().post('/v1/nemt/eligibility', eligibility).then(function (res) { self.setState(Object.assign(self.state, { stepIndex: stepIndex + 1, user: res.data })); }).catch(err => { @@ -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.setState({ stepIndex: 0 })}> + Provider + + +
    + this.handleProviderChanged(provider, this)} fontSize={12} locationType="provider" loadSuggestion={true} address={this.state.destination} /> + {/*
    */} + + {this.renderStepActions(1, this)} + + + + this.setState({ stepIndex: 1 })}> Member @@ -1113,21 +1149,6 @@ class VerticalNonLinear extends React.Component { {this.renderStepActions(0, this)} - - - this.setState({ stepIndex: 1 })}> - Provider - - -
    - this.handleProviderChanged(provider, this)} fontSize={12} locationType="provider" loadSuggestion={true} address={this.state.destination} /> - {/*
    */} - - {this.renderStepActions(1, this)} - - - - this.setState({ stepIndex: 2 })}> Visit Details @@ -1159,7 +1180,7 @@ class VerticalNonLinear extends React.Component { {/* */} - {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/routes/selfRegister/components/SignUp.js b/src/routes/selfRegister/components/SignUp.js index 2820ed5..020c952 100644 --- a/src/routes/selfRegister/components/SignUp.js +++ b/src/routes/selfRegister/components/SignUp.js @@ -54,8 +54,7 @@ class SignUp extends React.Component { this.clickEvent = this.clickEvent.bind(this); } - componentDidMount = () => { - } + componentDidMount = () => { } buttonValidated = () => { let validated = true; @@ -128,7 +127,7 @@ class SignUp extends React.Component { "pass": this.state.pass, }; - Instance.getRawConn().post('/v1/selfregister/', user).then(function (res) { + Instance.setToken(null).post('/v1/selfregister/', user).then(function (res) { localStorage.removeItem('loggedUser'); location.href = '/#/login'; }).catch(function (err) { 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();