* More email share vars + unfinished placeolders config
{desc} {expires} vars
(unfinished) config placeholder vals
* done
* migrate
* edit seed
* removed comments
* refactor: replace dependecy `luxon` with `moment`
* update shareRecipientsMessage message
* chore: remove `luxon`
* fix: grammatically incorrect `shareRecipientsMessage` message
* changed to defaultValue and value instead
* fix: don't expose defaultValue to non admin user
* fix: update default value if default value changes
* refactor: set config value to null instead of a empty string
* refactor: merge two migrations into one
* fix value check empty
---------
Co-authored-by: Elias Schneider <login@eliasschneider.com>
89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
import {
|
|
NumberInput,
|
|
PasswordInput,
|
|
Stack,
|
|
Switch,
|
|
Textarea,
|
|
TextInput,
|
|
} from "@mantine/core";
|
|
import { useForm } from "@mantine/form";
|
|
import { AdminConfig, UpdateConfig } from "../../../types/config.type";
|
|
|
|
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
|
|
style={{
|
|
width: "100%",
|
|
}}
|
|
{...form.getInputProps("stringValue")}
|
|
onChange={(e) => onValueChange(configVariable, e.target.value)}
|
|
/>
|
|
) : (
|
|
<TextInput
|
|
style={{
|
|
width: "100%",
|
|
}}
|
|
{...form.getInputProps("stringValue")}
|
|
placeholder={configVariable.defaultValue}
|
|
onChange={(e) => onValueChange(configVariable, e.target.value)}
|
|
/>
|
|
))}
|
|
|
|
{configVariable.type == "text" && (
|
|
<Textarea
|
|
style={{
|
|
width: "100%",
|
|
}}
|
|
autosize
|
|
{...form.getInputProps("textValue")}
|
|
placeholder={configVariable.defaultValue}
|
|
onChange={(e) => onValueChange(configVariable, e.target.value)}
|
|
/>
|
|
)}
|
|
{configVariable.type == "number" && (
|
|
<NumberInput
|
|
{...form.getInputProps("numberValue")}
|
|
placeholder={configVariable.defaultValue}
|
|
onChange={(number) => onValueChange(configVariable, number)}
|
|
/>
|
|
)}
|
|
{configVariable.type == "boolean" && (
|
|
<>
|
|
<Switch
|
|
{...form.getInputProps("booleanValue", { type: "checkbox" })}
|
|
onChange={(e) => onValueChange(configVariable, e.target.checked)}
|
|
/>
|
|
</>
|
|
)}
|
|
</Stack>
|
|
);
|
|
};
|
|
|
|
export default AdminConfigInput;
|