mirror of
https://github.com/Safe-Support-Chat/ocrcc-chatbox
synced 2024-11-22 02:34:55 +00:00
optionally use settings from admin app
This commit is contained in:
parent
de4106c093
commit
9432e4d86f
38
dist/bookmarklet.js
vendored
38
dist/bookmarklet.js
vendored
File diff suppressed because one or more lines are too long
38
dist/chatbox.js
vendored
38
dist/chatbox.js
vendored
File diff suppressed because one or more lines are too long
8
dist/component.js
vendored
8
dist/component.js
vendored
File diff suppressed because one or more lines are too long
5
dist/index.html
vendored
5
dist/index.html
vendored
@ -13,10 +13,7 @@
|
|||||||
<script src="./chatbox.js"></script>
|
<script src="./chatbox.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
matrixServerUrl: 'https://matrix.safesupport.chat',
|
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings'
|
||||||
airtableApiKey: 'keyFfDHgHILw5IIwA',
|
|
||||||
airtableBaseId: 'app7IycwU6dY6o1oj',
|
|
||||||
settingsTableName: 'settings',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EmbeddableChatbox.mount(config);
|
EmbeddableChatbox.mount(config);
|
||||||
|
@ -10,7 +10,12 @@ const ChatboxWithSettings = ({ settingsEndpoint, ...rest }) => {
|
|||||||
|
|
||||||
const getSettings = async () => {
|
const getSettings = async () => {
|
||||||
if (!settingsEndpoint) {
|
if (!settingsEndpoint) {
|
||||||
return null;
|
const props = {
|
||||||
|
...rest,
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
|
||||||
|
return setSettings(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(settingsEndpoint);
|
const res = await fetch(settingsEndpoint);
|
||||||
@ -25,7 +30,9 @@ const ChatboxWithSettings = ({ settingsEndpoint, ...rest }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("settings", settingsObj)
|
if (!settingsObj.enabled) {
|
||||||
|
settingsObj.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
return setSettings(settingsObj);
|
return setSettings(settingsObj);
|
||||||
};
|
};
|
||||||
|
@ -44,6 +44,7 @@ const DEFAULT_SIZE = 'large'
|
|||||||
const DEFAULT_MAX_WAIT_MS = 600000 // 10 minutes
|
const DEFAULT_MAX_WAIT_MS = 600000 // 10 minutes
|
||||||
const DEFAULT_WAIT_INTERVAL_MS = 120000 // 2 minutes
|
const DEFAULT_WAIT_INTERVAL_MS = 120000 // 2 minutes
|
||||||
const DEFAULT_DOCK_LABEL = 'Start a new chat'
|
const DEFAULT_DOCK_LABEL = 'Start a new chat'
|
||||||
|
const DEFAULT_ENABLED = false
|
||||||
|
|
||||||
class ChatBox extends React.Component {
|
class ChatBox extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -68,7 +69,7 @@ class ChatBox extends React.Component {
|
|||||||
isMobile: true,
|
isMobile: true,
|
||||||
isSlowConnection: true,
|
isSlowConnection: true,
|
||||||
decryptionErrors: {},
|
decryptionErrors: {},
|
||||||
messagesInFlight: []
|
messagesInFlight: [],
|
||||||
}
|
}
|
||||||
this.state = this.initialState
|
this.state = this.initialState
|
||||||
this.chatboxInput = React.createRef();
|
this.chatboxInput = React.createRef();
|
||||||
@ -654,6 +655,10 @@ class ChatBox extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
if (!this.props.enabled) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const { ready, messages, messagesInFlight, inputValue, userId, roomId, typingStatus, opened, showDock, emojiSelectorOpen, isMobile, decryptionErrors } = this.state;
|
const { ready, messages, messagesInFlight, inputValue, userId, roomId, typingStatus, opened, showDock, emojiSelectorOpen, isMobile, decryptionErrors } = this.state;
|
||||||
const orderedMessages = Object.values(messages).sort((a,b) => a.timestamp - b.timestamp)
|
const orderedMessages = Object.values(messages).sort((a,b) => a.timestamp - b.timestamp)
|
||||||
const inputLabel = 'Send a message...'
|
const inputLabel = 'Send a message...'
|
||||||
@ -783,6 +788,7 @@ ChatBox.propTypes = {
|
|||||||
maxWaitTime: PropTypes.number,
|
maxWaitTime: PropTypes.number,
|
||||||
waitInterval: PropTypes.number,
|
waitInterval: PropTypes.number,
|
||||||
dockLabel: PropTypes.string,
|
dockLabel: PropTypes.string,
|
||||||
|
enabled: PropTypes.bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatBox.defaultProps = {
|
ChatBox.defaultProps = {
|
||||||
@ -804,6 +810,7 @@ ChatBox.defaultProps = {
|
|||||||
maxWaitTime: DEFAULT_MAX_WAIT_MS,
|
maxWaitTime: DEFAULT_MAX_WAIT_MS,
|
||||||
waitInterval: DEFAULT_WAIT_INTERVAL_MS,
|
waitInterval: DEFAULT_WAIT_INTERVAL_MS,
|
||||||
dockLabel: DEFAULT_DOCK_LABEL,
|
dockLabel: DEFAULT_DOCK_LABEL,
|
||||||
|
enabled: DEFAULT_ENABLED,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ChatBox;
|
export default ChatBox;
|
||||||
|
Loading…
Reference in New Issue
Block a user