diff --git a/src/components/header/ButtonGroup.js b/src/components/header/ButtonGroup.js index 60b75b4..b1339a9 100644 --- a/src/components/header/ButtonGroup.js +++ b/src/components/header/ButtonGroup.js @@ -60,17 +60,18 @@ class ButtonGroup extends Component { } addSocketListeners = () => { - - // Remove existing listeners first to avoid duplicates - this.removeSocketListeners(); + // Remove existing listeners first to avoid duplicates + this.removeSocketListeners(); + + if (window.socketManager) { window.socketManager.on('cartUpdated', this.handleCartUpdated); - + } } removeSocketListeners = () => { - + if (window.socketManager) { window.socketManager.off('cartUpdated', this.handleCartUpdated); - + } } handleCartUpdated = (id,user,cart) => { diff --git a/src/pages/AdminPage.js b/src/pages/AdminPage.js index 5b8dac9..385557a 100644 --- a/src/pages/AdminPage.js +++ b/src/pages/AdminPage.js @@ -142,14 +142,16 @@ class AdminPage extends React.Component { addSocketListeners = () => { // Remove existing listeners first to avoid duplicates this.removeSocketListeners(); - window.socketManager.on('cartUpdated', this.handleCartUpdated); - + + if (window.socketManager) { + window.socketManager.on('cartUpdated', this.handleCartUpdated); + } } removeSocketListeners = () => { - - window.socketManager.off('cartUpdated', this.handleCartUpdated); - + if (window.socketManager) { + window.socketManager.off('cartUpdated', this.handleCartUpdated); + } } formatPrice = (price) => {