Update AuthSettings.tsx (#1006)

This commit is contained in:
Leendert de Borst
2025-07-14 22:46:08 +02:00
committed by Leendert de Borst
parent a963064dc8
commit 0b7cdbce02
3 changed files with 24 additions and 7 deletions

View File

@@ -21,10 +21,13 @@ const DEFAULT_OPTIONS: ApiOption[] = [
];
// Validation schema for URLs
const urlSchema = Yup.object().shape({
/**
* Creates a URL validation schema with localized error messages.
*/
const createUrlSchema = (t: (key: string) => string): Yup.ObjectSchema<{apiUrl: string; clientUrl: string}> => Yup.object().shape({
apiUrl: Yup.string()
.required('API URL is required')
.test('is-valid-api-url', 'Please enter a valid API URL', (value: string | undefined) => {
.required(t('validation.apiUrlRequired'))
.test('is-valid-api-url', t('validation.apiUrlInvalid'), (value: string | undefined) => {
if (!value) {
return true; // Allow empty for non-custom option
}
@@ -36,8 +39,8 @@ const urlSchema = Yup.object().shape({
}
}),
clientUrl: Yup.string()
.required('Client URL is required')
.test('is-valid-client-url', 'Please enter a valid client URL', (value: string | undefined) => {
.required(t('validation.clientUrlRequired'))
.test('is-valid-client-url', t('validation.clientUrlInvalid'), (value: string | undefined) => {
if (!value) {
return true; // Allow empty for non-custom option
}
@@ -61,6 +64,8 @@ const AuthSettings: React.FC = () => {
const [isGloballyEnabled, setIsGloballyEnabled] = useState<boolean>(true);
const [errors, setErrors] = useState<{ apiUrl?: string; clientUrl?: string }>({});
const { setIsInitialLoading } = useLoading();
const urlSchema = createUrlSchema(t);
useEffect(() => {
/**

View File

@@ -29,5 +29,11 @@
"keyboardShortcuts": "Keyboard Shortcuts",
"configureKeyboardShortcuts": "Configure keyboard shortcuts",
"configure": "Configure",
"versionPrefix": "Version "
"versionPrefix": "Version ",
"validation": {
"apiUrlRequired": "API URL is required",
"apiUrlInvalid": "Please enter a valid API URL",
"clientUrlRequired": "Client URL is required",
"clientUrlInvalid": "Please enter a valid client URL"
}
}

View File

@@ -29,5 +29,11 @@
"keyboardShortcuts": "Snelkoppelingen",
"configureKeyboardShortcuts": "Snelkoppelingen configureren",
"configure": "Configureren",
"versionPrefix": "Versie "
"versionPrefix": "Versie ",
"validation": {
"apiUrlRequired": "API URL is vereist",
"apiUrlInvalid": "Voer een geldige API URL in",
"clientUrlRequired": "Client URL is vereist",
"clientUrlInvalid": "Voer een geldige client URL in"
}
}