mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 03:17:56 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
26 lines
729 B
TypeScript
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);
|
|
};
|