Update page.tsx
This commit is contained in:
@@ -564,6 +564,57 @@ export default function OrderDetailsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const copyAllOrderData = async () => {
|
||||
if (!order) return;
|
||||
|
||||
try {
|
||||
const lines = [];
|
||||
|
||||
// Order number
|
||||
lines.push(`Order Number: ${order.orderId}`);
|
||||
lines.push('');
|
||||
|
||||
// Order details
|
||||
lines.push('Order Details:');
|
||||
if (order.products && order.products.length > 0) {
|
||||
order.products.forEach((product) => {
|
||||
const productName = productNames[product.productId] || 'Unknown Product';
|
||||
lines.push(` - ${productName} (Qty: ${product.quantity} @ £${product.pricePerUnit.toFixed(2)} = £${product.totalItemPrice.toFixed(2)})`);
|
||||
});
|
||||
}
|
||||
|
||||
// Shipping
|
||||
if (order.shippingMethod) {
|
||||
lines.push(` - Shipping: ${order.shippingMethod.type} (£${order.shippingMethod.price.toFixed(2)})`);
|
||||
}
|
||||
|
||||
// Discount
|
||||
if (order.discountAmount && order.discountAmount > 0) {
|
||||
lines.push(` - Discount: -£${order.discountAmount.toFixed(2)}${order.promotionCode ? ` (Promo: ${order.promotionCode})` : ''}`);
|
||||
}
|
||||
|
||||
// Subtotal if different from total
|
||||
if (order.subtotalBeforeDiscount && order.subtotalBeforeDiscount !== order.totalPrice) {
|
||||
lines.push(` - Subtotal: £${order.subtotalBeforeDiscount.toFixed(2)}`);
|
||||
}
|
||||
|
||||
// Total
|
||||
lines.push(` - Total: £${order.totalPrice.toFixed(2)}`);
|
||||
lines.push('');
|
||||
|
||||
// Address
|
||||
lines.push('Address:');
|
||||
lines.push(order.pgpAddress || 'N/A');
|
||||
|
||||
const textToCopy = lines.join('\n');
|
||||
await navigator.clipboard.writeText(textToCopy);
|
||||
toast.success("Order data copied to clipboard!");
|
||||
} catch (error) {
|
||||
toast.error("Failed to copy order data");
|
||||
console.error("Copy error:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function to check if order is underpaid
|
||||
const isOrderUnderpaid = (order: Order | null) => {
|
||||
// More robust check - only show underpaid if status is NOT paid and underpayment exists
|
||||
@@ -647,6 +698,15 @@ export default function OrderDetailsPage() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={copyAllOrderData}
|
||||
disabled={!order}
|
||||
>
|
||||
<Clipboard className="h-4 w-4 mr-1" />
|
||||
Copy All
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
|
||||
Reference in New Issue
Block a user