Skip to content

Commit bd2c433

Browse files
authored
Merge pull request #1 from necyberteam/login
Link to Login if anonymous
2 parents 00857a9 + a6e97f9 commit bd2c433

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qa_bot",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"private": true,
55
"homepage": ".",
66
"dependencies": {

src/App.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
.rcb-toggle-button.rcb-button-show {
2+
background-size: 72%;
3+
background-position: center;
4+
background-repeat: no-repeat;
5+
background-color: rgb(26, 91, 110);
6+
}
17
.rcb-chat-window {
28
width: 550px !important;
3-
max-width: calc(100% - 2.5rem);
9+
max-width: calc(100%);
410

511
.rcb-bot-avatar {
612
background-size: contain;

src/App.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const handleQuery = async (params) => {
1010
try {
1111
const requestOptions = {
1212
method: 'POST',
13-
headers: {
13+
headers: {
1414
'Content-Type': 'application/json',
1515
'X-API-KEY': apiKey
1616
},
@@ -55,16 +55,15 @@ const MyChatBot = (props) => {
5555
return 'loop'
5656
}
5757
}
58-
5958
}
6059
return (
61-
<ChatBot
60+
<ChatBot
6261
options={{
63-
theme: {
62+
theme: {
6463
primaryColor: '#1a5b6e',
6564
secondaryColor: '#107180',
6665
fontFamily: 'Arial, sans-serif',
67-
embedded: props.embedded,
66+
embedded: props.embedded,
6867
},
6968
header: {
7069
title: 'ACCESS Q&A Bot',
@@ -75,11 +74,11 @@ const MyChatBot = (props) => {
7574
disabledPlaceholderText: 'Please log in to ask questions.',
7675
disabled: props.disabled
7776
},
78-
chatHistory: { storageKey: "qa_bot" },
79-
botBubble: {
77+
chatHistory: { disabled: true },
78+
botBubble: {
8079
simStream: true,
8180
dangerouslySetInnerHtml: true
82-
},
81+
},
8382
isOpen: false,
8483
chatButton: {
8584
icon: 'https://support.access-ci.org/themes/contrib/asp-theme/images/icons/ACCESS-arrrow.svg',
@@ -110,7 +109,7 @@ const MyChatBot = (props) => {
110109
function App(props) {
111110
return (
112111
<div className="access-qa-bot">
113-
<MyChatBot embedded={props.embedded} welcome={props.welcome} prompt={props.prompt} disabled={props.disabled}/>
112+
<MyChatBot embedded={props.embedded} welcome={props.welcome} prompt={props.prompt} disabled={props.disabled} />
114113
</div>
115114
);
116115
}

src/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ embeddedQABots.forEach(embeddedQABot => {
3737
embeddedQABot.appendChild(embeddedDomNode);
3838
});
3939

40+
// attach login event to the disabled chatbot input
41+
const loginHandler = () => {
42+
if (disabled) {
43+
const loginUrl = '/login?destination=' + window.location.pathname;
44+
window.location = loginUrl;
45+
}
46+
}
47+
const addCustomEventListener = (selector, event, handler) => {
48+
let rootElement = document.querySelector('body');
49+
rootElement.addEventListener(event, function (evt) {
50+
var targetElement = evt.target;
51+
while (targetElement != null) {
52+
if (targetElement.matches(selector)) {
53+
handler(evt);
54+
return;
55+
}
56+
targetElement = targetElement.parentElement;
57+
}
58+
},
59+
true
60+
);
61+
}
62+
//adding the Event Listeners to all the chatbot instances
63+
addCustomEventListener('.rcb-chat-input','click',loginHandler);
64+
4065
// If you want to start measuring performance in your app, pass a function
4166
// to log results (for example: reportWebVitals(console.log))
4267
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals

0 commit comments

Comments
 (0)