frontend: enhance webhook toggle functionality based on API key presence and improve error handling in test webhook url
This commit is contained in:
parent
7509c79afb
commit
bd8c0a7b5d
@ -117,7 +117,11 @@
|
|||||||
<h4 class="webhook-section-title">Webhook Notifications</h4>
|
<h4 class="webhook-section-title">Webhook Notifications</h4>
|
||||||
<div class="webhook-toggle ov-mt-xs">
|
<div class="webhook-toggle ov-mt-xs">
|
||||||
<span>Enable webhook notifications</span>
|
<span>Enable webhook notifications</span>
|
||||||
<mat-slide-toggle formControlName="isEnabled"></mat-slide-toggle>
|
<mat-slide-toggle
|
||||||
|
formControlName="isEnabled"
|
||||||
|
[matTooltip]="!canEnableWebhooks ? 'API key is required to enable webhooks' : ''"
|
||||||
|
[matTooltipDisabled]="canEnableWebhooks"
|
||||||
|
></mat-slide-toggle>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Webhook URL -->
|
<!-- Webhook URL -->
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Clipboard } from '@angular/cdk/clipboard';
|
import { Clipboard } from '@angular/cdk/clipboard';
|
||||||
import { Component, OnInit, signal } from '@angular/core';
|
import { Component, effect, OnInit, signal } from '@angular/core';
|
||||||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatCardModule } from '@angular/material/card';
|
import { MatCardModule } from '@angular/material/card';
|
||||||
@ -56,12 +56,24 @@ export class DevelopersSettingsComponent implements OnInit {
|
|||||||
protected clipboard: Clipboard
|
protected clipboard: Clipboard
|
||||||
) {
|
) {
|
||||||
// Disable url field initially and enable/disable based on isEnabled toggle
|
// Disable url field initially and enable/disable based on isEnabled toggle
|
||||||
this.webhookForm.get('url')?.disable();
|
const urlControl = this.webhookForm.get('url');
|
||||||
|
urlControl?.disable();
|
||||||
this.webhookForm.get('isEnabled')?.valueChanges.subscribe((isEnabled) => {
|
this.webhookForm.get('isEnabled')?.valueChanges.subscribe((isEnabled) => {
|
||||||
if (isEnabled) {
|
if (isEnabled) {
|
||||||
this.webhookForm.get('url')?.enable();
|
urlControl?.enable();
|
||||||
} else {
|
} else {
|
||||||
this.webhookForm.get('url')?.disable();
|
urlControl?.disable();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Disable webhook toggle initially and enable/disable based on API key presence
|
||||||
|
const webhookToggle = this.webhookForm.get('isEnabled');
|
||||||
|
webhookToggle?.disable();
|
||||||
|
effect(() => {
|
||||||
|
if (this.apiKeyData()) {
|
||||||
|
webhookToggle?.enable();
|
||||||
|
} else {
|
||||||
|
webhookToggle?.disable();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -129,6 +141,14 @@ export class DevelopersSettingsComponent implements OnInit {
|
|||||||
await this.authService.deleteApiKeys();
|
await this.authService.deleteApiKeys();
|
||||||
this.apiKeyData.set(undefined);
|
this.apiKeyData.set(undefined);
|
||||||
this.showApiKey.set(false);
|
this.showApiKey.set(false);
|
||||||
|
|
||||||
|
// Disable webhooks when API key is revoked
|
||||||
|
const webhookToggle = this.webhookForm.get('isEnabled');
|
||||||
|
if (webhookToggle?.value) {
|
||||||
|
webhookToggle.setValue(false);
|
||||||
|
await this.saveWebhookConfig();
|
||||||
|
}
|
||||||
|
|
||||||
this.notificationService.showSnackbar('API Key revoked successfully');
|
this.notificationService.showSnackbar('API Key revoked successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error revoking API key:', error);
|
console.error('Error revoking API key:', error);
|
||||||
@ -138,6 +158,10 @@ export class DevelopersSettingsComponent implements OnInit {
|
|||||||
|
|
||||||
// ===== WEBHOOK CONFIGURATION METHODS =====
|
// ===== WEBHOOK CONFIGURATION METHODS =====
|
||||||
|
|
||||||
|
get canEnableWebhooks(): boolean {
|
||||||
|
return !!this.apiKeyData();
|
||||||
|
}
|
||||||
|
|
||||||
private async loadWebhookConfig() {
|
private async loadWebhookConfig() {
|
||||||
try {
|
try {
|
||||||
const webhookPreferences = await this.preferencesService.getWebhookPreferences();
|
const webhookPreferences = await this.preferencesService.getWebhookPreferences();
|
||||||
@ -207,8 +231,10 @@ export class DevelopersSettingsComponent implements OnInit {
|
|||||||
try {
|
try {
|
||||||
await this.preferencesService.testWebhookUrl(url);
|
await this.preferencesService.testWebhookUrl(url);
|
||||||
this.notificationService.showSnackbar('Test webhook sent successfully. Your URL is reachable.');
|
this.notificationService.showSnackbar('Test webhook sent successfully. Your URL is reachable.');
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
this.notificationService.showSnackbar('Failed to send test webhook. Your URL may not be reachable.');
|
const errorMessage = error.error?.message || error.message || 'Unknown error';
|
||||||
|
this.notificationService.showSnackbar(`Failed to send test webhook. ${errorMessage}`);
|
||||||
|
console.error(`Error sending test webhook. ${errorMessage}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user