3dfcb1585b
CI/CD / CI · API (dotnet build + test) (push) Successful in 42s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 28s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m9s
CI/CD / CI · Admin Web (tsc) (push) Successful in 37s
CI/CD / CI · Website (tsc) (push) Successful in 45s
CI/CD / CI · Koja (tsc) (push) Successful in 49s
CI/CD / Deploy · all services (push) Successful in 2m45s
Every notification surface now deep-links to where the staff member needs to act: - bell dropdown: clicking an actionable notification navigates and closes the dropdown (platform broadcasts still expand inline to show their text) - notifications page: rows navigate to the right page - in-app toast: gains a "View" action button - desktop/Windows popup: clicking it focuses the tab and navigates Routing is now permission-aware via a single resolver (notification-routes.ts): a new-order alert sends a kitchen user to /kds, a cashier to /pos, and a floor user to /tables — never to a page their role can't open; a waiter call → /tables. This also fixes the old bug where table_call_waiter (which carries a referenceId) wrongly routed to /kds. Toast/desktop clicks navigate client-side through a small event bridge mounted in the dashboard shell. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { toast } from "sonner";
|
|
import { ApiClientError } from "@/lib/api/client";
|
|
|
|
export type NotifyOptions = {
|
|
description?: string;
|
|
duration?: number;
|
|
/** Optional click-through button (e.g. "View" → navigate to the related page). */
|
|
action?: { label: string; onClick: () => void };
|
|
};
|
|
|
|
function baseOptions(opts?: NotifyOptions) {
|
|
return {
|
|
description: opts?.description,
|
|
duration: opts?.duration ?? 4000,
|
|
action: opts?.action
|
|
? { label: opts.action.label, onClick: opts.action.onClick }
|
|
: undefined,
|
|
};
|
|
}
|
|
|
|
/** Toast notifications — use for transient success/error/info across the app */
|
|
export const notify = {
|
|
success(message: string, opts?: NotifyOptions) {
|
|
toast.success(message, baseOptions(opts));
|
|
},
|
|
error(message: string, opts?: NotifyOptions) {
|
|
toast.error(message, { ...baseOptions(opts), duration: opts?.duration ?? 5500 });
|
|
},
|
|
warning(message: string, opts?: NotifyOptions) {
|
|
toast.warning(message, baseOptions(opts));
|
|
},
|
|
info(message: string, opts?: NotifyOptions) {
|
|
toast.info(message, baseOptions(opts));
|
|
},
|
|
loading(message: string) {
|
|
return toast.loading(message);
|
|
},
|
|
dismiss(id?: string | number) {
|
|
toast.dismiss(id);
|
|
},
|
|
promise<T>(
|
|
promise: Promise<T>,
|
|
messages: { loading: string; success: string; error?: string }
|
|
) {
|
|
return toast.promise(promise, {
|
|
loading: messages.loading,
|
|
success: messages.success,
|
|
error: messages.error ?? messages.loading,
|
|
});
|
|
},
|
|
};
|
|
|
|
export function getErrorMessage(err: unknown, fallback: string): string {
|
|
// ApiClientError.message is the raw (usually English) backend message; prefer
|
|
// the caller's localized fallback. For code-specific localized text, use the
|
|
// useApiError() hook instead of this helper.
|
|
if (err instanceof ApiClientError) return fallback;
|
|
if (err instanceof Error && err.message) return err.message;
|
|
return fallback;
|
|
}
|
|
|
|
export function notifyError(err: unknown, fallback: string) {
|
|
notify.error(getErrorMessage(err, fallback));
|
|
}
|