fix(orders): polish responsive header, uniform button heights, and outside-click invoice dropdown

This commit is contained in:
iFixKart Dev 2026-11-18 18:38:03 +05:30
parent 5ebac5126b
commit 3c179e62d7

View file

@ -1,6 +1,6 @@
'use client';
import { useEffect, useMemo, useState, type ReactNode } from 'react';
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
import {
Plus,
RefreshCw,
@ -192,6 +192,7 @@ export default function OrderIntelligencePage() {
const [changeReason, setChangeReason] = useState('');
const [updating, setUpdating] = useState(false);
const [showInvoiceMenu, setShowInvoiceMenu] = useState(false);
const invoiceMenuRef = useRef<HTMLDivElement>(null);
const [showCreateOrderModal, setShowCreateOrderModal] = useState(false);
const [buyerName, setBuyerName] = useState('');
@ -729,6 +730,17 @@ export default function OrderIntelligencePage() {
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) => {
setSelectedOrderId(id);
setDetailLoading(true);
@ -1081,72 +1093,75 @@ 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="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 items-start justify-between gap-3">
<div>
<p className="text-[12px] text-muted-foreground">{formatOrderDate(detailData.created_at)}</p>
<div className="mt-2 flex flex-wrap items-center gap-2">
{renderStatusBadge(detailData.status)}
<span
className={`inline-flex items-center px-2.5 py-1 crm-radius-badge text-[11px] font-semibold ${
detailData.payment_status === 'PAID' || detailData.payment_status === 'PAYMENT_CAPTURED'
? 'bg-success text-white'
: 'bg-warning text-white'
}`}
>
{(detailData.payment_status || 'UNPAID').replace('_', ' ')}
<div className="flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4">
{/* Header: Date, Badges & Action Toolbar */}
<div className="space-y-3 pb-3 border-b border-border">
<div className="flex items-center justify-between gap-2 flex-wrap">
<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>
{detailData.is_discounted && (
<span className="inline-flex items-center px-2.5 py-1 crm-radius-badge text-[11px] font-semibold bg-emerald-500/10 text-emerald-700 border border-emerald-500/25">
🏷️ Discounted Order
</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 className="flex flex-wrap items-center gap-2">
{renderStatusBadge(detailData.status)}
<span
className={`inline-flex items-center px-2.5 py-1 crm-radius-badge text-[11px] font-semibold ${
detailData.payment_status === 'PAID' || detailData.payment_status === 'PAYMENT_CAPTURED'
? 'bg-success text-white'
: 'bg-warning text-white'
}`}
>
{(detailData.payment_status || 'UNPAID').replace('_', ' ')}
</span>
{detailData.is_discounted && (
<span className="inline-flex items-center px-2.5 py-1 crm-radius-badge text-[11px] font-semibold bg-emerald-500/10 text-emerald-700 border border-emerald-500/25">
🏷️ Discounted Order
</span>
)}
</div>
{!showStatusForm && (
<div className="flex items-center gap-2">
<div className="flex flex-wrap items-center gap-2 pt-1">
{/* Print Invoice with Dropdown */}
<div className="relative inline-flex items-center shadow-sm">
<a
href={`${API_BASE_URL}/api/v1/admin/orders/${detailData.order_id}/invoice?format=standard`}
target="_blank"
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"
title="Print Standard GST Tax Invoice (Letter / A4)"
>
<FileText className="w-3.5 h-3.5" />
Print Invoice
</a>
<button
type="button"
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"
title="Choose Invoice Format"
>
<ChevronDown className="w-3.5 h-3.5" />
</button>
<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
href={`${API_BASE_URL}/api/v1/admin/orders/${detailData.order_id}/invoice?format=standard`}
target="_blank"
rel="noopener noreferrer"
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)"
>
<FileText className="w-3.5 h-3.5 shrink-0" />
<span>Print Invoice</span>
</a>
<button
type="button"
onClick={() => setShowInvoiceMenu((prev) => !prev)}
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"
aria-expanded={showInvoiceMenu}
>
<ChevronDown className={`w-3.5 h-3.5 transition-transform duration-150 ${showInvoiceMenu ? 'rotate-180' : ''}`} />
</button>
</div>
{showInvoiceMenu && (
<div
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)}
>
<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]">
<a
href={`${API_BASE_URL}/api/v1/admin/orders/${detailData.order_id}/invoice?format=standard`}
target="_blank"
rel="noopener noreferrer"
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" />
<div>
<div className="font-medium">Standard GST Invoice</div>
<div className="text-[10px] text-muted-foreground">Letter / A4 PDF document</div>
<FileText className="w-4 h-4 text-emerald-600 shrink-0" />
<div className="min-w-0">
<div className="font-semibold text-foreground whitespace-nowrap">Standard GST Invoice</div>
<div className="text-[11px] text-muted-foreground whitespace-nowrap">Letter / A4 PDF document</div>
</div>
</a>
<a
@ -1154,30 +1169,38 @@ export default function OrderIntelligencePage() {
target="_blank"
rel="noopener noreferrer"
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" />
<div>
<div className="font-medium">Thermal Receipt</div>
<div className="text-[10px] text-muted-foreground">80mm POS receipt roll</div>
<Printer className="w-4 h-4 text-amber-500 shrink-0" />
<div className="min-w-0">
<div className="font-semibold text-foreground whitespace-nowrap">Thermal Receipt</div>
<div className="text-[11px] text-muted-foreground whitespace-nowrap">80mm POS receipt roll</div>
</div>
</a>
</div>
)}
</div>
{/* Print Shipping Slip */}
{detailData.shipping_label_url && (
<a
href={detailData.shipping_label_url.startsWith('http') ? detailData.shipping_label_url : `${API_BASE_URL}${detailData.shipping_label_url}`}
target="_blank"
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" />
Print Shipping Slip
<Printer className="w-3.5 h-3.5 shrink-0" />
<span>Print Shipping Slip</span>
</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
</button>
</div>