fix(orders): polish responsive header, uniform button heights, and outside-click invoice dropdown
This commit is contained in:
parent
5ebac5126b
commit
3c179e62d7
1 changed files with 87 additions and 64 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useMemo, useState, type ReactNode } from 'react';
|
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||||
import {
|
import {
|
||||||
Plus,
|
Plus,
|
||||||
RefreshCw,
|
RefreshCw,
|
||||||
|
|
@ -192,6 +192,7 @@ export default function OrderIntelligencePage() {
|
||||||
const [changeReason, setChangeReason] = useState('');
|
const [changeReason, setChangeReason] = useState('');
|
||||||
const [updating, setUpdating] = useState(false);
|
const [updating, setUpdating] = useState(false);
|
||||||
const [showInvoiceMenu, setShowInvoiceMenu] = useState(false);
|
const [showInvoiceMenu, setShowInvoiceMenu] = useState(false);
|
||||||
|
const invoiceMenuRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const [showCreateOrderModal, setShowCreateOrderModal] = useState(false);
|
const [showCreateOrderModal, setShowCreateOrderModal] = useState(false);
|
||||||
const [buyerName, setBuyerName] = useState('');
|
const [buyerName, setBuyerName] = useState('');
|
||||||
|
|
@ -729,6 +730,17 @@ export default function OrderIntelligencePage() {
|
||||||
fetchCatalogProductsAndSkus();
|
fetchCatalogProductsAndSkus();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!showInvoiceMenu) return;
|
||||||
|
const handleOutsideClick = (e: MouseEvent) => {
|
||||||
|
if (invoiceMenuRef.current && !invoiceMenuRef.current.contains(e.target as Node)) {
|
||||||
|
setShowInvoiceMenu(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener('mousedown', handleOutsideClick);
|
||||||
|
return () => document.removeEventListener('mousedown', handleOutsideClick);
|
||||||
|
}, [showInvoiceMenu]);
|
||||||
|
|
||||||
const handleInspectOrder = async (id: string) => {
|
const handleInspectOrder = async (id: string) => {
|
||||||
setSelectedOrderId(id);
|
setSelectedOrderId(id);
|
||||||
setDetailLoading(true);
|
setDetailLoading(true);
|
||||||
|
|
@ -1081,11 +1093,19 @@ export default function OrderIntelligencePage() {
|
||||||
<div className="px-5 py-12 text-center text-[13px] text-muted-foreground">Failed to load order details.</div>
|
<div className="px-5 py-12 text-center text-[13px] text-muted-foreground">Failed to load order details.</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex min-h-0 flex-1 flex-col">
|
<div className="flex min-h-0 flex-1 flex-col">
|
||||||
<div className="flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-5">
|
<div className="flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4">
|
||||||
<div className="flex items-start justify-between gap-3">
|
{/* Header: Date, Badges & Action Toolbar */}
|
||||||
<div>
|
<div className="space-y-3 pb-3 border-b border-border">
|
||||||
<p className="text-[12px] text-muted-foreground">{formatOrderDate(detailData.created_at)}</p>
|
<div className="flex items-center justify-between gap-2 flex-wrap">
|
||||||
<div className="mt-2 flex flex-wrap items-center gap-2">
|
<span className="text-[12px] font-medium text-muted-foreground">{formatOrderDate(detailData.created_at)}</span>
|
||||||
|
{detailData.invoice_no && (
|
||||||
|
<span className="inline-flex items-center gap-1 px-2.5 py-0.5 rounded text-[11px] font-mono font-medium bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20">
|
||||||
|
📄 {detailData.invoice_no}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
{renderStatusBadge(detailData.status)}
|
{renderStatusBadge(detailData.status)}
|
||||||
<span
|
<span
|
||||||
className={`inline-flex items-center px-2.5 py-1 crm-radius-badge text-[11px] font-semibold ${
|
className={`inline-flex items-center px-2.5 py-1 crm-radius-badge text-[11px] font-semibold ${
|
||||||
|
|
@ -1101,52 +1121,47 @@ export default function OrderIntelligencePage() {
|
||||||
🏷️ Discounted Order
|
🏷️ Discounted Order
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{detailData.invoice_no && (
|
|
||||||
<span className="inline-flex items-center px-2.5 py-1 crm-radius-badge text-[11px] font-mono font-semibold bg-primary/10 text-primary border border-primary/20">
|
|
||||||
📄 {detailData.invoice_no}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!showStatusForm && (
|
{!showStatusForm && (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2 pt-1">
|
||||||
{/* Print Invoice with Dropdown */}
|
{/* Print Invoice with Dropdown */}
|
||||||
<div className="relative inline-flex items-center shadow-sm">
|
<div ref={invoiceMenuRef} className="relative inline-flex items-center">
|
||||||
|
<div className="inline-flex items-center h-8.5 rounded-lg overflow-hidden border border-emerald-600/40 shadow-sm">
|
||||||
<a
|
<a
|
||||||
href={`${API_BASE_URL}/api/v1/admin/orders/${detailData.order_id}/invoice?format=standard`}
|
href={`${API_BASE_URL}/api/v1/admin/orders/${detailData.order_id}/invoice?format=standard`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="inline-flex items-center gap-1.5 px-3 py-1.5 bg-emerald-600 hover:bg-emerald-700 text-white rounded-l crm-radius-button-l text-[12px] font-semibold transition-colors"
|
className="inline-flex items-center gap-1.5 h-full px-3 bg-emerald-600 hover:bg-emerald-700 text-white text-[12px] font-semibold whitespace-nowrap transition-colors"
|
||||||
title="Print Standard GST Tax Invoice (Letter / A4)"
|
title="Print Standard GST Tax Invoice (Letter / A4)"
|
||||||
>
|
>
|
||||||
<FileText className="w-3.5 h-3.5" />
|
<FileText className="w-3.5 h-3.5 shrink-0" />
|
||||||
Print Invoice
|
<span>Print Invoice</span>
|
||||||
</a>
|
</a>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setShowInvoiceMenu((prev) => !prev)}
|
onClick={() => setShowInvoiceMenu((prev) => !prev)}
|
||||||
className="px-1.5 py-1.5 bg-emerald-700 hover:bg-emerald-800 text-white rounded-r border-l border-emerald-500/40 text-[12px] transition-colors"
|
className="inline-flex items-center justify-center h-full px-2 bg-emerald-700 hover:bg-emerald-800 text-white border-l border-emerald-500/40 text-[12px] transition-colors"
|
||||||
title="Choose Invoice Format"
|
title="Choose Invoice Format"
|
||||||
|
aria-expanded={showInvoiceMenu}
|
||||||
>
|
>
|
||||||
<ChevronDown className="w-3.5 h-3.5" />
|
<ChevronDown className={`w-3.5 h-3.5 transition-transform duration-150 ${showInvoiceMenu ? 'rotate-180' : ''}`} />
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
{showInvoiceMenu && (
|
{showInvoiceMenu && (
|
||||||
<div
|
<div className="absolute left-0 top-full mt-1.5 w-60 bg-card border border-border rounded-lg shadow-2xl p-1 z-50 text-[12px]">
|
||||||
className="absolute right-0 top-full mt-1 w-52 bg-popover border border-border rounded-md shadow-xl py-1 z-50 text-[12px]"
|
|
||||||
onMouseLeave={() => setShowInvoiceMenu(false)}
|
|
||||||
>
|
|
||||||
<a
|
<a
|
||||||
href={`${API_BASE_URL}/api/v1/admin/orders/${detailData.order_id}/invoice?format=standard`}
|
href={`${API_BASE_URL}/api/v1/admin/orders/${detailData.order_id}/invoice?format=standard`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
onClick={() => setShowInvoiceMenu(false)}
|
onClick={() => setShowInvoiceMenu(false)}
|
||||||
className="flex items-center gap-2 px-3 py-2 text-foreground hover:bg-muted transition-colors"
|
className="flex items-center gap-2.5 px-3 py-2 text-foreground hover:bg-muted rounded-md transition-colors"
|
||||||
>
|
>
|
||||||
<FileText className="w-4 h-4 text-emerald-600" />
|
<FileText className="w-4 h-4 text-emerald-600 shrink-0" />
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<div className="font-medium">Standard GST Invoice</div>
|
<div className="font-semibold text-foreground whitespace-nowrap">Standard GST Invoice</div>
|
||||||
<div className="text-[10px] text-muted-foreground">Letter / A4 PDF document</div>
|
<div className="text-[11px] text-muted-foreground whitespace-nowrap">Letter / A4 PDF document</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
|
|
@ -1154,30 +1169,38 @@ export default function OrderIntelligencePage() {
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
onClick={() => setShowInvoiceMenu(false)}
|
onClick={() => setShowInvoiceMenu(false)}
|
||||||
className="flex items-center gap-2 px-3 py-2 text-foreground hover:bg-muted transition-colors border-t border-border/50"
|
className="flex items-center gap-2.5 px-3 py-2 text-foreground hover:bg-muted rounded-md transition-colors border-t border-border/50"
|
||||||
>
|
>
|
||||||
<Printer className="w-4 h-4 text-amber-500" />
|
<Printer className="w-4 h-4 text-amber-500 shrink-0" />
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<div className="font-medium">Thermal Receipt</div>
|
<div className="font-semibold text-foreground whitespace-nowrap">Thermal Receipt</div>
|
||||||
<div className="text-[10px] text-muted-foreground">80mm POS receipt roll</div>
|
<div className="text-[11px] text-muted-foreground whitespace-nowrap">80mm POS receipt roll</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Print Shipping Slip */}
|
||||||
{detailData.shipping_label_url && (
|
{detailData.shipping_label_url && (
|
||||||
<a
|
<a
|
||||||
href={detailData.shipping_label_url.startsWith('http') ? detailData.shipping_label_url : `${API_BASE_URL}${detailData.shipping_label_url}`}
|
href={detailData.shipping_label_url.startsWith('http') ? detailData.shipping_label_url : `${API_BASE_URL}${detailData.shipping_label_url}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="inline-flex items-center gap-1.5 px-3 py-1.5 bg-primary text-white crm-radius-button text-[12px] font-semibold hover:opacity-90 shadow-sm transition-colors"
|
className="inline-flex items-center gap-1.5 h-8.5 px-3 bg-primary hover:bg-primary/90 text-white rounded-lg text-[12px] font-semibold whitespace-nowrap shadow-sm transition-colors"
|
||||||
|
title="Print Carrier Shipping Label"
|
||||||
>
|
>
|
||||||
<Printer className="w-3.5 h-3.5" />
|
<Printer className="w-3.5 h-3.5 shrink-0" />
|
||||||
Print Shipping Slip
|
<span>Print Shipping Slip</span>
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
<button type="button" onClick={handleOpenStatusForm} className={primaryButton}>
|
|
||||||
|
{/* Update Status Button */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleOpenStatusForm}
|
||||||
|
className="inline-flex items-center justify-center gap-1.5 h-8.5 px-3.5 bg-card hover:bg-muted text-foreground border border-border rounded-lg text-[12px] font-semibold whitespace-nowrap shadow-sm transition-colors cursor-pointer"
|
||||||
|
>
|
||||||
Update status
|
Update status
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue