From 659160676c505257f14ce7e803ea03dfe0db9b3d Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Tue, 22 May 2018 12:41:39 +0200 Subject: [PATCH] Upstream sync --- src/client.js | 1 + .../Shared/ValidationErrorsInfoDialog.js | 59 ++++ .../steppers/components/VerticalNonLinear.js | 55 +--- .../eligibility/components/eligibility.js | 26 +- src/routes/selfRegister/components/SignUp.js | 284 ++++++++++++++++++ src/routes/selfRegister/index.js | 8 + 6 files changed, 374 insertions(+), 59 deletions(-) create mode 100644 src/components/Shared/ValidationErrorsInfoDialog.js create mode 100644 src/routes/selfRegister/components/SignUp.js create mode 100644 src/routes/selfRegister/index.js diff --git a/src/client.js b/src/client.js index a71a334..c093ba0 100644 --- a/src/client.js +++ b/src/client.js @@ -65,6 +65,7 @@ const rootRoute = { require('./routes/lockScreen'), require('./routes/login'), require('./routes/signUp'), + require('./routes/selfRegister'), require('./routes/fullscreen'), require('./routes/ride'), require('./routes/ready'), diff --git a/src/components/Shared/ValidationErrorsInfoDialog.js b/src/components/Shared/ValidationErrorsInfoDialog.js new file mode 100644 index 0000000..c42fd6f --- /dev/null +++ b/src/components/Shared/ValidationErrorsInfoDialog.js @@ -0,0 +1,59 @@ +import React, { Component } from 'react'; +import Dialog from 'material-ui/Dialog'; +import FlatButton from 'material-ui/FlatButton'; + +export class ValidationErrorsInfoDialog extends React.Component { + + state = { + open: this.props.open, + } + + componentWillReceiveProps(newProps){ + this.setState({open: newProps.open}); + } + + handleOpen = () => { + this.setState({ open: true }); + }; + + handleClose = () => { + this.setState({ open: false }); + this.props.onDismiss(); + }; + + render() { + + const actions = [ + , + ]; + + return ( +
+ + {this.props.errorMessages.map(errorMessage => { + return ( +
+ {errorMessage.message} +
+
+ ); + })} +
+
+ ); + } + } + + module.exports = ValidationErrorsInfoDialog; \ No newline at end of file diff --git a/src/routes/app/routes/forms/routes/steppers/components/VerticalNonLinear.js b/src/routes/app/routes/forms/routes/steppers/components/VerticalNonLinear.js index ae4784d..1982d3a 100644 --- a/src/routes/app/routes/forms/routes/steppers/components/VerticalNonLinear.js +++ b/src/routes/app/routes/forms/routes/steppers/components/VerticalNonLinear.js @@ -30,6 +30,7 @@ import Close from 'material-ui/svg-icons/navigation/close' import CommunicationCall from 'material-ui/svg-icons/communication/call' import Message from 'material-ui/svg-icons/communication/message' import Instance from '../../../../../../../components/Connection'; +import ValidationErrorsInfoDialog from '../../../../../../../components/Shared/ValidationErrorsInfoDialog'; import Checkbox from 'material-ui/Checkbox'; import Popover from 'material-ui/Popover'; @@ -41,60 +42,6 @@ const roundingTime = 1000 * 60 * 5; //5 minutes DateTimeFormat = global.Intl.DateTimeFormat; -export class ValidationErrorsInfoDialog extends React.Component { - - state = { - open: this.props.open, - } - - componentWillReceiveProps(newProps){ - this.setState({open: newProps.open}); - } - - handleOpen = () => { - this.setState({ open: true }); - }; - - handleClose = () => { - this.setState({ open: false }); - this.props.onDismiss(); - }; - - render() { - - const actions = [ - , - ]; - - return ( -
- - {this.props.errorMessages.map(errorMessage => { - return ( - - ); - })} - -
- ); - } -} - export class DialogExampleSimple extends React.Component { state = { diff --git a/src/routes/app/routes/pages/routes/eligibility/components/eligibility.js b/src/routes/app/routes/pages/routes/eligibility/components/eligibility.js index f922094..ab0a29e 100644 --- a/src/routes/app/routes/pages/routes/eligibility/components/eligibility.js +++ b/src/routes/app/routes/pages/routes/eligibility/components/eligibility.js @@ -14,6 +14,7 @@ import RaisedButton from 'material-ui/RaisedButton'; import SelectField from 'material-ui/SelectField'; import Checkbox from 'material-ui/Checkbox'; import Instance from '../../../../../../../components/Connection'; +import ValidationErrorsInfoDialog from '../../../../../../../components/Shared/ValidationErrorsInfoDialog'; class SignUp extends React.Component { constructor(props) { @@ -34,7 +35,9 @@ class SignUp extends React.Component { gender: null, agreedTerms: false, validated: false, - memberType:"S" + memberType:"S", + showValidationErrors: false, + validationErrors:[] } componentDidMount = () => { @@ -58,7 +61,10 @@ class SignUp extends React.Component { "member": this.state.member, "email": this.state.email, "phonenumber": this.state.phonenumber, - "birthdate": this.state.birthdate.toISOString() + "birthdate": this.state.birthdate.toISOString(), + "consent" : this.state.agreedTerms, + "type": this.state.memberType + // "eligibility": { // "tracking_id": "1234567", // "payer": { @@ -99,9 +105,14 @@ class SignUp extends React.Component { // alert('NO benefits found for this member'); // } }).catch(function (err) { - console.log('Error to get eligibility: ', err); - alert('NO benefits found for this member'); - this.handleRequestClose(); + if (err.response.status === 422){ + //Unprocessable Entity (validation failed) + state.setState(Object.assign(state.state, {showValidationErrors:true, validationErrors:err.response.data.data})) + }else{ + console.log('Error to get eligibility: ', err); + alert('NO benefits found for this member'); + this.handleRequestClose(); + } }); } @@ -173,10 +184,15 @@ class SignUp extends React.Component { this.setState(Object.assign(this.state, { validated: validated })); } + handleValidationErrosDialogDismiss(){ + this.setState(Object.assign(this.state, {showValidationErrors:false})); + } + render() { return (
+
{ + } + + buttonValidated = () => { + let validated = true; + if (!this.state.provider_name || this.state.provider_name === null || this.state.provider_name === "") validated = false; + if (!this.state.provider_npi || this.state.provider_npi === null || this.state.provider_npi === "") validated = false; + if (!this.state.email || this.state.email === null || this.state.email === "") validated = false; + if (!this.state.phone_number || this.state.phone_number === null || this.state.phone_number === "") validated = false; + if (!this.state.first || this.state.first === null || this.state.first === "") validated = false; + if (!this.state.last || this.state.last === null || this.state.last === "") validated = false; + if (!this.state.password_validated || !this.state.pass || this.state.pass === null || this.state.pass === "") validated = false; + + this.setState(Object.assign(this.state, { validated: validated })); + } + + handleProviderName = (event) => { + this.setState(Object.assign(this.state, { provider_name: event.target.value })); + }; + + handleProviderNPI = (event) => { + this.setState(Object.assign(this.state, { provider_npi: event.target.value })); + }; + + handleFirst = (event) => { + this.setState(Object.assign(this.state, { first: event.target.value })); + }; + + handleLast = (event) => { + this.setState(Object.assign(this.state, { last: event.target.value })); + }; + + handleEmail = (event) => { + this.setState(Object.assign(this.state, { email: event.target.value })); + }; + + handlePhone = (event) => { + let phone = event.target.value; + if (phone.indexOf("+1") < 0 && phone.length == 10) { + phone = "+1" + phone; + phone = phone.substring(0, 12); + } + + this.setState(Object.assign(this.state, { phone_number: phone })); + }; + + handlePass = (event) => { + this.setState(Object.assign(this.state, { pass: btoa(event.target.value) })); + this.setState(Object.assign(this.state, { password_validated: this.state.pass === this.state.passConfirmation })); + }; + + handleConfirmationPass = (event) => { + this.setState(Object.assign(this.state, { passConfirmation: btoa(event.target.value) })); + this.setState(Object.assign(this.state, { password_validated: this.state.pass === this.state.passConfirmation })); + }; + + clickEvent = (event) => { + event.preventDefault(); + const state = this; + + let user = { + "provider": + { + "org_name": this.state.provider_name, + "internal_id": this.state.provider_npi + }, + "name": this.state.first + ' ' + this.state.last, + "first": this.state.first, + "last": this.state.last, + "email": this.state.email, + "phonenumber": this.state.phone_number, + "pass": this.state.pass, + }; + + Instance.getRawConn().post('/v1/selfregister/', user).then(function (res) { + localStorage.removeItem('loggedUser'); + location.href = '/#/login'; + }).catch(function (err) { + if (err.response.status === 422) { + //Unprocessable Entity (validation failed) + state.setState(Object.assign(state.state, { + showValidationErrors: true, + validationErrors: err.response.data.data + })); + } else { + alert('Error to log in: ' + err.message); + } + console.error(err); + }); + } + + handleDismiss() { + this.setState(Object.assign(this.state, { showErrorMessage: false })); + } + + render() { + let validationErrors = null; + if (this.state.showValidationErrors) { + validationErrors = ( +
    + {this.state.validationErrors.map(errorMessage => { + const oneValidationMessage = (
  • {errorMessage.message}
  • ); + const oneValidationMessageWithTab = (
  • {errorMessage.message}
  • ); + + if (errorMessage.field_name === "password-tab") { + return oneValidationMessageWithTab; + } else { + return oneValidationMessage; + } + })} +
+ ); + } + + return ( +
+ +
+
+
+

CHMHub®

+
+ + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
+

By clicking on sign up, you agree to terms and privacy policy

+
+
+
+ {validationErrors} +
+
+ +
+
+ Login + +
+
+ +
+ ); + } +} + +const Page = () => ( +
+
+ +
+ +
+
+
+
+); + +module.exports = Page; diff --git a/src/routes/selfRegister/index.js b/src/routes/selfRegister/index.js new file mode 100644 index 0000000..008287b --- /dev/null +++ b/src/routes/selfRegister/index.js @@ -0,0 +1,8 @@ +module.exports = { + path: 'selfRegister', + getComponent(nextState, cb) { + require.ensure([], (require) => { + cb(null, require('./components/SignUp')); + }); + } +};