ng-implementation/my-workspace/projects/sae-lib/buttons/feedback-button/feedback-button.ts

63 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-08-08 16:43:50 +02:00
import {Component} from '@angular/core';
import {FormsModule} from '@angular/forms';
2025-09-25 16:22:43 +02:00
import {MainButton} from '../main-button/main-button';
import {NgClass} from '@angular/common';
2025-08-08 16:43:50 +02:00
@Component({
selector: 'sae-feedback-button',
imports: [
2025-09-25 16:22:43 +02:00
FormsModule,
MainButton,
NgClass
2025-08-08 16:43:50 +02:00
],
templateUrl: './feedback-button.html',
2025-09-25 16:22:43 +02:00
styleUrl: './feedback-button.scss'
2025-08-08 16:43:50 +02:00
})
export class FeedbackButton {
isModalOpen: boolean = false;
// isModalOpen: boolean = true;
2025-08-08 16:43:50 +02:00
feedbackText: string = '';
isSubmitting: boolean = false;
submitSuccess: boolean = false;
submitError: boolean = false;
protected readonly close = close;
2025-08-08 16:43:50 +02:00
toggleModal() {
this.isModalOpen = !this.isModalOpen;
// Reset state when opening modal
if (this.isModalOpen) {
this.feedbackText = '';
this.submitSuccess = false;
this.submitError = false;
}
}
async submitFeedback() {
if (!this.feedbackText.trim()) {
return; // Don't submit empty feedback
}
this.isSubmitting = true;
this.submitSuccess = false;
this.submitError = false;
try {
this.submitSuccess = true;
// Close modal after a short delay
setTimeout(() => {
this.toggleModal();
}, 2000);
} catch (error) {
console.error('Error submitting feedback:', error);
this.submitError = true;
} finally {
this.isSubmitting = false;
}
}
}