import React, { useState } from "react";
import { RqbitDesktopConfig } from "./configuration";
import { Button, Form, Modal, Row, Tab, Tabs } from "react-bootstrap";
import { ErrorComponent } from "./rqbit-webui-src/rqbit-web";
import { invokeAPI } from "./api";
import { ErrorDetails } from "./rqbit-webui-src/api-types";
const FormCheck: React.FC<{
label: string,
name: string,
checked: boolean,
onChange: (e: any) => void,
disabled?: boolean,
help?: string,
}> = ({ label, name, checked, onChange, disabled, help }) => {
return
{label}
{help && {help}
}
}
const FormInput: React.FC<{
label: string,
name: string,
value: string | number,
inputType: string,
onChange: (e: any) => void,
disabled?: boolean,
help?: string
}> = ({ label, name, value, inputType, onChange, disabled, help }) => {
return
{label}
{help && {help}
}
}
export const ConfigModal: React.FC<{
handleOk: (config: RqbitDesktopConfig) => void,
initialConfig: RqbitDesktopConfig,
}> = ({ handleOk, initialConfig }) => {
const [config, setConfig] = useState(initialConfig);
const [error, setError] = useState(null);
const handleInputChange = (e: any) => {
const name: string = e.target.name;
const value: any = e.target.value;
const [mainField, subField] = name.split('.', 2);
if (subField) {
setConfig((prevConfig: any) => ({
...prevConfig,
[mainField]: {
...prevConfig[mainField],
[subField]: value,
},
}));
} else {
setConfig((prevConfig) => ({
...prevConfig,
[name]: value,
}));
}
};
const handleToggleChange = (e: any) => {
const name: string = e.target.name;
const [mainField, subField] = name.split('.', 2);
if (subField) {
setConfig((prevConfig: any) => ({
...prevConfig,
[mainField]: {
...prevConfig[mainField],
[subField]: !prevConfig[mainField][subField],
},
}));
} else {
setConfig((prevConfig: any) => ({
...prevConfig,
[name]: !prevConfig[name],
}));
}
};
const handleOkClick = () => {
setError(null);
invokeAPI<{}>("config_change", { config }).then(
() => handleOk(config),
(e: ErrorDetails) => {
setError({
text: "Error saving configuration",
details: e,
});
}
)
};
return (
Configure Rqbit desktop
);
};