mirror of
https://github.com/swissmakers/swiss-datashare.git
synced 2026-04-09 09:37:01 +02:00
refactor: run formatter
This commit is contained in:
@@ -96,7 +96,9 @@ const AdminConfigInput = ({
|
||||
{configVariable.type == "timespan" && (
|
||||
<TimespanInput
|
||||
value={stringToTimespan(configVariable.value)}
|
||||
onChange={(timespan) => onValueChange(configVariable, timespanToString(timespan))}
|
||||
onChange={(timespan) =>
|
||||
onValueChange(configVariable, timespanToString(timespan))
|
||||
}
|
||||
w={201}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -3,81 +3,86 @@ import { Timespan } from "../../types/timespan.type";
|
||||
import { NativeSelect, NumberInput } from "@mantine/core";
|
||||
import useTranslate from "../../hooks/useTranslate.hook";
|
||||
|
||||
const TimespanInput = ({ label, value, onChange, ...restProps }: {
|
||||
label?: string,
|
||||
value: Timespan,
|
||||
onChange: (timespan: Timespan) => void,
|
||||
[key: string]: any,
|
||||
const TimespanInput = ({
|
||||
label,
|
||||
value,
|
||||
onChange,
|
||||
...restProps
|
||||
}: {
|
||||
label?: string;
|
||||
value: Timespan;
|
||||
onChange: (timespan: Timespan) => void;
|
||||
[key: string]: any;
|
||||
}) => {
|
||||
const [unit, setUnit] = useState(value.unit);
|
||||
const [inputValue, setInputValue] = useState(value.value);
|
||||
const t = useTranslate();
|
||||
|
||||
const version = inputValue == 1 ? "singular" : "plural";
|
||||
const unitSelect = (
|
||||
<NativeSelect
|
||||
data={[
|
||||
{
|
||||
value: "minutes",
|
||||
label: t(`upload.modal.expires.minute-${version}`),
|
||||
},
|
||||
{
|
||||
value: "hours",
|
||||
label: t(`upload.modal.expires.hour-${version}`),
|
||||
},
|
||||
{
|
||||
value: "days",
|
||||
label: t(`upload.modal.expires.day-${version}`),
|
||||
},
|
||||
{
|
||||
value: "weeks",
|
||||
label: t(`upload.modal.expires.week-${version}`),
|
||||
},
|
||||
{
|
||||
value: "months",
|
||||
label: t(`upload.modal.expires.month-${version}`),
|
||||
},
|
||||
{
|
||||
value: "years",
|
||||
label: t(`upload.modal.expires.year-${version}`),
|
||||
},
|
||||
]}
|
||||
value={unit}
|
||||
rightSectionWidth={28}
|
||||
styles={{
|
||||
input: {
|
||||
fontWeight: 500,
|
||||
borderTopLeftRadius: 0,
|
||||
borderBottomLeftRadius: 0,
|
||||
width: 120,
|
||||
marginRight: -2,
|
||||
},
|
||||
}}
|
||||
onChange={event => {
|
||||
const unit = event.currentTarget.value as Timespan["unit"];
|
||||
setUnit(unit);
|
||||
onChange({ value: inputValue, unit });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
const [unit, setUnit] = useState(value.unit);
|
||||
const [inputValue, setInputValue] = useState(value.value);
|
||||
const t = useTranslate();
|
||||
|
||||
return (
|
||||
<NumberInput
|
||||
label={label}
|
||||
value={inputValue}
|
||||
min={0}
|
||||
max={999999}
|
||||
precision={0}
|
||||
rightSection={unitSelect}
|
||||
rightSectionWidth={120}
|
||||
onChange={value => {
|
||||
const inputVal = value || 0;
|
||||
setInputValue(inputVal);
|
||||
onChange({ value: inputVal, unit });
|
||||
}}
|
||||
{...restProps}
|
||||
/>
|
||||
);
|
||||
const version = inputValue == 1 ? "singular" : "plural";
|
||||
const unitSelect = (
|
||||
<NativeSelect
|
||||
data={[
|
||||
{
|
||||
value: "minutes",
|
||||
label: t(`upload.modal.expires.minute-${version}`),
|
||||
},
|
||||
{
|
||||
value: "hours",
|
||||
label: t(`upload.modal.expires.hour-${version}`),
|
||||
},
|
||||
{
|
||||
value: "days",
|
||||
label: t(`upload.modal.expires.day-${version}`),
|
||||
},
|
||||
{
|
||||
value: "weeks",
|
||||
label: t(`upload.modal.expires.week-${version}`),
|
||||
},
|
||||
{
|
||||
value: "months",
|
||||
label: t(`upload.modal.expires.month-${version}`),
|
||||
},
|
||||
{
|
||||
value: "years",
|
||||
label: t(`upload.modal.expires.year-${version}`),
|
||||
},
|
||||
]}
|
||||
value={unit}
|
||||
rightSectionWidth={28}
|
||||
styles={{
|
||||
input: {
|
||||
fontWeight: 500,
|
||||
borderTopLeftRadius: 0,
|
||||
borderBottomLeftRadius: 0,
|
||||
width: 120,
|
||||
marginRight: -2,
|
||||
},
|
||||
}}
|
||||
onChange={(event) => {
|
||||
const unit = event.currentTarget.value as Timespan["unit"];
|
||||
setUnit(unit);
|
||||
onChange({ value: inputValue, unit });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<NumberInput
|
||||
label={label}
|
||||
value={inputValue}
|
||||
min={0}
|
||||
max={999999}
|
||||
precision={0}
|
||||
rightSection={unitSelect}
|
||||
rightSectionWidth={120}
|
||||
onChange={(value) => {
|
||||
const inputVal = value || 0;
|
||||
setInputValue(inputVal);
|
||||
onChange({ value: inputVal, unit });
|
||||
}}
|
||||
{...restProps}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default TimespanInput;
|
||||
|
||||
@@ -184,7 +184,10 @@ const CreateUploadModalBody = ({
|
||||
options.maxExpiration.value != 0 &&
|
||||
(form.values.never_expires ||
|
||||
expirationDate.isAfter(
|
||||
moment().add(options.maxExpiration.value, options.maxExpiration.unit),
|
||||
moment().add(
|
||||
options.maxExpiration.value,
|
||||
options.maxExpiration.unit,
|
||||
),
|
||||
))
|
||||
) {
|
||||
form.setFieldError(
|
||||
|
||||
@@ -31,8 +31,7 @@ const get = (key: string, configVariables: Config[]): any => {
|
||||
if (configVariable.type == "boolean") return value == "true";
|
||||
if (configVariable.type == "string" || configVariable.type == "text")
|
||||
return value;
|
||||
if (configVariable.type == "timespan")
|
||||
return stringToTimespan(value);
|
||||
if (configVariable.type == "timespan") return stringToTimespan(value);
|
||||
};
|
||||
|
||||
const finishSetup = async (): Promise<AdminConfig[]> => {
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
export type TimeUnit = "minutes" | "hours" | "days" | "weeks" | "months" | "years";
|
||||
export type TimeUnit =
|
||||
| "minutes"
|
||||
| "hours"
|
||||
| "days"
|
||||
| "weeks"
|
||||
| "months"
|
||||
| "years";
|
||||
export type Timespan = { value: number; unit: TimeUnit };
|
||||
|
||||
@@ -34,7 +34,7 @@ export const getExpirationPreview = (
|
||||
|
||||
export const timespanToString = (timespan: Timespan) => {
|
||||
return `${timespan.value} ${timespan.unit}`;
|
||||
}
|
||||
};
|
||||
|
||||
export const stringToTimespan = (value: string): Timespan => {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user