Pulse/frontend-modern/src/utils/toast.ts
rcourtman 449d77504f Improve PMG connection testing to validate metrics endpoints
Related to #551

Enhanced the PMG connection test to actually validate the metrics
endpoints that Pulse uses for monitoring, rather than only checking
the version endpoint. This provides users with immediate feedback if
their PMG credentials lack the necessary permissions to collect metrics.

Backend changes:
- Test mail statistics, cluster status, and quarantine endpoints during
  connection test (internal/api/config_handlers.go:1695-1714)
- Return warnings array in test response when endpoints are unavailable
- Increased timeout from 10s to 15s to accommodate multiple endpoint checks
- Added warning logs for failed endpoint checks

Frontend changes:
- Added showWarning() toast function for warning messages
- Enhanced NodeModal to display warning status with amber styling
- Added warnings list display in test results UI
- Updated Settings.tsx to show warnings from connection tests

This change helps users identify permission issues immediately rather
than discovering later that metrics aren't being collected despite a
"successful" connection.
2025-11-05 18:40:39 +00:00

27 lines
992 B
TypeScript

import type { ToastType } from '@/components/Toast/Toast';
import { logger } from '@/utils/logger';
// Global declaration is in Toast.tsx
export const showToast = (
type: ToastType,
title: string,
message?: string,
duration?: number,
): string | undefined => {
if (typeof window !== 'undefined' && window.showToast) {
return window.showToast(type, title, message, duration);
}
// Fallback to console if toast system not ready
logger.info(`[toast:${type}] ${title}${message ? `: ${message}` : ''}`);
return undefined;
};
// Convenience functions - only export what's used
export const showSuccess = (title: string, message?: string, duration?: number) =>
showToast('success', title, message, duration);
export const showError = (title: string, message?: string, duration?: number) =>
showToast('error', title, message, duration);
export const showWarning = (title: string, message?: string, duration?: number) =>
showToast('warning', title, message, duration);