feature/IO-3096-GlobalNotifications - Checkpoint - Splits are now in place

This commit is contained in:
Dave Richer
2025-03-03 11:41:10 -05:00
parent b5c03b8cf0
commit 35b92570e5
5 changed files with 85 additions and 34 deletions

View File

@@ -17,7 +17,17 @@ const SocketContext = createContext(null);
const INITIAL_NOTIFICATIONS = 10;
const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
/**
* Socket Provider - Scenario Notifications / Web Socket related items.
* @param children
* @param bodyshop
* @param navigate
* @param currentUser
* @param scenarioNotificationsOn
* @returns {JSX.Element}
* @constructor
*/
const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNotificationsOn }) => {
const socketRef = useRef(null);
const [clientId, setClientId] = useState(null);
const [isConnected, setIsConnected] = useState(false);
@@ -191,6 +201,11 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
};
const handleNotification = (data) => {
// Scenario Notifications have been disabled, bail.
if (!scenarioNotificationsOn) {
return;
}
const { jobId, jobRoNumber, notificationId, associationId, notifications } = data;
if (associationId !== userAssociationId) return;
@@ -295,6 +310,11 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
};
const handleSyncNotificationRead = ({ notificationId, timestamp }) => {
// Scenario Notifications have been disabled, bail.
if (!scenarioNotificationsOn) {
return;
}
try {
const notificationRef = client.cache.identify({
__typename: "notifications",
@@ -336,6 +356,11 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
};
const handleSyncAllNotificationsRead = ({ timestamp }) => {
// Scenario Notifications have been disabled, bail.
if (!scenarioNotificationsOn) {
return;
}
try {
const queryVars = {
limit: INITIAL_NOTIFICATIONS,
@@ -436,7 +461,8 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
clientId,
isConnected,
markNotificationRead,
markAllNotificationsRead
markAllNotificationsRead,
scenarioNotificationsOn
}}
>
{children}