From d5617bd9c83667b10048fc6f66ab71ef872dd79c Mon Sep 17 00:00:00 2001 From: Reza Rahemtola Date: Mon, 9 Oct 2023 21:02:15 +0200 Subject: [PATCH] fix(web/editor): OAuth Account connection polling --- .../back/src/workflows/workflows.service.ts | 2 ++ .../editor/EditorSelectEventAndAccount.tsx | 21 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/backend/back/src/workflows/workflows.service.ts b/backend/back/src/workflows/workflows.service.ts index 7d18c431..03532a32 100644 --- a/backend/back/src/workflows/workflows.service.ts +++ b/backend/back/src/workflows/workflows.service.ts @@ -313,6 +313,7 @@ export class WorkflowsService { isAction ? "Action" : "Reaction" } ${areaId} with service ${areaServiceId} not found for workflow area ${id}.`, ); + // TODO Dorian: Clean this let serviceUserConnection: { scopes: any[]; } = await queryRunner.manager.findOne(UserConnection, { @@ -323,6 +324,7 @@ export class WorkflowsService { scopes: true, }, }); + // TODO Dorian: Remove next line if (!serviceUserConnection && areaServiceId === "timer") serviceUserConnection = { scopes: [] }; if (!serviceUserConnection) throw new NotFoundException(`User connection for ${areaServiceId} not found.`); const scopeIds = serviceUserConnection.scopes.map(({ id }) => id); diff --git a/frontend/web/layouts/editor/EditorSelectEventAndAccount.tsx b/frontend/web/layouts/editor/EditorSelectEventAndAccount.tsx index 0e508b63..7e7661cb 100644 --- a/frontend/web/layouts/editor/EditorSelectEventAndAccount.tsx +++ b/frontend/web/layouts/editor/EditorSelectEventAndAccount.tsx @@ -42,19 +42,18 @@ const EditorSelectEventAndAccount = ({ }, [selectedEventId]); useEffect(() => { + if (!accountConnectionInProgress) return () => {}; const accountConnectionCheck = setInterval(() => { (async () => { - if (accountConnectionInProgress) { - const chosenArea = areaChoices.find((area) => area.id === selectedEventId)!; - const connectService = await services.connections.connect( - workflowArea.areaService!.id, - chosenArea.serviceScopesNeeded, - ); + const chosenArea = areaChoices.find((area) => area.id === selectedEventId)!; + const connectService = await services.connections.connect( + workflowArea.areaService!.id, + chosenArea.serviceScopesNeeded, + ); - if (connectService.data && connectService.data.oauthUrl === null) { - setConnectAccountUrl(null); - setAccountConnectionInProgress(false); - } + if (connectService.data && connectService.data.oauthUrl === null) { + setConnectAccountUrl(null); + setAccountConnectionInProgress(false); } })(); }, 1000); @@ -62,7 +61,7 @@ const EditorSelectEventAndAccount = ({ return () => { clearInterval(accountConnectionCheck); }; - }, []); + }, [accountConnectionInProgress]); return (