Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

776 B
Raw Blame
// Bridge for surfacing user-facing toasts from non-component code (Zustand
// slices, store actions) where the `useToast` hook isn't available. Mirrors the
// global `window.__addToast` channel that ToastContainer registers and that
// SystemNoticeBanner already uses for the same reason.

type NotifyType = 'success' | 'error' | 'warning' | 'info'

/**
 * Show a toast from outside the React tree. No-ops gracefully if the
 * ToastContainer hasn't registered its handler yet (e.g. very early boot),
 * so callers never have to guard for it.
 */
export function notify(message: string, type: NotifyType = 'info', duration?: number): void {
  if (typeof window !== 'undefined' && typeof window.__addToast === 'function') {
    window.__addToast(message, type, duration)
  }
}