diff --git a/app/src/app/[lng]/[inventory]/data/[step]/page.tsx b/app/src/app/[lng]/[inventory]/data/[step]/page.tsx index 4df7bc0a6..7ce5a35b5 100644 --- a/app/src/app/[lng]/[inventory]/data/[step]/page.tsx +++ b/app/src/app/[lng]/[inventory]/data/[step]/page.tsx @@ -480,6 +480,9 @@ export default function AddDataSteps({ {}, ); + const [disconnectingDataSourceId, setDisconnectingDataSourceId] = useState< + string | null + >(null); const [disconnectThirdPartyData, { isLoading: isDisconnectLoading }] = api.useDisconnectThirdPartyDataMutation(); @@ -487,17 +490,20 @@ export default function AddDataSteps({ source: DataSourceWithRelations, ) => { if (isSourceConnected(source)) { - source.inventoryValues!.forEach( - async (inventoryValue: InventoryValueAttributes) => { - await disconnectThirdPartyData({ - inventoryId: inventoryValue.inventoryId, - subCategoryId: inventoryValue.subCategoryId, - }).then((res: any) => { - // Todo show alert - onSearchDataSourcesClicked(); - }); - }, + setDisconnectingDataSourceId(source.datasourceId); + await Promise.all( + source.inventoryValues!.map( + async (inventoryValue: InventoryValueAttributes) => { + return await disconnectThirdPartyData({ + inventoryId: inventoryValue.inventoryId, + subCategoryId: inventoryValue.subCategoryId, + }); + }, + ), ); + // TODO show alert + setDisconnectingDataSourceId(null); + onSearchDataSourcesClicked(); } else { console.log("Something went wrong"); } @@ -748,7 +754,10 @@ export default function AddDataSteps({ px={6} py={4} onClick={() => onDisconnectThirdPartyData(source)} - isLoading={isDisconnectLoading} + isLoading={ + isDisconnectLoading && + source.datasourceId === disconnectingDataSourceId + } onMouseEnter={() => onButtonHover(source)} onMouseLeave={() => onMouseLeave(source)} leftIcon={}