Files
pterodactyl-panel/resources/scripts/plugins/notifications.ts
T
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00

26 lines
729 B
TypeScript

import { toast, type ExternalToast } from 'sonner';
import { httpErrorToHuman } from '@/api/http';
type NotificationOptions = Pick<ExternalToast, 'action' | 'description' | 'duration' | 'id'>;
const DEFAULT_DURATION = 8000;
export const notifyServerError = (title: string, options: NotificationOptions = {}) =>
toast.error(title, {
duration: DEFAULT_DURATION,
...options,
});
export const notifyHttpError = (cause: unknown, title: string, options: NotificationOptions = {}) => {
console.error(cause);
return notifyServerError(title, {
description: httpErrorToHuman(cause),
...options,
});
};
export const dismissNotification = (id: string) => {
toast.dismiss(id);
};