IO-3096-GlobalNotifications - Adjust splits

This commit is contained in:
Dave Richer
2025-03-13 17:37:36 -04:00
parent e3d7ebd7d8
commit 69da6bccf7
2 changed files with 17 additions and 21 deletions

View File

@@ -48,8 +48,6 @@ export function App({ bodyshop, checkUserSession, currentUser, online, setOnline
const { t } = useTranslation(); const { t } = useTranslation();
const navigate = useNavigate(); const navigate = useNavigate();
const scenarioNotificationsOn = client?.getTreatment("Realtime_Notifications_UI") === "on";
useEffect(() => { useEffect(() => {
if (!navigator.onLine) { if (!navigator.onLine) {
setOnline(false); setOnline(false);
@@ -203,12 +201,7 @@ export function App({ bodyshop, checkUserSession, currentUser, online, setOnline
path="/manage/*" path="/manage/*"
element={ element={
<ErrorBoundary> <ErrorBoundary>
<SocketProvider <SocketProvider bodyshop={bodyshop} navigate={navigate} currentUser={currentUser}>
bodyshop={bodyshop}
navigate={navigate}
currentUser={currentUser}
scenarioNotificationsOn={scenarioNotificationsOn}
>
<PrivateRoute isAuthorized={currentUser.authorized} /> <PrivateRoute isAuthorized={currentUser.authorized} />
</SocketProvider> </SocketProvider>
</ErrorBoundary> </ErrorBoundary>
@@ -220,12 +213,7 @@ export function App({ bodyshop, checkUserSession, currentUser, online, setOnline
path="/tech/*" path="/tech/*"
element={ element={
<ErrorBoundary> <ErrorBoundary>
<SocketProvider <SocketProvider bodyshop={bodyshop} navigate={navigate} currentUser={currentUser}>
bodyshop={bodyshop}
navigate={navigate}
currentUser={currentUser}
scenarioNotificationsOn={scenarioNotificationsOn}
>
<PrivateRoute isAuthorized={currentUser.authorized} /> <PrivateRoute isAuthorized={currentUser.authorized} />
</SocketProvider> </SocketProvider>
</ErrorBoundary> </ErrorBoundary>

View File

@@ -14,6 +14,7 @@ import {
} from "../../graphql/notifications.queries.js"; } from "../../graphql/notifications.queries.js";
import { useMutation } from "@apollo/client"; import { useMutation } from "@apollo/client";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useSplitTreatments } from "@splitsoftware/splitio-react";
const SocketContext = createContext(null); const SocketContext = createContext(null);
@@ -25,11 +26,10 @@ const INITIAL_NOTIFICATIONS = 10;
* @param bodyshop * @param bodyshop
* @param navigate * @param navigate
* @param currentUser * @param currentUser
* @param scenarioNotificationsOn
* @returns {JSX.Element} * @returns {JSX.Element}
* @constructor * @constructor
*/ */
const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNotificationsOn }) => { const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
const socketRef = useRef(null); const socketRef = useRef(null);
const [clientId, setClientId] = useState(null); const [clientId, setClientId] = useState(null);
const [isConnected, setIsConnected] = useState(false); const [isConnected, setIsConnected] = useState(false);
@@ -37,6 +37,14 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot
const userAssociationId = bodyshop?.associations?.[0]?.id; const userAssociationId = bodyshop?.associations?.[0]?.id;
const { t } = useTranslation(); const { t } = useTranslation();
const {
treatments: { Realtime_Notifications_UI }
} = useSplitTreatments({
attributes: {},
names: ["Realtime_Notifications_UI"],
splitKey: bodyshop?.imexshopid
});
const [markNotificationRead] = useMutation(MARK_NOTIFICATION_READ, { const [markNotificationRead] = useMutation(MARK_NOTIFICATION_READ, {
update: (cache, { data: { update_notifications } }) => { update: (cache, { data: { update_notifications } }) => {
const timestamp = new Date().toISOString(); const timestamp = new Date().toISOString();
@@ -209,7 +217,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot
const handleNotification = (data) => { const handleNotification = (data) => {
// Scenario Notifications have been disabled, bail. // Scenario Notifications have been disabled, bail.
if (!scenarioNotificationsOn) { if (Realtime_Notifications_UI?.treatment !== "on") {
return; return;
} }
@@ -329,7 +337,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot
const handleSyncNotificationRead = ({ notificationId, timestamp }) => { const handleSyncNotificationRead = ({ notificationId, timestamp }) => {
// Scenario Notifications have been disabled, bail. // Scenario Notifications have been disabled, bail.
if (!scenarioNotificationsOn) { if (Realtime_Notifications_UI?.treatment !== "on") {
return; return;
} }
@@ -371,7 +379,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot
const handleSyncAllNotificationsRead = ({ timestamp }) => { const handleSyncAllNotificationsRead = ({ timestamp }) => {
// Scenario Notifications have been disabled, bail. // Scenario Notifications have been disabled, bail.
if (!scenarioNotificationsOn) { if (Realtime_Notifications_UI?.treatment !== "on") {
return; return;
} }
@@ -462,7 +470,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot
markAllNotificationsRead, markAllNotificationsRead,
navigate, navigate,
currentUser, currentUser,
scenarioNotificationsOn, Realtime_Notifications_UI,
t t
]); ]);
@@ -474,7 +482,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser, scenarioNot
isConnected, isConnected,
markNotificationRead, markNotificationRead,
markAllNotificationsRead, markAllNotificationsRead,
scenarioNotificationsOn scenarioNotificationsOn: Realtime_Notifications_UI?.treatment === "on"
}} }}
> >
{children} {children}