aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAnderson Shindy Oki <[email protected]>2024-11-23 00:03:05 +0900
committerAnderson Shindy Oki <[email protected]>2024-11-26 15:24:53 +0900
commit65173279e55738965d1e1ea487829b9a958a12e6 (patch)
tree9516517139c627b59d1bb667820d476da7e171cc
parentf15f35caa3e7b5683d2f86b21db9b6fe93651e1b (diff)
downloadbazarr-65173279e55738965d1e1ea487829b9a958a12e6.tar.gz
bazarr-65173279e55738965d1e1ea487829b9a958a12e6.zip
Added opensubtitlescom provider validation
-rw-r--r--frontend/src/pages/Settings/Providers/components.tsx93
1 files changed, 64 insertions, 29 deletions
diff --git a/frontend/src/pages/Settings/Providers/components.tsx b/frontend/src/pages/Settings/Providers/components.tsx
index 5c37188a2..569b17808 100644
--- a/frontend/src/pages/Settings/Providers/components.tsx
+++ b/frontend/src/pages/Settings/Providers/components.tsx
@@ -172,6 +172,14 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
settings: staged,
hooks: {},
},
+ validate: {
+ settings: {
+ "settings-opensubtitlescom-username": (value) =>
+ /^.\S+@\S+$/.test(value)
+ ? "Invalid Username. Do not use your e-mail."
+ : null,
+ },
+ },
});
const deletePayload = useCallback(() => {
@@ -188,6 +196,12 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
const submit = useCallback(
(values: FormValues) => {
+ const result = form.validate();
+
+ if (result.hasErrors) {
+ return;
+ }
+
if (info && enabledProviders) {
const changes = { ...values.settings };
const hooks = values.hooks;
@@ -204,7 +218,7 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
modals.closeAll();
}
},
- [info, enabledProviders, modals, settingsKey],
+ [info, enabledProviders, modals, settingsKey, form],
);
const canSave = info !== null;
@@ -249,43 +263,61 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
const label = value.name ?? capitalize(value.key);
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) {
case "text":
elements.push(
- <Text
- key={BuildKey(itemKey, key)}
- label={label}
- settingKey={`settings-${itemKey}-${key}`}
- ></Text>,
+ <>
+ <Text
+ key={BuildKey(itemKey, key)}
+ label={label}
+ settingKey={`settings-${itemKey}-${key}`}
+ ></Text>
+ {error}
+ </>,
);
return;
case "password":
elements.push(
- <Password
- key={BuildKey(itemKey, key)}
- label={label}
- settingKey={`settings-${itemKey}-${key}`}
- ></Password>,
+ <>
+ <Password
+ key={BuildKey(itemKey, key)}
+ label={label}
+ settingKey={`settings-${itemKey}-${key}`}
+ ></Password>
+ {error}
+ </>,
);
return;
case "switch":
elements.push(
- <Check
- key={key}
- inline
- label={label}
- settingKey={`settings-${itemKey}-${key}`}
- ></Check>,
+ <>
+ <Check
+ key={key}
+ inline
+ label={label}
+ settingKey={`settings-${itemKey}-${key}`}
+ ></Check>
+ {error}
+ </>,
);
return;
case "select":
elements.push(
- <GlobalSelector
- key={key}
- label={label}
- settingKey={`settings-${itemKey}-${key}`}
- options={options}
- ></GlobalSelector>,
+ <>
+ <GlobalSelector
+ key={key}
+ label={label}
+ settingKey={`settings-${itemKey}-${key}`}
+ options={options}
+ ></GlobalSelector>
+ {error}
+ </>,
);
return;
case "testbutton":
@@ -295,11 +327,14 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
return;
case "chips":
elements.push(
- <Chips
- key={key}
- label={label}
- settingKey={`settings-${itemKey}-${key}`}
- ></Chips>,
+ <>
+ <Chips
+ key={key}
+ label={label}
+ settingKey={`settings-${itemKey}-${key}`}
+ ></Chips>
+ {error}
+ </>,
);
return;
default:
@@ -308,7 +343,7 @@ const ProviderTool: FunctionComponent<ProviderToolProps> = ({
});
return <Stack gap="xs">{elements}</Stack>;
- }, [info]);
+ }, [info, form]);
return (
<SettingsProvider value={settings}>