Self-hosted dashboard and admin auth (#4837)
Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
This commit is contained in:
co-authored by
kartik-mem0
parent
15feaa8ac4
commit
db8ac61713
@@ -0,0 +1,56 @@
|
||||
"use client";
|
||||
|
||||
// Shadcn recommends Sonner for toasts. This module wraps Sonner so existing
|
||||
// toast({ title, description, variant }) calls work and render via <Toaster /> from @/components/ui/sonner.
|
||||
import * as React from "react";
|
||||
import { toast as sonnerToast } from "sonner";
|
||||
|
||||
export type ToastVariant = "default" | "destructive" | "success";
|
||||
|
||||
export type ToastOptions = {
|
||||
title?: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
variant?: ToastVariant;
|
||||
};
|
||||
|
||||
function toast(options: ToastOptions) {
|
||||
const { title, description, variant = "default" } = options;
|
||||
const message =
|
||||
title != null
|
||||
? String(title)
|
||||
: description != null
|
||||
? String(description)
|
||||
: "Notification";
|
||||
const opts =
|
||||
title != null && description != null
|
||||
? { description: String(description) }
|
||||
: {};
|
||||
|
||||
if (variant === "destructive") {
|
||||
sonnerToast.error(message, opts);
|
||||
} else if (variant === "success") {
|
||||
sonnerToast.success(message, opts);
|
||||
} else {
|
||||
sonnerToast(message, opts);
|
||||
}
|
||||
|
||||
return {
|
||||
id: "",
|
||||
dismiss: () => {},
|
||||
update: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
function useToast() {
|
||||
return React.useMemo(
|
||||
() => ({
|
||||
toasts: [],
|
||||
toast,
|
||||
dismiss: () => {},
|
||||
}),
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
export { sonnerToast as toastSonner };
|
||||
export { useToast, toast };
|
||||
Reference in New Issue
Block a user