intgration page fix for user delveoper

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-10 12:02:27 +00:00
parent 6a056e3589
commit 3f49a2599e

View File

@@ -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'}`);