Merged in feature/IO-3255-simplified-part-management (pull request #2504)

feature/IO-3255-simplified-parts-management - Bug changes / Socket close cleanup
This commit is contained in:
Dave Richer
2025-08-22 18:26:38 +00:00
2 changed files with 15 additions and 16 deletions

View File

@@ -64,7 +64,7 @@ export default function ShopInfoContainer() {
onFinish={handleFinish} onFinish={handleFinish}
initialValues={ initialValues={
data data
? data.bodyshops[0].accountingconfig.ClosingPeriod ? data?.bodyshops?.[0]?.accountingconfig?.ClosingPeriod
? { ? {
...data.bodyshops[0], ...data.bodyshops[0],
accountingconfig: { accountingconfig: {

View File

@@ -167,7 +167,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
socketRef.current = socketInstance; socketRef.current = socketInstance;
const handleBodyshopMessage = (message) => { const handleBodyshopMessage = (message) => {
if (!message || !message.type) return; if (!message?.type) return;
switch (message.type) { switch (message.type) {
case "alert-update": case "alert-update":
store.dispatch(addAlerts(message.payload)); store.dispatch(addAlerts(message.payload));
@@ -512,22 +512,21 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => {
}; };
const unsubscribe = auth.onIdTokenChanged(async (user) => { const unsubscribe = auth.onIdTokenChanged(async (user) => {
if (user) { if (!user) {
socketRef.current?.disconnect();
socketRef.current = null;
setIsConnected(false);
return;
}
const token = await user.getIdToken(); const token = await user.getIdToken();
if (socketRef.current) { if (socketRef.current) {
socketRef.current.emit("update-token", { token, bodyshopId: bodyshop.id }); socketRef.current.emit("update-token", { token, bodyshopId: bodyshop.id });
} else { } else {
initializeSocket(token).catch((err) => initializeSocket(token).catch((err) =>
console.error(`Something went wrong Initializing Sockets: ${err?.message || ""}`) console.error("Something went wrong Initializing Sockets:", err?.message || "")
); );
} }
} else {
if (socketRef.current) {
socketRef.current.disconnect();
socketRef.current = null;
setIsConnected(false);
}
}
}); });
return () => { return () => {