|
@@ -350,12 +350,17 @@ export function IntegrationsContent() {
|
|
|
// Optimistic UI update - immediately update the local state
|
|
// Optimistic UI update - immediately update the local state
|
|
|
setConnectedShops(prev => prev.map(shop => {
|
|
setConnectedShops(prev => prev.map(shop => {
|
|
|
if (shop.id === storeId) {
|
|
if (shop.id === storeId) {
|
|
|
|
|
+ // Ensure store_sync_config is always an array with proper structure
|
|
|
|
|
+ const currentConfig = Array.isArray(shop.store_sync_config) && shop.store_sync_config.length > 0
|
|
|
|
|
+ ? shop.store_sync_config[0]
|
|
|
|
|
+ : { enabled: false, sync_frequency: 'hourly' };
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
...shop,
|
|
...shop,
|
|
|
- store_sync_config: shop.store_sync_config?.map(config => ({
|
|
|
|
|
- ...config,
|
|
|
|
|
|
|
+ store_sync_config: [{
|
|
|
|
|
+ ...currentConfig,
|
|
|
enabled: newEnabled
|
|
enabled: newEnabled
|
|
|
- })) || [{ enabled: newEnabled }]
|
|
|
|
|
|
|
+ }]
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
return shop;
|
|
return shop;
|
|
@@ -399,12 +404,17 @@ export function IntegrationsContent() {
|
|
|
// Revert the optimistic update on error
|
|
// Revert the optimistic update on error
|
|
|
setConnectedShops(prev => prev.map(shop => {
|
|
setConnectedShops(prev => prev.map(shop => {
|
|
|
if (shop.id === storeId) {
|
|
if (shop.id === storeId) {
|
|
|
|
|
+ // Ensure store_sync_config is always an array with proper structure
|
|
|
|
|
+ const existingConfig = Array.isArray(shop.store_sync_config) && shop.store_sync_config.length > 0
|
|
|
|
|
+ ? shop.store_sync_config[0]
|
|
|
|
|
+ : { enabled: false, sync_frequency: 'hourly' };
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
...shop,
|
|
...shop,
|
|
|
- store_sync_config: shop.store_sync_config?.map(config => ({
|
|
|
|
|
- ...config,
|
|
|
|
|
|
|
+ store_sync_config: [{
|
|
|
|
|
+ ...existingConfig,
|
|
|
enabled: currentEnabled // Revert to original value
|
|
enabled: currentEnabled // Revert to original value
|
|
|
- })) || [{ enabled: currentEnabled }]
|
|
|
|
|
|
|
+ }]
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
return shop;
|
|
return shop;
|