Server-side, return 200 with success: false and a friendly message when sendTestNotification reports failure (the underlying call already swallows the error); reserve real 500s for unexpected exceptions. Client-side, teach usePost to honour the response body's success flag so success:false flips the toast to error without throwing through axios. Also tidy the toast container: drop icons, no wrapping, single-line ellipsis with a sensible max-width that hugs short messages.
26 lines
780 B
TypeScript
26 lines
780 B
TypeScript
import { toast, type ToastOptions } from "react-toastify";
|
|
|
|
export const useToast = () => {
|
|
const showToast = (message: string, options?: ToastOptions) => {
|
|
toast.dismiss();
|
|
const baseStyle: React.CSSProperties = {
|
|
whiteSpace: "nowrap",
|
|
overflow: "hidden",
|
|
textOverflow: "ellipsis",
|
|
};
|
|
toast(message, {
|
|
...options,
|
|
style: { ...baseStyle, ...(options?.style || {}) },
|
|
});
|
|
};
|
|
|
|
const toastSuccess = (msg: string, opts?: ToastOptions) =>
|
|
showToast(msg, { ...opts, type: "success" });
|
|
const toastError = (msg: string, opts?: ToastOptions) =>
|
|
showToast(msg, { ...opts, type: "error" });
|
|
const toastInfo = (msg: string, opts?: ToastOptions) =>
|
|
showToast(msg, { ...opts, type: "info" });
|
|
|
|
return { showToast, toastSuccess, toastError, toastInfo };
|
|
};
|