mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 06:00:55 +00:00
style: improve the ui of the toast for notifications
This commit is contained in:
@@ -4,8 +4,7 @@ import {
|
||||
type NotificationDto,
|
||||
} from "@edr/types";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useEffect } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { io } from "socket.io-client";
|
||||
|
||||
import { API_BASE_URL } from "@/constants/apiConfig";
|
||||
@@ -19,10 +18,16 @@ const SOCKET_ORIGIN = String(API_BASE_URL ?? "").replace(/\/api\/?$/, "");
|
||||
|
||||
/**
|
||||
* Subscribes to live notification pushes for the signed-in staff user. New
|
||||
* items invalidate the list + toast; unread-count pushes update the badge.
|
||||
* items invalidate the cached lists + fire `onNew` (the host shows a rich
|
||||
* toast); unread-count pushes update the badge.
|
||||
*/
|
||||
export function useNotificationSocket(enabled: boolean) {
|
||||
export function useNotificationSocket(
|
||||
enabled: boolean,
|
||||
onNew?: (notification: NotificationDto) => void,
|
||||
) {
|
||||
const qc = useQueryClient();
|
||||
const onNewRef = useRef(onNew);
|
||||
onNewRef.current = onNew;
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
@@ -37,7 +42,8 @@ export function useNotificationSocket(enabled: boolean) {
|
||||
|
||||
socket.on(NOTIFICATION_WS_EVENTS.NEW, (n: NotificationDto) => {
|
||||
qc.invalidateQueries({ queryKey: NOTIFICATIONS_KEY });
|
||||
toast(n.title);
|
||||
qc.invalidateQueries({ queryKey: UNREAD_KEY });
|
||||
onNewRef.current?.(n);
|
||||
});
|
||||
|
||||
socket.on(NOTIFICATION_WS_EVENTS.UNREAD_COUNT, (count: number) => {
|
||||
|
||||
Reference in New Issue
Block a user