From e990781ff7c6858270e7cf96349999281f4fb6a9 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 22 Aug 2025 14:24:03 -0400 Subject: [PATCH] feature/IO-3255-simplified-parts-management - Bug changes / Socket close cleanup --- .../shop-info/shop-info.container.jsx | 2 +- .../src/contexts/SocketIO/socketProvider.jsx | 29 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/client/src/components/shop-info/shop-info.container.jsx b/client/src/components/shop-info/shop-info.container.jsx index 7102397ed..afcd7968d 100644 --- a/client/src/components/shop-info/shop-info.container.jsx +++ b/client/src/components/shop-info/shop-info.container.jsx @@ -64,7 +64,7 @@ export default function ShopInfoContainer() { onFinish={handleFinish} initialValues={ data - ? data.bodyshops[0].accountingconfig.ClosingPeriod + ? data?.bodyshops?.[0]?.accountingconfig?.ClosingPeriod ? { ...data.bodyshops[0], accountingconfig: { diff --git a/client/src/contexts/SocketIO/socketProvider.jsx b/client/src/contexts/SocketIO/socketProvider.jsx index b5119aed8..b118e3fb6 100644 --- a/client/src/contexts/SocketIO/socketProvider.jsx +++ b/client/src/contexts/SocketIO/socketProvider.jsx @@ -167,7 +167,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => { socketRef.current = socketInstance; const handleBodyshopMessage = (message) => { - if (!message || !message.type) return; + if (!message?.type) return; switch (message.type) { case "alert-update": store.dispatch(addAlerts(message.payload)); @@ -512,21 +512,20 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => { }; const unsubscribe = auth.onIdTokenChanged(async (user) => { - if (user) { - const token = await user.getIdToken(); - if (socketRef.current) { - socketRef.current.emit("update-token", { token, bodyshopId: bodyshop.id }); - } else { - initializeSocket(token).catch((err) => - console.error(`Something went wrong Initializing Sockets: ${err?.message || ""}`) - ); - } + if (!user) { + socketRef.current?.disconnect(); + socketRef.current = null; + setIsConnected(false); + return; + } + + const token = await user.getIdToken(); + if (socketRef.current) { + socketRef.current.emit("update-token", { token, bodyshopId: bodyshop.id }); } else { - if (socketRef.current) { - socketRef.current.disconnect(); - socketRef.current = null; - setIsConnected(false); - } + initializeSocket(token).catch((err) => + console.error("Something went wrong Initializing Sockets:", err?.message || "") + ); } });