@risecx/carespace-chat-ui
Version:
carespace-chat-ui React component
120 lines (97 loc) • 4.5 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import PropTypes from 'prop-types';
import React, { Component, Fragment } from 'react';
import MessageList from './MessageList';
import UserInput from './UserInput';
import Header from './Header';
import Auth from '../components/Auth';
import { Favorites } from '../components/Favorites';
import Programs from '../components/Programs';
var ChatWindow = /*#__PURE__*/function (_Component) {
_inheritsLoose(ChatWindow, _Component);
function ChatWindow(props) {
var _this;
_this = _Component.call(this, props) || this;
_defineProperty(_assertThisInitialized(_this), "onSubHeaderMenuItemClickHandler", function (menuItem) {
_this.setState({
component: menuItem.key
});
});
_defineProperty(_assertThisInitialized(_this), "onProgramSelectHandler", function () {
_this.setState({
component: 'MESSAGE_LIST'
});
_this.refHeader.onCloseClickHandler();
});
_defineProperty(_assertThisInitialized(_this), "onLoginClickHandler", function () {
_this.refAuth.onLoginClickHandler();
});
_defineProperty(_assertThisInitialized(_this), "onLogoutClickHandler", function () {
_this.refAuth.onLogoutClickHandler();
});
_this.state = {
component: 'MESSAGE_LIST'
};
return _this;
}
var _proto = ChatWindow.prototype;
_proto.onUserInputSubmit = function onUserInputSubmit(message) {
this.props.onUserInputSubmit(message);
};
_proto.onFilesSelected = function onFilesSelected(filesList) {
this.props.onFilesSelected(filesList);
};
_proto.renderComponent = function renderComponent(component) {
switch (component) {
case 'FAVORITES':
return /*#__PURE__*/React.createElement(Favorites, this.props);
case 'PROGRAMS':
return /*#__PURE__*/React.createElement(Programs, _extends({}, this.props, {
onSelect: this.onProgramSelectHandler
}));
default:
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(MessageList, this.props), /*#__PURE__*/React.createElement(UserInput, _extends({}, this.props, {
onSubmit: this.onUserInputSubmit.bind(this),
onFilesSelected: this.onFilesSelected.bind(this),
onLoginClick: this.onLoginClickHandler,
onLogoutClick: this.onLogoutClickHandler
})));
}
};
_proto.render = function render() {
var _this2 = this;
var classList = ['sc-chat-window', this.props.isOpen ? 'opened' : 'closed'];
var component = this.state.component;
return /*#__PURE__*/React.createElement("div", {
className: classList.join(' ')
}, /*#__PURE__*/React.createElement(Auth, _extends({}, this.props, {
ref: function ref(Auth) {
_this2.refAuth = Auth;
}
}), /*#__PURE__*/React.createElement(Header, _extends({
ref: function ref(Header) {
_this2.refHeader = Header;
}
}, this.props, {
isAuth: true,
teamName: this.props.agentProfile.teamName,
avatarImageUrl: this.props.agentProfile.avatarImageUrl,
onClose: this.props.onClose,
onSubHeaderMenuItemClick: this.onSubHeaderMenuItemClickHandler
})), this.renderComponent(component)));
};
return ChatWindow;
}(Component);
ChatWindow.propTypes = process.env.NODE_ENV !== "production" ? {
agentProfile: PropTypes.object.isRequired,
isOpen: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
onFilesSelected: PropTypes.func,
onAuth: PropTypes.func,
onUserInputSubmit: PropTypes.func.isRequired,
showEmoji: PropTypes.bool
} : {};
export default ChatWindow;