Feature/order cancel#201
Open
Srinjoy-git wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds “cancel pending order” support to the admin orders UI workflow, allowing staff to stop an order before it progresses to cooking/billing.
Changes:
- Added a Cancel button for orders in
pendingstatus on the order card. - Added a cancellation handler that updates the order status to
cancelled(currently via mocked delay). - Updated orders grid status handler to remove cancelled orders from the local list (similar to completed orders).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| RestroHub-FrontEnd/src/components/admin/orders/orderComponents/OrdersGrid.jsx | Treats cancelled as a terminal status (removes order from list) in the status update handler. |
| RestroHub-FrontEnd/src/components/admin/orders/orderComponents/OrderCard.jsx | Adds cancel UI + handler for pending orders; updates layout to show action + cancel buttons side-by-side. |
Comments suppressed due to low confidence (1)
RestroHub-FrontEnd/src/components/admin/orders/orderComponents/OrdersGrid.jsx:115
handleStatusUpdatederives the nextordersarray from theordersvalue captured in the render that created this callback. Because updates are triggered after async work inOrderCard, two rapid status changes can race and the later call can overwrite the earlier change (e.g., re-introducing an order that was previously filtered out). Use a functional state update (and keep parent sync in the same place) so each update is based on the latest state.
const handleStatusUpdate = (orderId, newStatus) => {
if (newStatus === 'complete' || newStatus === 'cancelled') {
syncOrders(orders.filter((o) => o.id !== orderId));
} else {
syncOrders(orders.map((o) => (o.id === orderId ? { ...o, status: newStatus } : o)));
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Loader2, | ||
| X, | ||
| } from 'lucide-react'; | ||
| import api from "@services/common/api"; |
Comment on lines
+120
to
+135
| const handleCancel = async () => { | ||
| const isConfirmed = window.confirm("Are you sure you want to cancel this order?"); | ||
| if (!isConfirmed) return; | ||
|
|
||
| try { | ||
| setUpdating(true); | ||
|
|
||
| // 🔌 UNCOMMENT WHEN API READY | ||
| // await api.put(`/api/orders/${order.id}/status`, { status: 'cancelled' }); | ||
| // toast.success(`Order #${order.id} cancelled`); | ||
|
|
||
| await new Promise((resolve) => setTimeout(resolve, 400)); | ||
| onStatusUpdate(order.id, 'cancelled'); | ||
| } catch (err) { | ||
| console.error('Failed to cancel order:', err); | ||
| } finally { |
Comment on lines
+126
to
+129
|
|
||
| // 🔌 UNCOMMENT WHEN API READY | ||
| // await api.put(`/api/orders/${order.id}/status`, { status: 'cancelled' }); | ||
| // toast.success(`Order #${order.id} cancelled`); |
Comment on lines
+212
to
+232
| <button | ||
| onClick={handleAction} | ||
| disabled={updating} | ||
| className={`flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl transition-all text-sm font-semibold disabled:opacity-50 ${action.bg} ${action.text} ${action.hoverBg} ${action.border}`} | ||
| > | ||
| {updating ? ( | ||
| <Loader2 className="w-4 h-4 animate-spin" /> | ||
| ) : ( | ||
| <action.icon className="w-4 h-4" /> | ||
| )} | ||
| {action.label} | ||
| </button> | ||
| {order.status === 'pending' && ( | ||
| <button | ||
| onClick={handleCancel} | ||
| disabled={updating} | ||
| className="flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl transition-all text-sm font-semibold text-red-700 bg-red-50 hover:bg-red-100 border border-red-200 disabled:opacity-50" | ||
| > | ||
| <X className="w-4 h-4" /> | ||
| Cancel | ||
| </button> |
Comment on lines
+131
to
+133
| await new Promise((resolve) => setTimeout(resolve, 400)); | ||
| onStatusUpdate(order.id, 'cancelled'); | ||
| } catch (err) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds cancel functionality for pending orders in the admin orders workflow.
Changes Made
pendingstatusWhy This Feature?
In real restaurant operations, customers may cancel orders before preparation begins due to:
Previously, pending orders could only move forward in the workflow. This feature improves real-world order management handling.
Files Updated
OrderCard.jsxOrdersGrid.jsxRestroHub-recording.mov