1 import React, { useRef, useState } from 'react';
3 import { NotificationsContainer, NotificationsContext, createNotificationManager } from '@proton/components';
4 import type { Notification } from '@proton/components';
5 import noop from '@proton/utils/noop';
8 children: React.ReactNode;
11 const NotificationsTestProvider = ({ children }: Props) => {
12 const [notifications, setNotifications] = useState<Notification[]>([]);
13 const managerRef = useRef<ReturnType<typeof createNotificationManager>>();
14 if (!managerRef.current) {
15 managerRef.current = createNotificationManager(setNotifications as any, noop);
17 const manager = managerRef.current;
18 const { hideNotification, removeNotification, removeDuplicate } = manager;
21 <NotificationsContext.Provider value={manager}>
23 <NotificationsContainer
24 notifications={notifications}
25 removeNotification={removeNotification}
26 removeDuplicate={removeDuplicate}
27 hideNotification={hideNotification}
29 </NotificationsContext.Provider>
33 export default NotificationsTestProvider;