Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.1 KB
Raw Blame
import {
	// eslint-disable-next-line no-restricted-imports
	createContext,
	// eslint-disable-next-line no-restricted-imports
	useContext,
	useMemo,
} from 'react';
import { notification } from 'antd';
import type { NotificationInstance } from 'antd/es/notification/interface';

type Notification = {
	notifications: NotificationInstance;
};

const defaultNotification: Notification = {
	notifications: {
		success: (): void => {},
		error: (): void => {},
		info: (): void => {},
		warning: (): void => {},
		open: (): void => {},
		destroy: (): void => {},
	},
};

export const NotificationContext =
	createContext<Notification>(defaultNotification);

export function NotificationProvider({
	children,
}: {
	children: JSX.Element;
}): JSX.Element {
	const [notificationApi, NotificationElement] = notification.useNotification();
	const notifications = useMemo(
		() => ({ notifications: notificationApi }),
		[notificationApi],
	);

	return (
		<NotificationContext.Provider value={notifications}>
			{NotificationElement}
			{children}
		</NotificationContext.Provider>
	);
}

export const useNotifications = (): Notification =>
	useContext(NotificationContext);