1d1027fab4
Added defensive programming by adding null checks for document object before accessing its properties and methods across multiple components (MultiSelect, ConfirmationModal, Dropdown, Modal). Also implemented lazy initialization for Firebase messaging to prevent SSR-related errors and ensure messaging is only initialized on the client side. These changes improve server-side rendering compatibility and prevent potential runtime errors.
26 lines
674 B
TypeScript
26 lines
674 B
TypeScript
"use client";
|
|
|
|
import { onMessage } from "firebase/messaging";
|
|
import { useEffect, type PropsWithChildren } from "react";
|
|
|
|
import { messaging } from "@/services/firebase";
|
|
import { toast } from "react-toastify";
|
|
|
|
const Notification = ({ children }: PropsWithChildren) => {
|
|
useEffect(() => {
|
|
const messagingInstance = messaging();
|
|
if (messagingInstance) {
|
|
onMessage(messagingInstance, (payload) => {
|
|
console.log("Message received. ", payload);
|
|
if (payload.notification) {
|
|
toast.success(payload.notification.title ?? "New Notification");
|
|
}
|
|
});
|
|
}
|
|
}, []);
|
|
|
|
return <>{children}</>;
|
|
};
|
|
|
|
export default Notification;
|