Skip to content

Commit

Permalink
Disable chat for anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
a-pasquale committed Sep 12, 2024
1 parent f30c090 commit 969d2e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const MyChatBot = (props) => {
},
chatInput: {
enabledPlaceholderText: prompt,
disabledPlaceholderText: 'Please log in to ask questions.',
disabled: props.disabled
},
chatHistory: { storageKey: "qa_bot" },
botBubble: {
Expand Down Expand Up @@ -108,7 +110,7 @@ const MyChatBot = (props) => {
function App(props) {
return (
<div className="access-qa-bot">
<MyChatBot embedded={props.embedded} welcome={props.welcome} prompt={props.prompt}/>
<MyChatBot embedded={props.embedded} welcome={props.welcome} prompt={props.prompt} disabled={props.disabled}/>
</div>
);
}
Expand Down
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@ import reportWebVitals from './reportWebVitals';

// Popup Chat widget
const domNode = document.createElement('div');
const root = ReactDOM.createRoot(domNode);
const root = ReactDOM.createRoot(domNode);

function isAnonymous() {
return !document.querySelector('body').classList.contains('user-logged-in');
}
const disabled = isAnonymous();

root.render(
<React.StrictMode>
<App />
<App disabled={disabled} />
</React.StrictMode>
);
document.body.appendChild(domNode);

// Look for optional elements for an embedded chat widget
const embeddedQABots = document.querySelectorAll('.embedded-qa-bot');
embeddedQABots.forEach(embeddedQABot => {
const disabled = isAnonymous();
// welcome message and prompt are data- attributes
const welcome = embeddedQABot.dataset.welcome;
const prompt = embeddedQABot.dataset.prompt;
const embeddedDomNode = document.createElement('div');
const embeddedRoot = ReactDOM.createRoot(embeddedDomNode);
embeddedRoot.render(
<React.StrictMode>
<App embedded welcome={welcome} prompt={prompt}/>
<App embedded welcome={welcome} prompt={prompt} disabled={disabled}/>
</React.StrictMode>
);
embeddedQABot.appendChild(embeddedDomNode);
Expand Down

0 comments on commit 969d2e4

Please sign in to comment.