Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

721 B
Raw Blame
import type { Notification } from '@openpanel/db';
import { BellIcon } from 'lucide-react';
import { toast } from 'sonner';
import { useAppParams } from '@/hooks/use-app-params';
import useWS from '@/hooks/use-ws';

export function NotificationProvider() {
  const { projectId } = useAppParams();

  if (!projectId) {
    return null;
  }

  return <InnerNotificationProvider projectId={projectId} />;
}

export function InnerNotificationProvider({
  projectId,
}: {
  projectId: string;
}) {
  useWS<Notification>(`/live/notifications/${projectId}`, (notification) => {
    toast(notification.title, {
      description: notification.message,
      icon: <BellIcon className="size-4" />,
    });
  });

  return null;
}