initial step 4 for online test
This commit is contained in:
134
web/src/App.js
134
web/src/App.js
@@ -4,9 +4,13 @@ import './css/popup.css';
|
||||
import IntentList from './components/IntentList';
|
||||
import IntentDetails from './components/IntentDetails';
|
||||
import LaunchRequest from './components/LaunchRequest';
|
||||
import Contact from './components/Contact';
|
||||
import Popup from 'react-popup';
|
||||
|
||||
import {getSkill, updateSkill} from './lib/api'
|
||||
import {
|
||||
NEW_INTENT_SELECTED_INDEX,
|
||||
LAUNCH_REQUEST_SELECTED_INDEX,
|
||||
CONTACT_SELECTED_INDEX} from './config'
|
||||
|
||||
class App extends Component {
|
||||
|
||||
@@ -20,8 +24,8 @@ class App extends Component {
|
||||
invocationAnswer:'We are saburly',
|
||||
allIntents:[],
|
||||
selectedIntent: {intentName:'',questions:[''],answer:''},
|
||||
selectedIndex:-1,
|
||||
launchRequest:false,
|
||||
selectedIndex:NEW_INTENT_SELECTED_INDEX,
|
||||
contactEmail:'',
|
||||
waiting: false
|
||||
};
|
||||
|
||||
@@ -30,7 +34,7 @@ class App extends Component {
|
||||
if (jResult===undefined) return;
|
||||
this.setState({ skillID:jResult.skillID,skillName:jResult.skillName, invocationName: jResult.invocationName,
|
||||
invocationAnswer: jResult.invocationAnswer,
|
||||
allIntents: jResult.intents})
|
||||
allIntents: jResult.intents, contactEmail: jResult.contactEmail})
|
||||
})
|
||||
|
||||
this.handleIntentClick = this.handleIntentClick.bind(this);
|
||||
@@ -41,62 +45,67 @@ class App extends Component {
|
||||
this.handleSaveLaunchRequestClick = this.handleSaveLaunchRequestClick.bind(this);
|
||||
this.createSkill = this.createSkill.bind(this);
|
||||
this.sendSkill = this.sendSkill.bind(this);
|
||||
this.handleContactClick = this.handleContactClick.bind(this);
|
||||
this.handleSaveEmailClick = this.handleSaveEmailClick.bind(this);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
if(this.state.launchRequest){
|
||||
return (
|
||||
<div className="App">
|
||||
<Popup/>
|
||||
<div className="App-header">
|
||||
<h1> Tell All </h1>
|
||||
</div>
|
||||
<IntentList allIntents={this.state.allIntents}
|
||||
onLaunchRequestClick={this.handleLaunchRequestClick}
|
||||
onIntentClick={this.handleIntentClick}
|
||||
onAddIntentClick={this.handleAddIntentClick}
|
||||
selectedIndex={this.state.selectedIndex}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentList>
|
||||
<LaunchRequest invocationName={this.state.invocationName}
|
||||
invocationAnswer={this.state.invocationAnswer}
|
||||
onSaveClick={this.handleSaveLaunchRequestClick}
|
||||
waiting={this.state.waiting}>
|
||||
</LaunchRequest>
|
||||
return(
|
||||
<div className="App">
|
||||
<Popup/>
|
||||
<div className="App-header">
|
||||
<h1> Tell All </h1>
|
||||
</div>
|
||||
);
|
||||
}else{
|
||||
return (
|
||||
<div className="App">
|
||||
<Popup/>
|
||||
<div className="App-header">
|
||||
<h1> Tell All </h1>
|
||||
</div>
|
||||
<IntentList allIntents={this.state.allIntents}
|
||||
onLaunchRequestClick={this.handleLaunchRequestClick}
|
||||
onIntentClick={this.handleIntentClick}
|
||||
onAddIntentClick={this.handleAddIntentClick}
|
||||
selectedIndex={this.state.selectedIndex}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentList>
|
||||
<IntentDetails selectedIntent={this.state.selectedIntent}
|
||||
onDeleteIntentClick={this.handleDeleteIntentClick}
|
||||
onSaveIntentClick={this.handleSaveIntentClick}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentDetails>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
<IntentList allIntents={this.state.allIntents}
|
||||
onLaunchRequestClick={this.handleLaunchRequestClick}
|
||||
onContactClick={this.handleContactClick}
|
||||
onIntentClick={this.handleIntentClick}
|
||||
onAddIntentClick={this.handleAddIntentClick}
|
||||
selectedIndex={this.state.selectedIndex}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentList>
|
||||
{(
|
||||
()=>{
|
||||
if (this.state.selectedIndex===LAUNCH_REQUEST_SELECTED_INDEX){
|
||||
return (
|
||||
<LaunchRequest invocationName={this.state.invocationName}
|
||||
invocationAnswer={this.state.invocationAnswer}
|
||||
onSaveClick={this.handleSaveLaunchRequestClick}
|
||||
waiting={this.state.waiting}>
|
||||
</LaunchRequest>
|
||||
);
|
||||
}else if (this.state.selectedIndex===CONTACT_SELECTED_INDEX){
|
||||
return (
|
||||
<Contact
|
||||
contactEmail={this.state.contactEmail}
|
||||
onSaveEmailClick={this.handleSaveEmailClick}
|
||||
waiting={this.state.waiting}>
|
||||
</Contact>
|
||||
);
|
||||
}else{
|
||||
return(
|
||||
<IntentDetails selectedIntent={this.state.selectedIntent}
|
||||
onDeleteIntentClick={this.handleDeleteIntentClick}
|
||||
onSaveIntentClick={this.handleSaveIntentClick}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentDetails>
|
||||
);
|
||||
}
|
||||
}
|
||||
)()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
createSkill(intents, name, answer){
|
||||
createSkill(intents, name, answer, email, updateOnAmazon){
|
||||
return {
|
||||
_id: this.state._id,
|
||||
skillID: this.state.skillID,
|
||||
intents: intents,
|
||||
invocationName: (name===undefined) ? this.state.invocationName : name,
|
||||
invocationAnswer: (answer===undefined)? this.state.invocationAnswer: answer
|
||||
invocationName: name,
|
||||
invocationAnswer: answer,
|
||||
contactEmail: email,
|
||||
updateOnAmazon: updateOnAmazon
|
||||
};
|
||||
}
|
||||
|
||||
@@ -105,12 +114,21 @@ class App extends Component {
|
||||
}
|
||||
|
||||
handleLaunchRequestClick(){
|
||||
this.setState({selectedIndex: -2, launchRequest:true});
|
||||
this.setState({selectedIndex: LAUNCH_REQUEST_SELECTED_INDEX});
|
||||
}
|
||||
|
||||
handleContactClick(){
|
||||
this.setState({selectedIndex: CONTACT_SELECTED_INDEX})
|
||||
}
|
||||
|
||||
handleSaveLaunchRequestClick(name, answer){
|
||||
this.setState({waiting:true, invocationName:name, invocationAnswer: answer});
|
||||
this.sendSkill(this.state.allIntents,true,{waiting:false},{waiting:false},name,answer);
|
||||
this.sendSkill(this.state.allIntents,true,{waiting:false},{waiting:false},name,answer,this.state.contactEmail,true);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
handleDeleteIntentClick(selectedIntent){
|
||||
@@ -128,7 +146,7 @@ class App extends Component {
|
||||
this.setState({waiting:true});
|
||||
|
||||
let newState = {allIntents: newAllIntents, selectedIntent: {intentName:'', questions:[''],answer:''}, waiting:false};
|
||||
this.sendSkill(newAllIntents,true,newState,{waiting:false});
|
||||
this.sendSkill(newAllIntents,true,newState,{waiting:false},this.state.invocationName,this.state.invocationAnswer,this.state.contactEmail,true);
|
||||
|
||||
}catch(e){
|
||||
console.log("error : " + e);
|
||||
@@ -142,7 +160,7 @@ class App extends Component {
|
||||
let newAllIntents = JSON.parse(newAllIntentsJSON);
|
||||
|
||||
let newState = null;
|
||||
if (this.state.selectedIndex === -1){
|
||||
if (this.state.selectedIndex === NEW_INTENT_SELECTED_INDEX){
|
||||
//new intent
|
||||
newAllIntents.push(selectedIntent);
|
||||
newState = {allIntents: newAllIntents, selectedIntent: selectedIntent, selectedIndex: newAllIntents.length-1, waiting:false};
|
||||
@@ -151,16 +169,16 @@ class App extends Component {
|
||||
newState = {allIntents: newAllIntents, selectedIntent: selectedIntent, waiting: false};
|
||||
}
|
||||
this.setState({waiting:true});
|
||||
this.sendSkill(newAllIntents, true, newState, {waiting:false});
|
||||
this.sendSkill(newAllIntents, true, newState, {waiting:false}, this.state.invocationName,this.state.invocationAnswer,this.state.contactEmail, true);
|
||||
}
|
||||
|
||||
handleAddIntentClick(){
|
||||
this.setState({allIntents: this.state.allIntents, selectedIndex: -1,launchRequest:false,selectedIntent: {intentName:'',questions:[''], answer:''}});
|
||||
this.setState({allIntents: this.state.allIntents, selectedIndex: NEW_INTENT_SELECTED_INDEX,launchRequest:false,selectedIntent: {intentName:'',questions:[''], answer:''}});
|
||||
}
|
||||
|
||||
sendSkill(newAllIntents, showPopUp, resolveState, rejectState, newName, newAnswer){
|
||||
sendSkill(newAllIntents, showPopUp, resolveState, rejectState, newName, newAnswer, email, updateOnAmazon){
|
||||
return new Promise((resolve,reject)=>{
|
||||
updateSkill(this.createSkill(newAllIntents,newName,newAnswer)).then(l=>l.text()).then(result=>{
|
||||
updateSkill(this.createSkill(newAllIntents,newName,newAnswer,email,updateOnAmazon)).then(l=>l.text()).then(result=>{
|
||||
let jResult = JSON.parse(result);
|
||||
if (jResult.result !== 0){
|
||||
if (showPopUp) Popup.alert('Model was not saved. Please try again');
|
||||
|
||||
Reference in New Issue
Block a user