Added opensubtitlescom provider validation

pull/2770/head
Anderson Shindy Oki 5 days ago
parent f15f35caa3
commit 65173279e5

@ -172,6 +172,14 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
settings: staged, settings: staged,
hooks: {}, hooks: {},
}, },
validate: {
settings: {
"settings-opensubtitlescom-username": (value) =>
/^.\S+@\S+$/.test(value)
? "Invalid Username. Do not use your e-mail."
: null,
},
},
}); });
const deletePayload = useCallback(() => { const deletePayload = useCallback(() => {
@ -188,6 +196,12 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
const submit = useCallback( const submit = useCallback(
(values: FormValues) => { (values: FormValues) => {
const result = form.validate();
if (result.hasErrors) {
return;
}
if (info && enabledProviders) { if (info && enabledProviders) {
const changes = { ...values.settings }; const changes = { ...values.settings };
const hooks = values.hooks; const hooks = values.hooks;
@ -204,7 +218,7 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
modals.closeAll(); modals.closeAll();
} }
}, },
[info, enabledProviders, modals, settingsKey], [info, enabledProviders, modals, settingsKey, form],
); );
const canSave = info !== null; const canSave = info !== null;
@ -249,43 +263,61 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
const label = value.name ?? capitalize(value.key); const label = value.name ?? capitalize(value.key);
const options = value.options ?? []; const options = value.options ?? [];
const error = form.errors[`settings.settings-${itemKey}-${key}`] ? (
<MantineText c="red" component="span" size="xs">
{form.errors[`settings.settings-${itemKey}-${key}`]}
</MantineText>
) : null;
switch (value.type) { switch (value.type) {
case "text": case "text":
elements.push( elements.push(
<Text <>
key={BuildKey(itemKey, key)} <Text
label={label} key={BuildKey(itemKey, key)}
settingKey={`settings-${itemKey}-${key}`} label={label}
></Text>, settingKey={`settings-${itemKey}-${key}`}
></Text>
{error}
</>,
); );
return; return;
case "password": case "password":
elements.push( elements.push(
<Password <>
key={BuildKey(itemKey, key)} <Password
label={label} key={BuildKey(itemKey, key)}
settingKey={`settings-${itemKey}-${key}`} label={label}
></Password>, settingKey={`settings-${itemKey}-${key}`}
></Password>
{error}
</>,
); );
return; return;
case "switch": case "switch":
elements.push( elements.push(
<Check <>
key={key} <Check
inline key={key}
label={label} inline
settingKey={`settings-${itemKey}-${key}`} label={label}
></Check>, settingKey={`settings-${itemKey}-${key}`}
></Check>
{error}
</>,
); );
return; return;
case "select": case "select":
elements.push( elements.push(
<GlobalSelector <>
key={key} <GlobalSelector
label={label} key={key}
settingKey={`settings-${itemKey}-${key}`} label={label}
options={options} settingKey={`settings-${itemKey}-${key}`}
></GlobalSelector>, options={options}
></GlobalSelector>
{error}
</>,
); );
return; return;
case "testbutton": case "testbutton":
@ -295,11 +327,14 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
return; return;
case "chips": case "chips":
elements.push( elements.push(
<Chips <>
key={key} <Chips
label={label} key={key}
settingKey={`settings-${itemKey}-${key}`} label={label}
></Chips>, settingKey={`settings-${itemKey}-${key}`}
></Chips>
{error}
</>,
); );
return; return;
default: default:
@ -308,7 +343,7 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
}); });
return <Stack gap="xs">{elements}</Stack>; return <Stack gap="xs">{elements}</Stack>;
}, [info]); }, [info, form]);
return ( return (
<SettingsProvider value={settings}> <SettingsProvider value={settings}>

Loading…
Cancel
Save