added Callback and custon notification Toast, client notification event handler
This commit is contained in:
@@ -5,9 +5,12 @@ import { toast } from "react-hot-toast";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { ReactNode, useEffect, useState } from "react";
|
||||
import { dispatchSocket } from "dispatch/socket";
|
||||
import { Mission } from "@repo/db";
|
||||
import { Mission, NotificationPayload } from "@repo/db";
|
||||
import { HPGnotificationToast } from "_components/customToasts/HPGnotification";
|
||||
import { useMapStore } from "_store/mapStore";
|
||||
|
||||
export function QueryProvider({ children }: { children: ReactNode }) {
|
||||
const mapStore = useMapStore((s) => s);
|
||||
const [queryClient] = useState(
|
||||
() =>
|
||||
new QueryClient({
|
||||
@@ -48,15 +51,42 @@ export function QueryProvider({ children }: { children: ReactNode }) {
|
||||
});
|
||||
};
|
||||
|
||||
const handleNotification = (notification: NotificationPayload) => {
|
||||
console.log("notification", notification);
|
||||
switch (notification.type) {
|
||||
case "hpg-validation":
|
||||
toast.custom(
|
||||
(t) => <HPGnotificationToast event={notification} mapStore={mapStore} t={t} />,
|
||||
{
|
||||
duration: 9999,
|
||||
},
|
||||
);
|
||||
|
||||
break;
|
||||
default:
|
||||
toast(notification.message);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
dispatchSocket.on("update-mission", invalidateMission);
|
||||
dispatchSocket.on("delete-mission", invalidateMission);
|
||||
dispatchSocket.on("new-mission", invalidateMission);
|
||||
dispatchSocket.on("dispatchers-update", invalidateConnectedUsers);
|
||||
dispatchSocket.on("pilots-update", invalidateConnectedUsers);
|
||||
dispatchSocket.on("update-connectedAircraft", invalidateConenctedAircrafts);
|
||||
}, [queryClient]);
|
||||
dispatchSocket.on("notification", handleNotification);
|
||||
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
);
|
||||
return () => {
|
||||
dispatchSocket.off("update-mission", invalidateMission);
|
||||
dispatchSocket.off("delete-mission", invalidateMission);
|
||||
dispatchSocket.off("new-mission", invalidateMission);
|
||||
dispatchSocket.off("dispatchers-update", invalidateConnectedUsers);
|
||||
dispatchSocket.off("pilots-update", invalidateConnectedUsers);
|
||||
dispatchSocket.off("update-connectedAircraft", invalidateConenctedAircrafts);
|
||||
dispatchSocket.off("notification", handleNotification);
|
||||
};
|
||||
}, [queryClient, mapStore]);
|
||||
|
||||
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user