feat: Implement real-time stock updates using WebSockets (#178)#278
feat: Implement real-time stock updates using WebSockets (#178)#278devprashant19 wants to merge 1 commit into
Conversation
|
@devprashant19 is attempting to deploy a commit to the niharika-mente's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Review: Real-time stock updates via WebSockets. Check WebSocket server setup, stock update event triggers, client-side WebSocket connection, reconnection handling, and scalability with multiple clients. Document WebSocket endpoint. Hard difficulty appropriate. |
|
@Aamod-Dev please review it now |
Aamod-Dev
left a comment
There was a problem hiding this comment.
package-lock.json has unresolved merge conflict markers (<<<<<<< HEAD / >>>>>>> origin/main). This will break npm install.
Fix: Run npm install in BACKEND/ and FRONTEND/ to regenerate clean lockfiles, then commit.
09bd4df to
d809ea3
Compare
Aamod-Dev
left a comment
There was a problem hiding this comment.
Request Changes
- No backend code emits stockUpdate events. io server is created but no controller or model hook emits stock changes. Frontend listeners will never fire.
- socket instance created at module level in ProductCard.jsx and ProductPage.jsx. Connects on import for all users, even on pages that do not need it.
- test-socket.mjs should not be committed, or move to a test directory.
- Unrelated lint cleanup changes should be in a separate PR.
|
Missing backend WebSocket emission |
69b7e5b to
617fa71
Compare
Aamod-Dev
left a comment
There was a problem hiding this comment.
Looks good, approved!
Aamod-Dev
left a comment
There was a problem hiding this comment.
Needs changes: There are merge conflicts. Please resolve them.
617fa71 to
cbcf26e
Compare
Description
This Pull Request integrates Socket.io to push real-time stock updates from our Express backend to all connected React clients. This resolves the issue where users were forced to manually refresh the page to see if an item went out of stock.
Fixes #178
Changes Made
BACKEND/server.js,BACKEND/controllers/):socket.ioand wrapped the Express application in anhttp.Serverto attach the WebSocket server.io.emit("stockUpdate")inside thestripeWebhooklogic andupdateProductroute so that any stock reduction broadcasts globally.FRONTEND/src/pages/ProductPage.jsx,FRONTEND/src/components/ui/ProductCard.jsx):socket.io-clientand initialized a globalsocketconnection to the backend.useEffecthooks in the product view components to listen for incomingstockUpdateevents.Acceptance Criteria Met
stockUpdateevent containingproductIdandnewStockupon stock updates.ProductPageandProductCardcomponents.stockUpdateevents and dynamically update the UI in real-time.How to Test Locally
npm installin bothFRONTENDandBACKENDdirectories.npm run dev.