reverse-proxy-frontend/src/features/chatbot/components/BotsManager.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-06-06 01:42:11 +03:00
import React, { useEffect, useState } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
2020-06-06 03:16:14 +03:00
import { bindActionCreators } from "redux";
2020-06-06 01:42:11 +03:00
import { botType } from "../botType";
import Wizard from "./Wizard";
2020-06-06 02:07:04 +03:00
import { makeStyles } from "@material-ui/core/styles";
2020-06-06 03:16:14 +03:00
import { dismissBot } from "../actionCreators";
2020-06-06 02:07:04 +03:00
const useStyles = makeStyles(theme => ({
bot: {
position: "fixed",
bottom: theme.spacing(2),
right: theme.spacing(2),
zIndex: 1
},
botPosition: {
position: "absolute"
}
}));
2020-06-06 01:42:11 +03:00
2020-06-06 03:16:14 +03:00
const BotsManager = ({ bot, actions }) => {
2020-06-06 01:42:11 +03:00
const [type, setType] = useState(bot.type);
2020-06-06 02:07:04 +03:00
const classes = useStyles();
2020-06-06 01:42:11 +03:00
useEffect(() => {
if (bot.type) setType(bot.type);
}, [bot.type]);
return (
2020-06-06 02:07:04 +03:00
<div className={classes.botPosition}>
2020-06-06 03:16:14 +03:00
<div className={classes.bot}>
{type === botType.wizard && <Wizard dismissBot={actions.dismissBot} />}
</div>
2020-06-06 01:42:11 +03:00
</div>
);
};
BotsManager.propTypes = {
2020-06-06 03:16:14 +03:00
bot: PropTypes.object.isRequired,
actions: PropTypes.object.isRequired
2020-06-06 01:42:11 +03:00
};
function mapStateToProps(state) {
return {
bot: state.bot
};
}
2020-06-06 03:16:14 +03:00
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({ dismissBot }, dispatch)
};
2020-06-06 01:42:11 +03:00
}
export default connect(mapStateToProps, mapDispatchToProps)(BotsManager);