Skip to content

Commit

Permalink
Merge pull request #413 from Open-Earth-Foundation/fix/disconnecting-…
Browse files Browse the repository at this point in the history
…source-progress-indicator

fix(ui): disconnecting source progress indicator being enabled for all sources
  • Loading branch information
lemilonkh committed Apr 15, 2024
2 parents b5737b4 + 1640b83 commit 5917cfa
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions app/src/app/[lng]/[inventory]/data/[step]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,24 +480,30 @@ export default function AddDataSteps({
{},
);

const [disconnectingDataSourceId, setDisconnectingDataSourceId] = useState<
string | null
>(null);
const [disconnectThirdPartyData, { isLoading: isDisconnectLoading }] =
api.useDisconnectThirdPartyDataMutation();

const onDisconnectThirdPartyData = async (
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");
}
Expand Down Expand Up @@ -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={<Icon as={MdCheckCircle} />}
Expand Down

0 comments on commit 5917cfa

Please sign in to comment.