import React, { ReactNode } from "react" import type { Toast } from "react-hot-toast" import { toast as globalToast } from "react-hot-toast" import RefreshIcon from "../../fundamentals/icons/refresh-icon" import ToasterContainer from "../toaster-container" import ErrorState from "./error-state" import SavingState from "./saving-state" import SuccessState from "./success-state" type SaveNotificationProps = { toast: Toast icon?: ReactNode title?: string message?: string onSave: () => Promise reset: () => void } const SaveNotification: React.FC = ({ toast, icon, title = "Unsaved changes", message = "You have unsaved changes. Do you want to save and publish or discard them?", onSave, reset, }) => { const onDismiss = () => { reset() globalToast.dismiss(toast.id) } const handleSave = () => { globalToast.custom((t) => , { id: toast.id, }) onSave() .then(() => { globalToast.custom( (t) => , { id: toast.id, } ) }) .catch((_err) => { globalToast.custom( (t) => , { id: toast.id, } ) }) } return (
{getIcon(icon)}
{title} {message}
) } const ICON_SIZE = 20 function getIcon(icon?: any) { if (icon) { return React.cloneElement(icon, { size: ICON_SIZE, className: "text-grey-90", }) } else { return } } export default SaveNotification