mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-21 06:11:45 +00:00
43173e2b33
Reservation toggle, todo/packing toggle and budget reorder were swallowing API errors after rolling back, so the user saw the change silently snap back with no explanation. Route those failures through the existing toast channel (new store/notify.ts bridges to window.__addToast, the same channel SystemNoticeBanner uses); the reservation toggle re-throws so ReservationsPanel's own translated toast finally fires. Also wire the existing parseInDev/checkInDev response validation into the maps and notification-test endpoints to catch contract drift in dev.
18 lines
776 B
TypeScript
18 lines
776 B
TypeScript
// 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)
|
|
}
|
|
}
|