mirror of
https://github.com/Safe-Support-Chat/ocrcc-chatbox
synced 2024-11-01 00:55:26 +00:00
47 lines
941 B
JavaScript
47 lines
941 B
JavaScript
|
import React, { useState, useEffect } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import Chatbox from './chatbox';
|
||
|
|
||
|
|
||
|
const ChatboxWithSettings = ({ settingsEndpoint, ...rest }) => {
|
||
|
const [settings, setSettings] = useState({});
|
||
|
|
||
|
const settingsObj = {};
|
||
|
|
||
|
const getSettings = async () => {
|
||
|
if (!settingsEndpoint) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
const res = await fetch(settingsEndpoint);
|
||
|
const data = await res.json();
|
||
|
const { fields } = data;
|
||
|
|
||
|
Object.entries(fields).forEach(([k, v]) => {
|
||
|
const [scope, key] = k.split('_');
|
||
|
|
||
|
if (scope === 'web') {
|
||
|
settingsObj[key] = v;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
console.log("settings", settingsObj)
|
||
|
|
||
|
return setSettings(settingsObj);
|
||
|
};
|
||
|
|
||
|
useEffect(() => {
|
||
|
getSettings();
|
||
|
}, []);
|
||
|
|
||
|
return (
|
||
|
<Chatbox {...settings} {...rest} />
|
||
|
);
|
||
|
};
|
||
|
|
||
|
ChatboxWithSettings.propTypes = {
|
||
|
settingsEndpoint: PropTypes.string,
|
||
|
};
|
||
|
|
||
|
export default ChatboxWithSettings;
|