mirror of
https://github.com/SamyRai/tercul-frontend.git
synced 2025-12-27 02:31:34 +00:00
Refactors the toast component's styling, updates DashboardLayout link components and exports a standalone toast function in useToast hook. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cbacfb18-842a-4116-a907-18c0105ad8ec Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/39b5c689-6e8a-4d5a-9792-69cc81a56534/f896073f-d218-43ce-a7c7-a9c09756cf37.jpg
61 lines
1.2 KiB
TypeScript
61 lines
1.2 KiB
TypeScript
// Basic toast hook for notifications
|
|
import { useState } from "react";
|
|
|
|
type ToastVariant = "default" | "destructive";
|
|
|
|
export interface ToastOptions {
|
|
title?: string;
|
|
description?: string;
|
|
variant?: ToastVariant;
|
|
duration?: number;
|
|
id?: number;
|
|
className?: string;
|
|
}
|
|
|
|
// Export stand-alone toast function for convenience
|
|
let addToast: (options: ToastOptions) => number = () => 0;
|
|
|
|
export function toast(options: ToastOptions) {
|
|
return addToast(options);
|
|
}
|
|
|
|
export function useToast() {
|
|
const [toasts, setToasts] = useState<ToastOptions[]>([]);
|
|
|
|
// Create a function that matches the expected signature
|
|
const toast = (options: ToastOptions) => {
|
|
const id = Date.now();
|
|
const newToast = {
|
|
...options,
|
|
id,
|
|
duration: options.duration || 3000,
|
|
};
|
|
|
|
setToasts((prev) => [...prev, newToast]);
|
|
|
|
// Auto dismiss
|
|
setTimeout(() => {
|
|
dismiss(id);
|
|
}, newToast.duration);
|
|
|
|
return id;
|
|
};
|
|
|
|
// Set the exported toast function to use this implementation
|
|
addToast = toast;
|
|
|
|
const dismiss = (id?: number) => {
|
|
if (id) {
|
|
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
} else {
|
|
setToasts([]);
|
|
}
|
|
};
|
|
|
|
return {
|
|
toast,
|
|
dismiss,
|
|
toasts
|
|
};
|
|
}
|