Skip to content

Feature/order cancel#201

Open
Srinjoy-git wants to merge 4 commits into
rdodiya:gssoc_developfrom
Srinjoy-git:feature/order-cancel
Open

Feature/order cancel#201
Srinjoy-git wants to merge 4 commits into
rdodiya:gssoc_developfrom
Srinjoy-git:feature/order-cancel

Conversation

@Srinjoy-git
Copy link
Copy Markdown

Overview

This PR adds cancel functionality for pending orders in the admin orders workflow.

Changes Made

  • Added a cancel button for orders with pending status
  • Added cancellation handling logic for order management
  • Improved workflow flexibility for restaurant staff
  • Updated UI flow to support order cancellation before cooking starts

Why This Feature?

In real restaurant operations, customers may cancel orders before preparation begins due to:

  • changed decisions
  • duplicate orders
  • waiter input mistakes
  • payment-related issues

Previously, pending orders could only move forward in the workflow. This feature improves real-world order management handling.

Files Updated

  • OrderCard.jsx
  • OrdersGrid.jsx
RestroHub-recording.mov

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pending status 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

  • handleStatusUpdate derives the next orders array from the orders value captured in the render that created this callback. Because updates are triggered after async work in OrderCard, 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) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants