Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Phone,
MoreVertical,
Loader2,
X,
} from 'lucide-react';
import api from "@services/common/api";
Comment thread
Srinjoy-git marked this conversation as resolved.

Expand Down Expand Up @@ -116,6 +117,26 @@ const OrderCard = ({ order, onStatusUpdate }) => {
}
};

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`);
Comment thread
Srinjoy-git marked this conversation as resolved.

await new Promise((resolve) => setTimeout(resolve, 400));
onStatusUpdate(order.id, 'cancelled');
} catch (err) {
Comment thread
Srinjoy-git marked this conversation as resolved.
console.error('Failed to cancel order:', err);
} finally {
Comment thread
Srinjoy-git marked this conversation as resolved.
setUpdating(false);
}
};

// ------------------------------------
// RENDER
// ------------------------------------
Expand Down Expand Up @@ -187,18 +208,30 @@ const OrderCard = ({ order, onStatusUpdate }) => {

{/* Action Button - NO WHITE TEXT */}
{action && (
<button
onClick={handleAction}
disabled={updating}
className={`w-full 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" />
<div className="flex items-center gap-2">
<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 thread
Srinjoy-git marked this conversation as resolved.
)}
{action.label}
</button>
</div>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const OrdersGrid = ({ activeFilter, searchQuery, onOrdersChange }) => {
// HANDLERS
// ------------------------------------
const handleStatusUpdate = (orderId, newStatus) => {
if (newStatus === 'complete') {
if (newStatus === 'complete' || newStatus === 'cancelled') {
syncOrders(orders.filter((o) => o.id !== orderId));
} else {
syncOrders(orders.map((o) => (o.id === orderId ? { ...o, status: newStatus } : o)));
Expand Down