optionally use settings from admin app
This commit is contained in:
parent
de4106c093
commit
9432e4d86f
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -13,10 +13,7 @@
|
|||
<script src="./chatbox.js"></script>
|
||||
<script>
|
||||
var config = {
|
||||
matrixServerUrl: 'https://matrix.safesupport.chat',
|
||||
airtableApiKey: 'keyFfDHgHILw5IIwA',
|
||||
airtableBaseId: 'app7IycwU6dY6o1oj',
|
||||
settingsTableName: 'settings',
|
||||
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings'
|
||||
}
|
||||
|
||||
EmbeddableChatbox.mount(config);
|
||||
|
|
|
@ -10,7 +10,12 @@ const ChatboxWithSettings = ({ settingsEndpoint, ...rest }) => {
|
|||
|
||||
const getSettings = async () => {
|
||||
if (!settingsEndpoint) {
|
||||
return null;
|
||||
const props = {
|
||||
...rest,
|
||||
enabled: true
|
||||
}
|
||||
|
||||
return setSettings(props);
|
||||
}
|
||||
|
||||
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);
|
||||
};
|
||||
|
|
|
@ -44,6 +44,7 @@ const DEFAULT_SIZE = 'large'
|
|||
const DEFAULT_MAX_WAIT_MS = 600000 // 10 minutes
|
||||
const DEFAULT_WAIT_INTERVAL_MS = 120000 // 2 minutes
|
||||
const DEFAULT_DOCK_LABEL = 'Start a new chat'
|
||||
const DEFAULT_ENABLED = false
|
||||
|
||||
class ChatBox extends React.Component {
|
||||
constructor(props) {
|
||||
|
@ -68,7 +69,7 @@ class ChatBox extends React.Component {
|
|||
isMobile: true,
|
||||
isSlowConnection: true,
|
||||
decryptionErrors: {},
|
||||
messagesInFlight: []
|
||||
messagesInFlight: [],
|
||||
}
|
||||
this.state = this.initialState
|
||||
this.chatboxInput = React.createRef();
|
||||
|
@ -654,6 +655,10 @@ class ChatBox extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
if (!this.props.enabled) {
|
||||
return null
|
||||
}
|
||||
|
||||
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 inputLabel = 'Send a message...'
|
||||
|
@ -783,6 +788,7 @@ ChatBox.propTypes = {
|
|||
maxWaitTime: PropTypes.number,
|
||||
waitInterval: PropTypes.number,
|
||||
dockLabel: PropTypes.string,
|
||||
enabled: PropTypes.bool,
|
||||
}
|
||||
|
||||
ChatBox.defaultProps = {
|
||||
|
@ -804,6 +810,7 @@ ChatBox.defaultProps = {
|
|||
maxWaitTime: DEFAULT_MAX_WAIT_MS,
|
||||
waitInterval: DEFAULT_WAIT_INTERVAL_MS,
|
||||
dockLabel: DEFAULT_DOCK_LABEL,
|
||||
enabled: DEFAULT_ENABLED,
|
||||
}
|
||||
|
||||
export default ChatBox;
|
||||
|
|
Loading…
Reference in New Issue