assignment 2 ui changes
This commit is contained in:
@@ -28,6 +28,13 @@ export function updateShippingAddress(orderId: string, address: Address) {
|
||||
});
|
||||
}
|
||||
|
||||
export function updateOrderNotes(orderId: string, notes: string) {
|
||||
return apiRequest<OrderDetail>(`/api/orders/${orderId}/notes`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ notes })
|
||||
});
|
||||
}
|
||||
|
||||
export function cancelOrder(orderId: string, reason?: string) {
|
||||
return apiRequest<OrderDetail>(`/api/orders/${orderId}/cancel`, {
|
||||
method: "POST",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Address, AuditEvent, OrderDetail } from "@orderops/shared";
|
||||
import { AuditTimeline } from "./audit-timeline";
|
||||
import { OrderItemsPanel } from "./order-items-panel";
|
||||
import { OrderNotesPanel } from "./order-notes";
|
||||
import { OrderSummaryPanel } from "./order-summary";
|
||||
import { ShippingAddressForm } from "./shipping-address-form";
|
||||
|
||||
@@ -9,6 +10,7 @@ interface OrderDetailPageProps {
|
||||
auditEvents: AuditEvent[];
|
||||
onUpdateQuantity: (itemId: string, quantity: number) => Promise<void>;
|
||||
onSaveAddress: (address: Address) => Promise<void>;
|
||||
onSaveNotes: (notes: string) => Promise<void>;
|
||||
onCancel: () => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -17,11 +19,13 @@ export function OrderDetailPage({
|
||||
auditEvents,
|
||||
onUpdateQuantity,
|
||||
onSaveAddress,
|
||||
onSaveNotes,
|
||||
onCancel
|
||||
}: OrderDetailPageProps) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<OrderSummaryPanel order={order} />
|
||||
<OrderNotesPanel notes={order.notes} onSave={onSaveNotes} />
|
||||
<div className="flex justify-end">
|
||||
<button className="rounded-md bg-red-600 px-4 py-2 text-sm font-medium text-white" onClick={() => void onCancel()} type="button">
|
||||
Cancel order
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { useState } from "react";
|
||||
|
||||
export const NOTES_MAX_LENGTH = 1000;
|
||||
|
||||
interface OrderNotesProps {
|
||||
notes: string;
|
||||
onSave: (notes: string) => Promise<void>;
|
||||
}
|
||||
|
||||
export function OrderNotesPanel({ notes, onSave }: OrderNotesProps) {
|
||||
const [draft, setDraft] = useState(notes);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const trimmed = draft.trim();
|
||||
const isDisabled = isSaving || trimmed.length === 0 || trimmed === notes;
|
||||
|
||||
async function handleSave() {
|
||||
if (isDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSaving(true);
|
||||
try {
|
||||
await onSave(trimmed);
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold text-slate-700">Internal notes</h3>
|
||||
<span className="text-xs text-slate-500">{draft.length}/{NOTES_MAX_LENGTH}</span>
|
||||
</div>
|
||||
{notes ? (
|
||||
<p className="mb-3 whitespace-pre-wrap text-sm text-slate-700">{notes}</p>
|
||||
) : (
|
||||
<p className="mb-3 text-sm text-slate-400">No internal notes yet. Add context for teammates following up on this order.</p>
|
||||
)}
|
||||
<textarea
|
||||
className="w-full resize-y rounded-lg border border-slate-300 px-3 py-2 text-sm text-slate-900 focus:border-blue-500 focus:outline-none"
|
||||
maxLength={NOTES_MAX_LENGTH}
|
||||
onChange={(event) => setDraft(event.target.value)}
|
||||
placeholder="Add internal notes..."
|
||||
rows={3}
|
||||
value={draft}
|
||||
/>
|
||||
<div className="mt-3 flex justify-end">
|
||||
<button
|
||||
className="rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white disabled:cursor-not-allowed disabled:opacity-50"
|
||||
disabled={isDisabled}
|
||||
onClick={() => void handleSave()}
|
||||
type="button"
|
||||
>
|
||||
{isSaving ? "Saving..." : "Save notes"}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
|
||||
import type { Address, AuditEvent, OrderDetail } from "@orderops/shared";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
import { Toast } from "../ui/toast";
|
||||
import { cancelOrder, getOrder, listAuditEvents, updateOrderItemQuantity, updateShippingAddress } from "./order-api";
|
||||
import { cancelOrder, getOrder, listAuditEvents, updateOrderItemQuantity, updateOrderNotes, updateShippingAddress } from "./order-api";
|
||||
import { OrderDetailPage } from "./order-detail-page";
|
||||
|
||||
interface ToastState {
|
||||
@@ -86,6 +86,7 @@ export function OrderPage() {
|
||||
auditEvents={auditEvents}
|
||||
onUpdateQuantity={(itemId, quantity) => runAction(() => updateOrderItemQuantity(order.id, itemId, quantity), "Quantity saved.")}
|
||||
onSaveAddress={(address: Address) => runAction(() => updateShippingAddress(order.id, address), "Shipping address saved.")}
|
||||
onSaveNotes={(notes: string) => runAction(() => updateOrderNotes(order.id, notes), "Notes saved.")}
|
||||
onCancel={() => runAction(() => cancelOrder(order.id), "Order cancelled.")}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user