diff --git a/frontend/src/pages/Settings/Integration.tsx b/frontend/src/pages/Settings/Integration.tsx index 7500c0d1..80f1e0e9 100644 --- a/frontend/src/pages/Settings/Integration.tsx +++ b/frontend/src/pages/Settings/Integration.tsx @@ -167,20 +167,12 @@ export default function Integration() { body: JSON.stringify(requestBody), }); - if (data.success) { - // Validation successful - setValidationStatuses(prev => ({ - ...prev, - [integrationId]: 'success', - })); - } else { - // Validation failed - console.error(`Validation failed for ${integrationId}:`, data.error || data.message); - setValidationStatuses(prev => ({ - ...prev, - [integrationId]: 'error', - })); - } + // fetchAPI extracts the data field and throws on error + // If we get here without error, validation was successful + setValidationStatuses(prev => ({ + ...prev, + [integrationId]: 'success', + })); } catch (error: any) { console.error(`Error validating ${integrationId}:`, error); setValidationStatuses(prev => ({ @@ -243,9 +235,11 @@ export default function Integration() { const promises = integrationIds.map(async (id) => { try { + // fetchAPI extracts 'data' field from {success: true, data: {...}} + // So 'data' here is the actual config object {id, enabled, apiKey, ...} const data = await fetchAPI(`/v1/system/settings/integrations/${id}/`); - if (data.success && data.data) { - return { id, config: data.data }; + if (data && typeof data === 'object') { + return { id, config: data }; } return { id, config: null }; } catch (error) { @@ -403,21 +397,19 @@ export default function Integration() { body: JSON.stringify(configToSave), }); - if (data.success) { - toast.success(data.message || 'Settings saved successfully'); - setShowSettingsModal(false); - // Reload settings - use setTimeout to avoid state update during render - setTimeout(() => { - loadIntegrationSettings().then(() => { - // Trigger validation after settings are reloaded - setTimeout(() => validateEnabledIntegrations(), 300); - }).catch(err => { - console.error('Error reloading settings after save:', err); - }); - }, 100); - } else { - throw new Error(data.error || 'Failed to save settings'); - } + // fetchAPI extracts the data field and throws on error + // If we get here without error, save was successful + toast.success('Settings saved successfully'); + setShowSettingsModal(false); + // Reload settings - use setTimeout to avoid state update during render + setTimeout(() => { + loadIntegrationSettings().then(() => { + // Trigger validation after settings are reloaded + setTimeout(() => validateEnabledIntegrations(), 300); + }).catch(err => { + console.error('Error reloading settings after save:', err); + }); + }, 100); } catch (error: any) { console.error('Error saving integration settings:', error); toast.error(`Failed to save settings: ${error.message || 'Unknown error'}`);