mirror of
https://github.com/Safe-Support-Chat/ocrcc-chatbox
synced 2024-12-23 09:37:43 +00:00
add default settings endpoint'
This commit is contained in:
parent
819d9b8ebb
commit
c45182a574
@ -13,10 +13,8 @@
|
||||
<script src="./chatbox.js"></script>
|
||||
<script>
|
||||
var config = {
|
||||
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings',
|
||||
matrixServerUrl: 'https://matrix.safesupport.chat'
|
||||
}
|
||||
|
||||
};
|
||||
EmbeddableChatbox.mount(config);
|
||||
</script>
|
||||
|
||||
|
@ -1,15 +1,21 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Chatbox from './chatbox';
|
||||
import { DEFAULT_SETTINGS_ENDPOINT } from '../utils/constants';
|
||||
|
||||
|
||||
const ChatboxWithSettings = ({ settingsEndpoint, matrixServerUrl, ...rest }) => {
|
||||
const ChatboxWithSettings = ({ settingsEndpoint = null, matrixServerUrl, ...rest }) => {
|
||||
const [settings, setSettings] = useState({});
|
||||
const [shifts, setShifts] = useState();
|
||||
const [isAvailable, setAvailability] = useState(false);
|
||||
|
||||
const getSettings = async () => {
|
||||
if (!settingsEndpoint) {
|
||||
const endpoint = settingsEndpoint || DEFAULT_SETTINGS_ENDPOINT;
|
||||
const url = `${endpoint}?homeserver=${encodeURIComponent(matrixServerUrl)}`;
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
const { fields, schedule = [] } = data;
|
||||
|
||||
if (!fields) {
|
||||
const props = {
|
||||
...rest,
|
||||
enabled: true,
|
||||
@ -19,10 +25,6 @@ const ChatboxWithSettings = ({ settingsEndpoint, matrixServerUrl, ...rest }) =>
|
||||
return setSettings(props);
|
||||
}
|
||||
|
||||
const url = `${settingsEndpoint}?homeserver=${encodeURIComponent(matrixServerUrl)}`;
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
const { fields, schedule = [] } = data;
|
||||
const settingsObj = {};
|
||||
|
||||
setShifts(schedule);
|
||||
|
1
src/utils/constants.js
Normal file
1
src/utils/constants.js
Normal file
@ -0,0 +1 @@
|
||||
export const DEFAULT_SETTINGS_ENDPOINT = 'https://safesupport-admin.herokuapp.com/api/get-settings';
|
Loading…
Reference in New Issue
Block a user