Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8297a2dd9d |
@@ -1,8 +1,6 @@
|
|||||||
import type { OrderStatus } from "@orderops/shared/order-status";
|
import type { OrderStatus } from "@orderops/shared/order-status";
|
||||||
|
|
||||||
export function canEditOrderItems(status: OrderStatus) {
|
export { canEditOrderItems } from "@orderops/shared/order-status";
|
||||||
return status === "pending";
|
|
||||||
}
|
|
||||||
|
|
||||||
export function canEditShippingAddress(status: OrderStatus) {
|
export function canEditShippingAddress(status: OrderStatus) {
|
||||||
return status === "pending" || status === "processing";
|
return status === "pending" || status === "processing";
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import type { OrderDetail } from "@orderops/shared";
|
import type { OrderDetail } from "@orderops/shared";
|
||||||
|
import { canEditOrderItems } from "@orderops/shared/order-status";
|
||||||
|
|
||||||
interface OrderItemsPanelProps {
|
interface OrderItemsPanelProps {
|
||||||
order: OrderDetail;
|
order: OrderDetail;
|
||||||
@@ -39,9 +40,14 @@ function QuantityForm({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function OrderItemsPanel({ order, onUpdateQuantity }: OrderItemsPanelProps) {
|
export function OrderItemsPanel({ order, onUpdateQuantity }: OrderItemsPanelProps) {
|
||||||
|
const canEditQuantity = canEditOrderItems(order.status);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
|
<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>
|
<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">
|
<div className="space-y-3">
|
||||||
{order.items.map((item) => (
|
{order.items.map((item) => (
|
||||||
<div key={item.id} className="rounded-lg border border-slate-200 p-3">
|
<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-600">{item.sku}</div>
|
||||||
<div className="text-sm text-slate-500">Available: {item.availableQuantity}</div>
|
<div className="text-sm text-slate-500">Available: {item.availableQuantity}</div>
|
||||||
</div>
|
</div>
|
||||||
|
{canEditQuantity ? (
|
||||||
<QuantityForm itemId={item.id} quantity={item.quantity} onSave={onUpdateQuantity} />
|
<QuantityForm itemId={item.id} quantity={item.quantity} onSave={onUpdateQuantity} />
|
||||||
|
) : (
|
||||||
|
<div className="text-sm text-slate-700">Quantity: {item.quantity}</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -72,19 +72,6 @@ export function OrderPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleUpdateQuantity(itemId: string, quantity: number) {
|
|
||||||
if (!order) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (order.status !== "pending") {
|
|
||||||
setToast({ message: "Order items cannot be changed for this order status.", variant: "error" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await runAction(() => updateOrderItemQuantity(order.id, itemId, quantity), "Quantity saved.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<Link className="inline-flex text-sm font-medium text-blue-600 hover:text-blue-700" to="/orders">
|
<Link className="inline-flex text-sm font-medium text-blue-600 hover:text-blue-700" to="/orders">
|
||||||
@@ -97,7 +84,7 @@ export function OrderPage() {
|
|||||||
<OrderDetailPage
|
<OrderDetailPage
|
||||||
order={order}
|
order={order}
|
||||||
auditEvents={auditEvents}
|
auditEvents={auditEvents}
|
||||||
onUpdateQuantity={handleUpdateQuantity}
|
onUpdateQuantity={(itemId, quantity) => runAction(() => updateOrderItemQuantity(order.id, itemId, quantity), "Quantity saved.")}
|
||||||
onSaveAddress={(address: Address) => runAction(() => updateShippingAddress(order.id, address), "Shipping address saved.")}
|
onSaveAddress={(address: Address) => runAction(() => updateShippingAddress(order.id, address), "Shipping address saved.")}
|
||||||
onSaveNotes={(notes) => runAction(() => updateOrderNotes(order.id, notes), "Notes saved.")}
|
onSaveNotes={(notes) => runAction(() => updateOrderNotes(order.id, notes), "Notes saved.")}
|
||||||
onCancel={() => runAction(() => cancelOrder(order.id), "Order cancelled.")}
|
onCancel={() => runAction(() => cancelOrder(order.id), "Order cancelled.")}
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
export const orderStatuses = ["pending", "processing", "shipped", "cancelled", "refunded"] as const;
|
export const orderStatuses = ["pending", "processing", "shipped", "cancelled", "refunded"] as const;
|
||||||
|
|
||||||
export type OrderStatus = (typeof orderStatuses)[number];
|
export type OrderStatus = (typeof orderStatuses)[number];
|
||||||
|
|
||||||
|
export function canEditOrderItems(status: OrderStatus) {
|
||||||
|
return status === "pending";
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user