mirror of
https://github.com/Safe-Support-Chat/ocrcc-chatbox
synced 2024-11-23 11:15:01 +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 src="./chatbox.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings',
|
|
||||||
matrixServerUrl: 'https://matrix.safesupport.chat'
|
matrixServerUrl: 'https://matrix.safesupport.chat'
|
||||||
}
|
};
|
||||||
|
|
||||||
EmbeddableChatbox.mount(config);
|
EmbeddableChatbox.mount(config);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Chatbox from './chatbox';
|
import Chatbox from './chatbox';
|
||||||
|
import { DEFAULT_SETTINGS_ENDPOINT } from '../utils/constants';
|
||||||
|
|
||||||
|
const ChatboxWithSettings = ({ settingsEndpoint = null, matrixServerUrl, ...rest }) => {
|
||||||
const ChatboxWithSettings = ({ settingsEndpoint, matrixServerUrl, ...rest }) => {
|
|
||||||
const [settings, setSettings] = useState({});
|
const [settings, setSettings] = useState({});
|
||||||
const [shifts, setShifts] = useState();
|
const [shifts, setShifts] = useState();
|
||||||
const [isAvailable, setAvailability] = useState(false);
|
const [isAvailable, setAvailability] = useState(false);
|
||||||
|
|
||||||
const getSettings = async () => {
|
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 = {
|
const props = {
|
||||||
...rest,
|
...rest,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
@ -19,10 +25,6 @@ const ChatboxWithSettings = ({ settingsEndpoint, matrixServerUrl, ...rest }) =>
|
|||||||
return setSettings(props);
|
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 = {};
|
const settingsObj = {};
|
||||||
|
|
||||||
setShifts(schedule);
|
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