From 69da6bccf7c70e8caeb70f798039e71f1691c5b8 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Thu, 13 Mar 2025 17:37:36 -0400 Subject: [PATCH] IO-3096-GlobalNotifications - Adjust splits --- client/src/App/App.jsx | 16 ++-------------- client/src/contexts/SocketIO/useSocket.jsx | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/client/src/App/App.jsx b/client/src/App/App.jsx index af3c906a8..1cf4a8a06 100644 --- a/client/src/App/App.jsx +++ b/client/src/App/App.jsx @@ -48,8 +48,6 @@ export function App({ bodyshop, checkUserSession, currentUser, online, setOnline const { t } = useTranslation(); const navigate = useNavigate(); - const scenarioNotificationsOn = client?.getTreatment("Realtime_Notifications_UI") === "on"; - useEffect(() => { if (!navigator.onLine) { setOnline(false); @@ -203,12 +201,7 @@ export function App({ bodyshop, checkUserSession, currentUser, online, setOnline path="/manage/*" element={ - + @@ -220,12 +213,7 @@ export function App({ bodyshop, checkUserSession, currentUser, online, setOnline path="/tech/*" element={ - + diff --git a/client/src/contexts/SocketIO/useSocket.jsx b/client/src/contexts/SocketIO/useSocket.jsx index ee51def17..70f52311f 100644 --- a/client/src/contexts/SocketIO/useSocket.jsx +++ b/client/src/contexts/SocketIO/useSocket.jsx @@ -14,6 +14,7 @@ import { } from "../../graphql/notifications.queries.js"; import { useMutation } from "@apollo/client"; import { useTranslation } from "react-i18next"; +import { useSplitTreatments } from "@splitsoftware/splitio-react"; const SocketContext = createContext(null); @@ -25,11 +26,10 @@ const INITIAL_NOTIFICATIONS = 10; * @param bodyshop * @param navigate * @param currentUser - * @param scenarioNotificationsOn * @returns {JSX.Element} * @constructor */ -const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNotificationsOn }) => { +const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => { const socketRef = useRef(null); const [clientId, setClientId] = useState(null); const [isConnected, setIsConnected] = useState(false); @@ -37,6 +37,14 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot const userAssociationId = bodyshop?.associations?.[0]?.id; const { t } = useTranslation(); + const { + treatments: { Realtime_Notifications_UI } + } = useSplitTreatments({ + attributes: {}, + names: ["Realtime_Notifications_UI"], + splitKey: bodyshop?.imexshopid + }); + const [markNotificationRead] = useMutation(MARK_NOTIFICATION_READ, { update: (cache, { data: { update_notifications } }) => { const timestamp = new Date().toISOString(); @@ -209,7 +217,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot const handleNotification = (data) => { // Scenario Notifications have been disabled, bail. - if (!scenarioNotificationsOn) { + if (Realtime_Notifications_UI?.treatment !== "on") { return; } @@ -329,7 +337,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot const handleSyncNotificationRead = ({ notificationId, timestamp }) => { // Scenario Notifications have been disabled, bail. - if (!scenarioNotificationsOn) { + if (Realtime_Notifications_UI?.treatment !== "on") { return; } @@ -371,7 +379,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot const handleSyncAllNotificationsRead = ({ timestamp }) => { // Scenario Notifications have been disabled, bail. - if (!scenarioNotificationsOn) { + if (Realtime_Notifications_UI?.treatment !== "on") { return; } @@ -462,7 +470,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot markAllNotificationsRead, navigate, currentUser, - scenarioNotificationsOn, + Realtime_Notifications_UI, t ]); @@ -474,7 +482,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot isConnected, markNotificationRead, markAllNotificationsRead, - scenarioNotificationsOn + scenarioNotificationsOn: Realtime_Notifications_UI?.treatment === "on" }} > {children}