replace form validation messages with dialog

This commit is contained in:
GotPPay
2018-05-28 14:06:15 +02:00
parent bc888503b2
commit 4099c9231a
2 changed files with 29 additions and 56 deletions

View File

@@ -28,39 +28,29 @@ export class ValidationErrorsInfoDialog extends React.Component {
render() { render() {
const actions = [ return (
<FlatButton <div>
label="Dismiss" <Dialog
primary={true} title="Errors"
onClick={this.handleClose} actions={actions}
/>, modal={this.props.modal ? this.props.modal : false}
]; open={this.state.open}
onRequestClose={this.handleClose}
return ( overlayStyle={{ backgroundColor: 'transparent' }}
<div className="container"> >
{ {this.props.errorMessages.map(errorMessage => {
this.state.open && const oneValidationMessage = (<span><a>{errorMessage.message}</a><br /></span>);
<Dialog const oneValidationMessageWithTab = (<span><li style={{ marginLeft: 2 + "em" }}>{errorMessage.message}</li></span>);
title={this.props.title ? this.props.title : 'Error'}
isDraggable={this.props.draggable ? this.props.draggable : false} if (errorMessage.field_name === "password-tab") {
buttons={actions} return oneValidationMessageWithTab;
hasCloseIcon={false} } else {
modal={this.props.modal ? this.props.modal : false} return oneValidationMessage;
height={defaultDialogHeight + this.props.errorMessages.length * dialogHeightPerLine}
>
{this.props.errorMessages.map(errorMessage => {
return (
<div>
<a>{errorMessage.message}</a>
<br/>
</div>
);})
}
</Dialog>
} }
</div> })}
); </Dialog>
} </div>
);
} }
module.exports = ValidationErrorsInfoDialog; module.exports = ValidationErrorsInfoDialog;

View File

@@ -17,6 +17,8 @@ import Toggle from 'material-ui/Toggle';
import Snackbar from 'material-ui/Snackbar'; import Snackbar from 'material-ui/Snackbar';
import Instance from '../../../components/Connection'; import Instance from '../../../components/Connection';
import ValidationErrorsInfoDialog from '../../../components/Shared/ValidationErrorsInfoDialog';
class SignUp extends React.Component { class SignUp extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@@ -144,29 +146,13 @@ class SignUp extends React.Component {
}); });
} }
handleDismiss() { handleValidationErrosDialogDismiss() {
this.setState(Object.assign(this.state, { showErrorMessage: false })); this.setState(Object.assign(this.state, {
showValidationErrors: false
}));
} }
render() { render() {
let validationErrors = null;
if (this.state.showValidationErrors) {
validationErrors = (
<ul>
{this.state.validationErrors.map(errorMessage => {
const oneValidationMessage = (<li>{errorMessage.message}</li>);
const oneValidationMessageWithTab = (<span><li style={{ marginLeft: 2 + "em" }}>{errorMessage.message}</li></span>);
if (errorMessage.field_name === "password-tab") {
return oneValidationMessageWithTab;
} else {
return oneValidationMessage;
}
})}
</ul>
);
}
return ( return (
<div className="body-inner"> <div className="body-inner">
@@ -245,10 +231,7 @@ class SignUp extends React.Component {
<div className="form-group"> <div className="form-group">
<p className="text-small">By clicking on sign up, you agree to <a href="javascript:;"><i>terms</i></a> and <a href="javascript:;"><i>privacy policy</i></a></p> <p className="text-small">By clicking on sign up, you agree to <a href="javascript:;"><i>terms</i></a> and <a href="javascript:;"><i>privacy policy</i></a></p>
</div> </div>
<div className="divider" /> <ValidationErrorsInfoDialog open={this.state.showValidationErrors} errorMessages={this.state.validationErrors} onDismiss={this.handleValidationErrosDialogDismiss.bind(this)} />
<div className="form-group">
{validationErrors}
</div>
</fieldset> </fieldset>
</form> </form>
</div> </div>