Skip to content

Commit fc07fa1

Browse files
committed
fix(integrations): fix GitHub/Slack/Jira connect popup blocker, save button stuck, stale focus reload
1 parent 1851422 commit fc07fa1

1 file changed

Lines changed: 46 additions & 19 deletions

File tree

src/app/components/workspace-integrations/workspace-integrations.ts

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CommonModule } from '@angular/common';
22
import { Component, Input, OnInit, OnDestroy, OnChanges, SimpleChanges, inject } from '@angular/core';
33
import { ActivatedRoute } from '@angular/router';
4+
import { finalize } from 'rxjs';
45
import { IntegrationService } from '../../services/integration.service';
56
import { GitHubRepo, SyncStatus } from '../../models/github-integration.model';
67
import { SlackChannel } from '../../models/slack-integration.model';
@@ -82,15 +83,12 @@ export class WorkspaceIntegrationsComponent implements OnInit, OnChanges, OnDest
8283
}
8384

8485
private onWindowFocus = (): void => {
85-
// If we have an active feedback message, let's refresh to see if connection succeeded in background
86-
if (this.slackFeedbackMessage === 'Starting Slack connection...' ||
87-
this.githubFeedbackMessage === 'Starting GitHub connection...' ||
88-
this.jiraFeedbackMessage === 'Starting Jira connection...') {
89-
this.slackFeedbackMessage = '';
90-
this.githubFeedbackMessage = '';
91-
this.jiraFeedbackMessage = '';
92-
this.loadAllIntegrations();
93-
}
86+
// Always reload integrations when the tab regains focus so that OAuth
87+
// connections completed in another tab/window are picked up immediately.
88+
this.slackFeedbackMessage = this.slackFeedbackMessage === 'Starting Slack connection...' ? '' : this.slackFeedbackMessage;
89+
this.githubFeedbackMessage = this.githubFeedbackMessage === 'Starting GitHub connection...' ? '' : this.githubFeedbackMessage;
90+
this.jiraFeedbackMessage = this.jiraFeedbackMessage === 'Starting Jira connection...' ? '' : this.jiraFeedbackMessage;
91+
this.loadAllIntegrations();
9492
};
9593

9694
private loadAllIntegrations(): void {
@@ -102,8 +100,19 @@ export class WorkspaceIntegrationsComponent implements OnInit, OnChanges, OnDest
102100
connectSlack(): void {
103101
this.slackErrorMessage = '';
104102
this.slackFeedbackMessage = 'Starting Slack connection...';
105-
this.integrationService.connectSlack(this.workspaceId).subscribe({
103+
// Open the window synchronously (in the same click event) to avoid popup blockers,
104+
// then navigate it to the auth URL once the API returns it.
105+
const authWindow = window.open('', '_blank');
106+
this.integrationService.getSlackAuthUrl(this.workspaceId).subscribe({
107+
next: ({ authUrl }) => {
108+
if (authWindow) {
109+
authWindow.location.href = authUrl;
110+
} else {
111+
window.location.href = authUrl;
112+
}
113+
},
106114
error: (error: Error) => {
115+
authWindow?.close();
107116
this.slackErrorMessage = error.message;
108117
this.slackFeedbackMessage = '';
109118
}
@@ -120,8 +129,17 @@ export class WorkspaceIntegrationsComponent implements OnInit, OnChanges, OnDest
120129
connectGitHub(): void {
121130
this.githubErrorMessage = '';
122131
this.githubFeedbackMessage = 'Starting GitHub connection...';
123-
this.integrationService.connectGitHub(this.workspaceId).subscribe({
132+
const authWindow = window.open('', '_blank');
133+
this.integrationService.getGitHubAuthUrl(this.workspaceId).subscribe({
134+
next: ({ authUrl }) => {
135+
if (authWindow) {
136+
authWindow.location.href = authUrl;
137+
} else {
138+
window.location.href = authUrl;
139+
}
140+
},
124141
error: (error: Error) => {
142+
authWindow?.close();
125143
this.githubErrorMessage = error.message;
126144
this.githubFeedbackMessage = '';
127145
}
@@ -139,8 +157,17 @@ export class WorkspaceIntegrationsComponent implements OnInit, OnChanges, OnDest
139157
connectJira(): void {
140158
this.jiraErrorMessage = '';
141159
this.jiraFeedbackMessage = 'Starting Jira connection...';
142-
this.integrationService.connectJira(this.workspaceId).subscribe({
160+
const authWindow = window.open('', '_blank');
161+
this.integrationService.getJiraAuthUrl(this.workspaceId).subscribe({
162+
next: ({ authUrl }) => {
163+
if (authWindow) {
164+
authWindow.location.href = authUrl;
165+
} else {
166+
window.location.href = authUrl;
167+
}
168+
},
143169
error: (error: Error) => {
170+
authWindow?.close();
144171
this.jiraErrorMessage = error.message;
145172
this.jiraFeedbackMessage = '';
146173
}
@@ -185,15 +212,15 @@ export class WorkspaceIntegrationsComponent implements OnInit, OnChanges, OnDest
185212
saveSlackChannelSelection(): void {
186213
this.isSlackSaving = true;
187214
this.slackErrorMessage = '';
188-
this.integrationService.updateSlackChannels(this.workspaceId, this.selectedSlackChannelIds).subscribe({
215+
this.integrationService.updateSlackChannels(this.workspaceId, this.selectedSlackChannelIds).pipe(
216+
finalize(() => { this.isSlackSaving = false; })
217+
).subscribe({
189218
next: () => {
190-
this.isSlackSaving = false;
191219
this.slackFeedbackMessage = 'Slack channel selection saved.';
192220
this.loadSlackChannels();
193-
this.syncSlackNow(); // Trigger sync after saving selection
221+
this.syncSlackNow();
194222
},
195223
error: () => {
196-
this.isSlackSaving = false;
197224
this.slackErrorMessage = 'Could not save Slack channel selection.';
198225
}
199226
});
@@ -221,14 +248,14 @@ export class WorkspaceIntegrationsComponent implements OnInit, OnChanges, OnDest
221248
saveRepoSelection(): void {
222249
this.isGitHubSaving = true;
223250
this.githubErrorMessage = '';
224-
this.integrationService.updateGitHubRepos(this.workspaceId, this.selectedRepoIds).subscribe({
251+
this.integrationService.updateGitHubRepos(this.workspaceId, this.selectedRepoIds).pipe(
252+
finalize(() => { this.isGitHubSaving = false; })
253+
).subscribe({
225254
next: () => {
226-
this.isGitHubSaving = false;
227255
this.githubFeedbackMessage = 'Repository selection saved.';
228256
this.loadRepos();
229257
},
230258
error: () => {
231-
this.isGitHubSaving = false;
232259
this.githubErrorMessage = 'Could not save repository selection.';
233260
}
234261
});

0 commit comments

Comments
 (0)