From cce8823ac4fd6aaedd07c6bf60b5b2a448eb6028 Mon Sep 17 00:00:00 2001 From: adityamukherjee399 Date: Tue, 14 Jul 2026 23:10:26 +0530 Subject: [PATCH] fix --- .../notificationProvider/index.spec.tsx | 44 +++++++------- .../providers/notificationProvider/index.tsx | 25 ++++++-- .../core/src/contexts/notification/types.ts | 2 +- .../src/providers/notificationProvider.tsx | 57 +++++++++++++------ 4 files changed, 85 insertions(+), 43 deletions(-) diff --git a/packages/antd/src/providers/notificationProvider/index.spec.tsx b/packages/antd/src/providers/notificationProvider/index.spec.tsx index 0cf483d96f8ea..313a21c33cf63 100644 --- a/packages/antd/src/providers/notificationProvider/index.spec.tsx +++ b/packages/antd/src/providers/notificationProvider/index.spec.tsx @@ -22,6 +22,8 @@ describe("Antd useNotificationProvider", () => { }); const notificationOpenSpy = vi.spyOn(notification, "open"); + const notificationSuccessSpy = vi.spyOn(notification, "success"); + const notificationErrorSpy = vi.spyOn(notification, "error"); const notificationCloseSpy = vi.spyOn(notification, "destroy"); it("should render notification type succes notification", async () => { @@ -29,9 +31,9 @@ describe("Antd useNotificationProvider", () => { result.current.open?.(mockNotification); - expect(notificationOpenSpy).toHaveBeenCalledTimes(1); - expect(notificationOpenSpy).toHaveBeenCalledWith({ - ...mockNotification, + expect(notificationSuccessSpy).toHaveBeenCalledTimes(1); + expect(notificationSuccessSpy).toHaveBeenCalledWith({ + key: mockNotification.key, message: null, description: mockNotification.message, }); @@ -45,12 +47,11 @@ describe("Antd useNotificationProvider", () => { type: "error", }); - expect(notificationOpenSpy).toHaveBeenCalledTimes(1); - expect(notificationOpenSpy).toHaveBeenCalledWith({ - ...mockNotification, + expect(notificationErrorSpy).toHaveBeenCalledTimes(1); + expect(notificationErrorSpy).toHaveBeenCalledWith({ + key: mockNotification.key, message: null, description: mockNotification.message, - type: "error", }); }); @@ -62,9 +63,9 @@ describe("Antd useNotificationProvider", () => { description: "Notification Description", }); - expect(notificationOpenSpy).toHaveBeenCalledTimes(1); - expect(notificationOpenSpy).toHaveBeenCalledWith({ - ...mockNotification, + expect(notificationSuccessSpy).toHaveBeenCalledTimes(1); + expect(notificationSuccessSpy).toHaveBeenCalledWith({ + key: mockNotification.key, message: "Notification Description", description: "Test Notification Message", }); @@ -109,12 +110,16 @@ describe("Antd useNotificationProvider", () => { describe("using with Ant design's App component", () => { const openFn = vi.fn(); + const successFn = vi.fn(); + const errorFn = vi.fn(); const destroyFn = vi.fn(); beforeAll(() => { vi.spyOn(App, "useApp").mockReturnValue({ notification: { open: openFn, + success: successFn, + error: errorFn, destroy: destroyFn, }, } as unknown as ReturnType); @@ -132,9 +137,9 @@ describe("Antd useNotificationProvider", () => { }); await waitFor(() => { - expect(openFn).toHaveBeenCalledTimes(1); - expect(openFn).toHaveBeenCalledWith({ - ...mockNotification, + expect(successFn).toHaveBeenCalledTimes(1); + expect(successFn).toHaveBeenCalledWith({ + key: mockNotification.key, message: null, description: mockNotification.message, }); @@ -152,12 +157,11 @@ describe("Antd useNotificationProvider", () => { }); await waitFor(() => { - expect(openFn).toHaveBeenCalledTimes(1); - expect(openFn).toHaveBeenCalledWith({ - ...mockNotification, + expect(errorFn).toHaveBeenCalledTimes(1); + expect(errorFn).toHaveBeenCalledWith({ + key: mockNotification.key, message: null, description: mockNotification.message, - type: "error", }); }); }); @@ -173,9 +177,9 @@ describe("Antd useNotificationProvider", () => { }); await waitFor(() => { - expect(openFn).toHaveBeenCalledTimes(1); - expect(openFn).toHaveBeenCalledWith({ - ...mockNotification, + expect(successFn).toHaveBeenCalledTimes(1); + expect(successFn).toHaveBeenCalledWith({ + key: mockNotification.key, message: "Notification Description", description: "Test Notification Message", }); diff --git a/packages/antd/src/providers/notificationProvider/index.tsx b/packages/antd/src/providers/notificationProvider/index.tsx index 9d77c91325344..f833f9c812e06 100644 --- a/packages/antd/src/providers/notificationProvider/index.tsx +++ b/packages/antd/src/providers/notificationProvider/index.tsx @@ -39,12 +39,25 @@ export const useNotificationProvider = (): NotificationProvider => { closeIcon: <>, }); } else { - notification.open({ - key, - description: message, - message: description ?? null, - type, - }); + if ( + type === "success" || + type === "error" || + type === "info" || + type === "warning" + ) { + notification[type]({ + key, + description: message, + message: description ?? null, + }); + } else { + notification.open({ + key, + description: message, + message: description ?? null, + type, + }); + } } }, close: (key) => notification.destroy(key), diff --git a/packages/core/src/contexts/notification/types.ts b/packages/core/src/contexts/notification/types.ts index 6b09df9520ea6..977543515d79d 100644 --- a/packages/core/src/contexts/notification/types.ts +++ b/packages/core/src/contexts/notification/types.ts @@ -33,7 +33,7 @@ export type SuccessErrorNotification< export type OpenNotificationParams = { key?: string; message: string; - type: "success" | "error" | "progress"; + type?: "success" | "error" | "progress" | "info" | "warning"; description?: string; cancelMutation?: () => void; undoableTimeout?: number; diff --git a/packages/mantine/src/providers/notificationProvider.tsx b/packages/mantine/src/providers/notificationProvider.tsx index d4caf5b1e3d69..eeac429b16ce7 100644 --- a/packages/mantine/src/providers/notificationProvider.tsx +++ b/packages/mantine/src/providers/notificationProvider.tsx @@ -6,8 +6,13 @@ import { hideNotification, } from "@mantine/notifications"; import { ActionIcon, Box, Group, Text } from "@mantine/core"; -import { IconCheck, IconRotate2, IconX } from "@tabler/icons-react"; - +import { + IconCheck, + IconRotate2, + IconX, + IconInfoCircle, + IconAlertCircle, +} from "@tabler/icons-react"; import { RingCountdown } from "@components"; export const useNotificationProvider = (): NotificationProvider => { @@ -123,16 +128,41 @@ export const useNotificationProvider = (): NotificationProvider => { }); } } else { + const getIcon = (type?: "success" | "error" | "progress" | "info" | "warning") => { + switch (type) { + case "success": + return ; + case "error": + return ; + case "info": + return ; + case "warning": + return ; + default: + return undefined; + } + }; + + const getColor = (type?: "success" | "error" | "progress" | "info" | "warning") => { + switch (type) { + case "success": + return "primary"; + case "error": + return "red"; + case "info": + return "blue"; + case "warning": + return "orange"; + default: + return undefined; + } + }; + if (isNotificationActive(key)) { updateNotification({ id: key!, - color: type === "success" ? "primary" : "red", - icon: - type === "success" ? ( - - ) : ( - - ), + color: getColor(type), + icon: getIcon(type), message, title: description, autoClose: 5000, @@ -141,13 +171,8 @@ export const useNotificationProvider = (): NotificationProvider => { addNotification(key); showNotification({ id: key!, - color: type === "success" ? "primary" : "red", - icon: - type === "success" ? ( - - ) : ( - - ), + color: getColor(type), + icon: getIcon(type), message, title: description, onClose: () => {