From 5e923149389c016a0e636cb7566977efccc06417 Mon Sep 17 00:00:00 2001 From: GotPPay Date: Mon, 29 Jan 2018 21:32:24 +0100 Subject: [PATCH] frontend user input handling --- web/src/App.js | 78 ++++++++++++++++++++++++----- web/src/components/IntentDetails.js | 13 ++--- web/src/components/LaunchRequest.js | 4 +- web/src/config/constants.js | 11 +++- web/src/lib/helpers.js | 5 ++ 5 files changed, 87 insertions(+), 24 deletions(-) create mode 100644 web/src/lib/helpers.js diff --git a/web/src/App.js b/web/src/App.js index 15ee959..f99b096 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -7,11 +7,16 @@ import LaunchRequest from './components/LaunchRequest'; import Contact from './components/Contact'; import Popup from 'react-popup'; import {getSkill, updateSkill} from './lib/api'; +import {isEmailValid} from './lib/helpers'; import { NEW_INTENT_SELECTED_INDEX, LAUNCH_REQUEST_SELECTED_INDEX, CONTACT_SELECTED_INDEX, RESULT_CODES, + INVOCATION_NAME_MIN_LENGTH, + INTENT_NAME_MIN_LENGTH, + QUESTION_MIN_LENGTH, + ANSWER_MIN_LENGTH, } from './config/constants'; class App extends Component { @@ -144,6 +149,12 @@ class App extends Component { } handleSaveLaunchRequestClick (name, answer) { + + if (name.length < INVOCATION_NAME_MIN_LENGTH){ + Popup.alert ('Invocation name should be at least 2 characters long'); + return; + } + this.setState ({ waiting: true, invocationName: name, @@ -162,17 +173,21 @@ class App extends Component { } handleSaveEmailClick (email) { - this.setState ({waiting: true}); - this.sendSkill ( - this.state.allIntents, - true, - {contactEmail: email, waiting: false}, - {waiting: false}, - this.state.invocationName, - this.state.invocationAnswer, - email, - false - ); + if (isEmailValid(email)){ + this.setState ({waiting: true}); + this.sendSkill ( + this.state.allIntents, + true, + {contactEmail: email, waiting: false}, + {waiting: false}, + this.state.invocationName, + this.state.invocationAnswer, + email, + false + ); + }else{ + Popup.alert ('Please enter valid email'); + } } handleDeleteIntentClick (selectedIntent) { @@ -215,7 +230,46 @@ class App extends Component { } handleSaveIntentClick (selectedIntent) { - console.log("Save intent"); + + if (selectedIntent.intentName.length < INTENT_NAME_MIN_LENGTH){ + Popup.alert ('Question name should have at least 2 characters'); + return; + } + + if (selectedIntent.answer.length < ANSWER_MIN_LENGTH){ + Popup.alert('Answer should have at least 2 characters'); + return; + } + + for(let i=0;i { + let validEmailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + + return validEmailRegex.test (email); +};