intgration page fix for user delveoper
This commit is contained in:
@@ -167,20 +167,12 @@ export default function Integration() {
|
|||||||
body: JSON.stringify(requestBody),
|
body: JSON.stringify(requestBody),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.success) {
|
// fetchAPI extracts the data field and throws on error
|
||||||
// Validation successful
|
// If we get here without error, validation was successful
|
||||||
setValidationStatuses(prev => ({
|
setValidationStatuses(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
[integrationId]: 'success',
|
[integrationId]: 'success',
|
||||||
}));
|
}));
|
||||||
} else {
|
|
||||||
// Validation failed
|
|
||||||
console.error(`Validation failed for ${integrationId}:`, data.error || data.message);
|
|
||||||
setValidationStatuses(prev => ({
|
|
||||||
...prev,
|
|
||||||
[integrationId]: 'error',
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(`Error validating ${integrationId}:`, error);
|
console.error(`Error validating ${integrationId}:`, error);
|
||||||
setValidationStatuses(prev => ({
|
setValidationStatuses(prev => ({
|
||||||
@@ -243,9 +235,11 @@ export default function Integration() {
|
|||||||
|
|
||||||
const promises = integrationIds.map(async (id) => {
|
const promises = integrationIds.map(async (id) => {
|
||||||
try {
|
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}/`);
|
const data = await fetchAPI(`/v1/system/settings/integrations/${id}/`);
|
||||||
if (data.success && data.data) {
|
if (data && typeof data === 'object') {
|
||||||
return { id, config: data.data };
|
return { id, config: data };
|
||||||
}
|
}
|
||||||
return { id, config: null };
|
return { id, config: null };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -403,21 +397,19 @@ export default function Integration() {
|
|||||||
body: JSON.stringify(configToSave),
|
body: JSON.stringify(configToSave),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.success) {
|
// fetchAPI extracts the data field and throws on error
|
||||||
toast.success(data.message || 'Settings saved successfully');
|
// If we get here without error, save was successful
|
||||||
setShowSettingsModal(false);
|
toast.success('Settings saved successfully');
|
||||||
// Reload settings - use setTimeout to avoid state update during render
|
setShowSettingsModal(false);
|
||||||
setTimeout(() => {
|
// Reload settings - use setTimeout to avoid state update during render
|
||||||
loadIntegrationSettings().then(() => {
|
setTimeout(() => {
|
||||||
// Trigger validation after settings are reloaded
|
loadIntegrationSettings().then(() => {
|
||||||
setTimeout(() => validateEnabledIntegrations(), 300);
|
// Trigger validation after settings are reloaded
|
||||||
}).catch(err => {
|
setTimeout(() => validateEnabledIntegrations(), 300);
|
||||||
console.error('Error reloading settings after save:', err);
|
}).catch(err => {
|
||||||
});
|
console.error('Error reloading settings after save:', err);
|
||||||
}, 100);
|
});
|
||||||
} else {
|
}, 100);
|
||||||
throw new Error(data.error || 'Failed to save settings');
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Error saving integration settings:', error);
|
console.error('Error saving integration settings:', error);
|
||||||
toast.error(`Failed to save settings: ${error.message || 'Unknown error'}`);
|
toast.error(`Failed to save settings: ${error.message || 'Unknown error'}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user