wizard update

master
Tudor Stanciu 2020-06-06 03:16:14 +03:00
parent a05d4a32af
commit 38e44a990c
5 changed files with 49 additions and 11 deletions

View File

@ -4,6 +4,6 @@ export function summonWizard() {
return { type: types.SUMMON_WIZARD }; return { type: types.SUMMON_WIZARD };
} }
export function cancelBot() { export function dismissBot() {
return { type: types.CANCEL_BOT }; return { type: types.DISMISS_BOT };
} }

View File

@ -1,2 +1,2 @@
export const CANCEL_BOT = "CANCEL_BOT"; export const DISMISS_BOT = "DISMISS_BOT";
export const SUMMON_WIZARD = "SUMMON_WIZARD"; export const SUMMON_WIZARD = "SUMMON_WIZARD";

View File

@ -1,9 +1,11 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { botType } from "../botType"; import { botType } from "../botType";
import Wizard from "./Wizard"; import Wizard from "./Wizard";
import { makeStyles } from "@material-ui/core/styles"; import { makeStyles } from "@material-ui/core/styles";
import { dismissBot } from "../actionCreators";
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles(theme => ({
bot: { bot: {
@ -17,7 +19,7 @@ const useStyles = makeStyles(theme => ({
} }
})); }));
const BotsManager = ({ bot }) => { const BotsManager = ({ bot, actions }) => {
const [type, setType] = useState(bot.type); const [type, setType] = useState(bot.type);
const classes = useStyles(); const classes = useStyles();
@ -27,13 +29,16 @@ const BotsManager = ({ bot }) => {
return ( return (
<div className={classes.botPosition}> <div className={classes.botPosition}>
<div className={classes.bot}>{type === botType.wizard && <Wizard />}</div> <div className={classes.bot}>
{type === botType.wizard && <Wizard dismissBot={actions.dismissBot} />}
</div>
</div> </div>
); );
}; };
BotsManager.propTypes = { BotsManager.propTypes = {
bot: PropTypes.object bot: PropTypes.object.isRequired,
actions: PropTypes.object.isRequired
}; };
function mapStateToProps(state) { function mapStateToProps(state) {
@ -42,8 +47,10 @@ function mapStateToProps(state) {
}; };
} }
function mapDispatchToProps() { function mapDispatchToProps(dispatch) {
return {}; return {
actions: bindActionCreators({ dismissBot }, dispatch)
};
} }
export default connect(mapStateToProps, mapDispatchToProps)(BotsManager); export default connect(mapStateToProps, mapDispatchToProps)(BotsManager);

View File

@ -1,9 +1,10 @@
import React from "react"; import React from "react";
import PropTypes from "prop-types";
import ChatBot from "react-simple-chatbot"; import ChatBot from "react-simple-chatbot";
import { ThemeProvider } from "styled-components"; import { ThemeProvider } from "styled-components";
import { useTheme } from "@material-ui/core/styles"; import { useTheme } from "@material-ui/core/styles";
const Wizard = () => { const Wizard = ({ dismissBot }) => {
const theme = useTheme(); const theme = useTheme();
const botTheme = { const botTheme = {
@ -41,14 +42,40 @@ const Wizard = () => {
}, },
{ {
id: "5", id: "5",
message: "Hi {previousValue}, nice to meet you!", message: "I don't have time for that. Ask me something serious.",
trigger: "6"
},
{
id: "6",
user: true,
trigger: "7"
},
{
id: "7",
message:
"I don't think I understand '{previousValue}'. You mean, like, flowers?",
trigger: "8"
},
{
id: "8",
user: true,
trigger: "9"
},
{
id: "9",
message: "I think you're wasting my time. Farewell!",
end: true end: true
} }
]; ];
const handleEnd = () => {
setTimeout(dismissBot, 3000);
};
return ( return (
<ThemeProvider theme={botTheme}> <ThemeProvider theme={botTheme}>
<ChatBot <ChatBot
handleEnd={handleEnd}
steps={steps} steps={steps}
botAvatar="public/icons/wizard.png" botAvatar="public/icons/wizard.png"
headerTitle="Zirhan" headerTitle="Zirhan"
@ -57,4 +84,8 @@ const Wizard = () => {
); );
}; };
Wizard.propTypes = {
dismissBot: PropTypes.func.isRequired
};
export default Wizard; export default Wizard;

View File

@ -7,7 +7,7 @@ export default function chatbotReducer(state = initialState.snackbar, action) {
case types.SUMMON_WIZARD: case types.SUMMON_WIZARD:
return { ...state, type: botType.wizard }; return { ...state, type: botType.wizard };
case types.CANCEL_BOT: case types.DISMISS_BOT:
return { ...state, type: botType.none }; return { ...state, type: botType.none };
default: default: