pull/2770/head
Anderson Shindy Oki 3 days ago
parent 65173279e5
commit 49e70dadf0

@ -42,7 +42,7 @@ import {
} from "@/pages/Settings/utilities/SettingsProvider"; } from "@/pages/Settings/utilities/SettingsProvider";
import { BuildKey, useSelectorOptions } from "@/utilities"; import { BuildKey, useSelectorOptions } from "@/utilities";
import { ASSERT } from "@/utilities/console"; import { ASSERT } from "@/utilities/console";
import { ProviderInfo } from "./list"; import { ProviderInfo, ProviderList } from "./list";
type SettingsKey = type SettingsKey =
| "settings-general-enabled_providers" | "settings-general-enabled_providers"
@ -151,6 +151,27 @@ const SelectItem: AutocompleteProps["renderOption"] = ({ option }) => {
); );
}; };
const validation = ProviderList.map((provider) => {
return provider.inputs
?.map((input) => {
if (input.validation === undefined) {
return null;
}
return {
[`settings-${provider.key}-${input.key}`]: input.validation?.rule,
};
})
.filter((input) => input && Object.keys(input).length > 0)
.reduce((acc, curr) => {
return { ...acc, ...curr };
}, {});
})
.filter((provider) => provider && Object.keys(provider).length > 0)
.reduce((acc, item) => {
return { ...acc, ...item };
}, {});
const ProviderTool: FunctionComponent<ProviderToolProps> = ({ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
payload, payload,
enabledProviders, enabledProviders,
@ -173,12 +194,7 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
hooks: {}, hooks: {},
}, },
validate: { validate: {
settings: { settings: validation!,
"settings-opensubtitlescom-username": (value) =>
/^.\S+@\S+$/.test(value)
? "Invalid Username. Do not use your e-mail."
: null,
},
}, },
}); });

@ -1,6 +1,7 @@
import { ReactText } from "react";
import { SelectorOption } from "@/components"; import { SelectorOption } from "@/components";
type Text = string | number;
type Input<T, N> = { type Input<T, N> = {
type: N; type: N;
key: string; key: string;
@ -8,15 +9,18 @@ type Input<T, N> = {
name?: string; name?: string;
description?: string; description?: string;
options?: SelectorOption<string>[]; options?: SelectorOption<string>[];
validation?: {
rule: (value: string) => string | null;
};
}; };
type AvailableInput = type AvailableInput =
| Input<ReactText, "text"> | Input<Text, "text">
| Input<string, "password"> | Input<string, "password">
| Input<boolean, "switch"> | Input<boolean, "switch">
| Input<string, "select"> | Input<string, "select">
| Input<string, "testbutton"> | Input<string, "testbutton">
| Input<ReactText[], "chips">; | Input<Text[], "chips">;
export interface ProviderInfo { export interface ProviderInfo {
key: string; key: string;
@ -390,6 +394,12 @@ export const ProviderList: Readonly<ProviderInfo[]> = [
{ {
type: "text", type: "text",
key: "username", key: "username",
validation: {
rule: (value: string) =>
/^.\S+@\S+$/.test(value)
? "Invalid Username. Do not use your e-mail."
: null,
},
}, },
{ {
type: "password", type: "password",

Loading…
Cancel
Save