Compare commits

...
Author SHA1 Message Date
Ludy87 93d816750f Sync provider settings and fix default initialization
Added useEffect to ProviderCard to keep local settings in sync with incoming settings when collapsed. Improved default settings initialization to preserve values from settings.yml. Passed settings prop to ProviderCard in AdminConnectionsSection to ensure correct settings are used.
2025-12-21 00:00:42 +01:00
2 changed files with 12 additions and 3 deletions
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { Paper, Group, Text, Button, Collapse, Stack, TextInput, Textarea, Switch, PasswordInput } from '@mantine/core';
import { useTranslation } from 'react-i18next';
import LocalIcon from '@app/components/shared/LocalIcon';
@@ -25,14 +25,22 @@ export default function ProviderCard({
const [expanded, setExpanded] = useState(false);
const [localSettings, setLocalSettings] = useState<Record<string, any>>(settings);
// Keep local settings in sync with incoming settings (values loaded from settings.yml)
useEffect(() => {
if (!expanded) {
setLocalSettings(settings);
}
}, [settings, expanded]);
// Initialize local settings with defaults when opening an unconfigured provider
const handleConnectToggle = () => {
if (!isConfigured && !expanded) {
// First time opening an unconfigured provider - initialize with defaults
const defaultSettings: Record<string, any> = {};
// while preserving any values already present (from settings.yml)
const defaultSettings: Record<string, any> = { ...settings };
provider.fields.forEach((field) => {
if (field.defaultValue !== undefined) {
defaultSettings[field.key] = field.defaultValue;
defaultSettings[field.key] = defaultSettings[field.key] ?? field.defaultValue;
}
});
setLocalSettings(defaultSettings);
@@ -422,6 +422,7 @@ export default function AdminConnectionsSection() {
key={provider.id}
provider={provider}
isConfigured={false}
settings={getProviderSettings(provider)}
onSave={(providerSettings) => handleProviderSave(provider, providerSettings)}
disabled={!loginEnabled}
/>