From 0b7cdbce02c498fb70a9ab2ba954707c8f5afe98 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Mon, 14 Jul 2025 22:46:08 +0200 Subject: [PATCH] Update AuthSettings.tsx (#1006) --- .../src/entrypoints/popup/pages/AuthSettings.tsx | 15 ++++++++++----- .../src/locales/en/settings.json | 8 +++++++- .../src/locales/nl/settings.json | 8 +++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx index 657e943c9..3b83d3748 100644 --- a/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx +++ b/apps/browser-extension/src/entrypoints/popup/pages/AuthSettings.tsx @@ -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(true); const [errors, setErrors] = useState<{ apiUrl?: string; clientUrl?: string }>({}); const { setIsInitialLoading } = useLoading(); + + const urlSchema = createUrlSchema(t); useEffect(() => { /** diff --git a/apps/browser-extension/src/locales/en/settings.json b/apps/browser-extension/src/locales/en/settings.json index f24432f80..7510c4c85 100644 --- a/apps/browser-extension/src/locales/en/settings.json +++ b/apps/browser-extension/src/locales/en/settings.json @@ -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" + } } \ No newline at end of file diff --git a/apps/browser-extension/src/locales/nl/settings.json b/apps/browser-extension/src/locales/nl/settings.json index b85e786b8..1f538ce79 100644 --- a/apps/browser-extension/src/locales/nl/settings.json +++ b/apps/browser-extension/src/locales/nl/settings.json @@ -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" + } } \ No newline at end of file