From c45182a5741831ae1aeb33affb1e07481ef31c73 Mon Sep 17 00:00:00 2001 From: Sharon Kennedy Date: Tue, 15 Dec 2020 10:24:20 -0500 Subject: [PATCH] add default settings endpoint' --- public/index.html | 4 +--- src/components/ChatboxWithSettings.js | 16 +++++++++------- src/utils/constants.js | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 src/utils/constants.js diff --git a/public/index.html b/public/index.html index fe521d6..bdb4fc9 100644 --- a/public/index.html +++ b/public/index.html @@ -13,10 +13,8 @@ diff --git a/src/components/ChatboxWithSettings.js b/src/components/ChatboxWithSettings.js index a2af4aa..0784221 100644 --- a/src/components/ChatboxWithSettings.js +++ b/src/components/ChatboxWithSettings.js @@ -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); diff --git a/src/utils/constants.js b/src/utils/constants.js new file mode 100644 index 0000000..6048189 --- /dev/null +++ b/src/utils/constants.js @@ -0,0 +1 @@ +export const DEFAULT_SETTINGS_ENDPOINT = 'https://safesupport-admin.herokuapp.com/api/get-settings';