Restrict order quantity edits to pending orders
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import type { OrderStatus } from "@orderops/shared/order-status";
|
||||
|
||||
export function canEditOrderItems(status: OrderStatus) {
|
||||
return status === "pending" || status === "processing";
|
||||
}
|
||||
export { canEditOrderItems } from "@orderops/shared/order-status";
|
||||
|
||||
export function canEditShippingAddress(status: OrderStatus) {
|
||||
return status === "pending" || status === "processing";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState } from "react";
|
||||
import type { OrderDetail } from "@orderops/shared";
|
||||
import { canEditOrderItems } from "@orderops/shared/order-status";
|
||||
|
||||
interface OrderItemsPanelProps {
|
||||
order: OrderDetail;
|
||||
@@ -39,9 +40,14 @@ function QuantityForm({
|
||||
}
|
||||
|
||||
export function OrderItemsPanel({ order, onUpdateQuantity }: OrderItemsPanelProps) {
|
||||
const canEditQuantity = canEditOrderItems(order.status);
|
||||
|
||||
return (
|
||||
<section className="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
|
||||
<h3 className="mb-3 text-sm font-semibold text-slate-700">Items</h3>
|
||||
{!canEditQuantity ? (
|
||||
<p className="mb-3 text-sm text-slate-600">Item quantities can only be changed while an order is pending.</p>
|
||||
) : null}
|
||||
<div className="space-y-3">
|
||||
{order.items.map((item) => (
|
||||
<div key={item.id} className="rounded-lg border border-slate-200 p-3">
|
||||
@@ -51,7 +57,11 @@ export function OrderItemsPanel({ order, onUpdateQuantity }: OrderItemsPanelProp
|
||||
<div className="text-sm text-slate-600">{item.sku}</div>
|
||||
<div className="text-sm text-slate-500">Available: {item.availableQuantity}</div>
|
||||
</div>
|
||||
<QuantityForm itemId={item.id} quantity={item.quantity} onSave={onUpdateQuantity} />
|
||||
{canEditQuantity ? (
|
||||
<QuantityForm itemId={item.id} quantity={item.quantity} onSave={onUpdateQuantity} />
|
||||
) : (
|
||||
<div className="text-sm text-slate-700">Quantity: {item.quantity}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user