* add config file possibility * revert port in docker compose * Update docker-compose.yml Co-authored-by: Elias Schneider <login@eliasschneider.com> * Update docker-compose.yml Co-authored-by: Elias Schneider <login@eliasschneider.com> * add attribute description to config file * remove email message config * add package to resolve errors * remove email messages from config * move config initialization to config module * revert unnecessary change * add order * improve alert * run formatter * remove unnecessary packages * remove unnecessary types * use logger * don't save yaml config to db * allowEdit if no yaml config is set * improve docs * fix allow edit state * remove unnecessary check and refactor code * restore old config file * add script that generates `config.example.yaml` automatically * allow config variables to be changed if they are not set in the `config.yml` * add back init user * Revert "allow config variables to be changed if they are not set in the `config.yml`" This reverts commit 7dbdb6729034be5b083f126f854d5e1411735a54. * improve info box text --------- Co-authored-by: Elias Schneider <login@eliasschneider.com>
118 lines
3.6 KiB
TypeScript
118 lines
3.6 KiB
TypeScript
import {
|
|
NumberInput,
|
|
PasswordInput,
|
|
Stack,
|
|
Switch,
|
|
Textarea,
|
|
TextInput,
|
|
} from "@mantine/core";
|
|
import { useForm } from "@mantine/form";
|
|
import { AdminConfig, UpdateConfig } from "../../../types/config.type";
|
|
import { stringToTimespan, timespanToString } from "../../../utils/date.util";
|
|
import FileSizeInput from "../../core/FileSizeInput";
|
|
import TimespanInput from "../../core/TimespanInput";
|
|
|
|
const AdminConfigInput = ({
|
|
configVariable,
|
|
updateConfigVariable,
|
|
}: {
|
|
configVariable: AdminConfig;
|
|
updateConfigVariable: (variable: UpdateConfig) => void;
|
|
}) => {
|
|
const form = useForm({
|
|
initialValues: {
|
|
stringValue: configVariable.value ?? configVariable.defaultValue,
|
|
textValue: configVariable.value ?? configVariable.defaultValue,
|
|
numberValue: parseInt(
|
|
configVariable.value ?? configVariable.defaultValue,
|
|
),
|
|
booleanValue:
|
|
(configVariable.value ?? configVariable.defaultValue) == "true",
|
|
},
|
|
});
|
|
|
|
const onValueChange = (configVariable: AdminConfig, value: any) => {
|
|
form.setFieldValue(`${configVariable.type}Value`, value);
|
|
updateConfigVariable({ key: configVariable.key, value: value });
|
|
};
|
|
|
|
return (
|
|
<Stack align="end">
|
|
{configVariable.type == "string" &&
|
|
(configVariable.obscured ? (
|
|
<PasswordInput
|
|
autoComplete="new-password"
|
|
style={{
|
|
width: "100%",
|
|
}}
|
|
disabled={!configVariable.allowEdit}
|
|
{...form.getInputProps("stringValue")}
|
|
onChange={(e) => onValueChange(configVariable, e.target.value)}
|
|
/>
|
|
) : (
|
|
<TextInput
|
|
style={{
|
|
width: "100%",
|
|
}}
|
|
disabled={!configVariable.allowEdit}
|
|
{...form.getInputProps("stringValue")}
|
|
placeholder={configVariable.defaultValue}
|
|
onChange={(e) => onValueChange(configVariable, e.target.value)}
|
|
/>
|
|
))}
|
|
|
|
{configVariable.type == "text" && (
|
|
<Textarea
|
|
style={{
|
|
width: "100%",
|
|
}}
|
|
disabled={!configVariable.allowEdit}
|
|
autosize
|
|
{...form.getInputProps("textValue")}
|
|
placeholder={configVariable.defaultValue}
|
|
onChange={(e) => onValueChange(configVariable, e.target.value)}
|
|
/>
|
|
)}
|
|
{configVariable.type == "number" && (
|
|
<NumberInput
|
|
{...form.getInputProps("numberValue")}
|
|
disabled={!configVariable.allowEdit}
|
|
placeholder={configVariable.defaultValue}
|
|
onChange={(number) => onValueChange(configVariable, number)}
|
|
w={201}
|
|
/>
|
|
)}
|
|
{configVariable.type == "filesize" && (
|
|
<FileSizeInput
|
|
{...form.getInputProps("numberValue")}
|
|
disabled={!configVariable.allowEdit}
|
|
value={parseInt(configVariable.value ?? configVariable.defaultValue)}
|
|
onChange={(bytes) => onValueChange(configVariable, bytes)}
|
|
w={201}
|
|
/>
|
|
)}
|
|
{configVariable.type == "boolean" && (
|
|
<>
|
|
<Switch
|
|
disabled={!configVariable.allowEdit}
|
|
{...form.getInputProps("booleanValue", { type: "checkbox" })}
|
|
onChange={(e) => onValueChange(configVariable, e.target.checked)}
|
|
/>
|
|
</>
|
|
)}
|
|
{configVariable.type == "timespan" && (
|
|
<TimespanInput
|
|
value={stringToTimespan(configVariable.value)}
|
|
disabled={!configVariable.allowEdit}
|
|
onChange={(timespan) =>
|
|
onValueChange(configVariable, timespanToString(timespan))
|
|
}
|
|
w={201}
|
|
/>
|
|
)}
|
|
</Stack>
|
|
);
|
|
};
|
|
|
|
export default AdminConfigInput;
|