add default settings endpoint'

This commit is contained in:
Sharon Kennedy 2020-12-15 10:24:20 -05:00
parent 819d9b8ebb
commit c45182a574
3 changed files with 11 additions and 10 deletions

View File

@ -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>

View File

@ -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
View File

@ -0,0 +1 @@
export const DEFAULT_SETTINGS_ENDPOINT = 'https://safesupport-admin.herokuapp.com/api/get-settings';