diff --git a/apps/edr-freight-web/portal/src/pages/MyPortalPage/MyPortalPage.tsx b/apps/edr-freight-web/portal/src/pages/MyPortalPage/MyPortalPage.tsx index fccc4d98f..c9e073eb5 100644 --- a/apps/edr-freight-web/portal/src/pages/MyPortalPage/MyPortalPage.tsx +++ b/apps/edr-freight-web/portal/src/pages/MyPortalPage/MyPortalPage.tsx @@ -34,7 +34,6 @@ export default function MyPortalPage() { totalOutstanding, companyName, greeting, - recentInvoices, dashboard, volumePoints, maxVolume, @@ -120,7 +119,7 @@ export default function MyPortalPage() { - + diff --git a/apps/edr-freight-web/portal/src/pages/MyPortalPage/components/InvoicesSection.tsx b/apps/edr-freight-web/portal/src/pages/MyPortalPage/components/InvoicesSection.tsx index 22362c816..8d350b93f 100644 --- a/apps/edr-freight-web/portal/src/pages/MyPortalPage/components/InvoicesSection.tsx +++ b/apps/edr-freight-web/portal/src/pages/MyPortalPage/components/InvoicesSection.tsx @@ -2,7 +2,7 @@ import { formatCurrency } from "@/lib/currency"; import type { PortalInvoice } from "@/services/invoices.service"; import { Box, Group, Stack, Text } from "@mantine/core"; import { Freight } from "@edr/types"; -import { CheckCircle2, ChevronRight, Clock3, Zap } from "lucide-react"; +import { ChevronRight, Clock3 } from "lucide-react"; import { memo } from "react"; import { Link } from "react-router-dom"; import { cv, INVOICE_BADGE } from "../constants"; @@ -13,18 +13,22 @@ interface InvoicesSectionProps { invoices: PortalInvoice[]; } +/** Max rows to list in the compact dashboard card. */ +const MAX_ROWS = 5; + const titleCase = (v: string) => v ? v.charAt(0).toUpperCase() + v.slice(1).toLowerCase() : ""; export const InvoicesSection = memo(function InvoicesSection({ invoices, }: InvoicesSectionProps) { - const outstandingInvoices = invoices.filter( + // Dashboard shows unpaid invoices only (pending + overdue). + const pendingInvoices = invoices.filter( (inv) => inv.status === Freight.InvoiceStatus.Pending || inv.status === Freight.InvoiceStatus.Overdue, ); - const totalOutstanding = outstandingInvoices.reduce( + const totalOutstanding = pendingInvoices.reduce( (sum, inv) => sum + Number(inv.totalAmount), 0, ); @@ -52,83 +56,74 @@ export const InvoicesSection = memo(function InvoicesSection({ {formatCurrency(totalOutstanding || 0, "ETB")} - - - {outstandingInvoices.length} invoices unpaid - - - - - Pay all - - - + + {pendingInvoices.length} invoices unpaid + - {invoices.length === 0 ? ( - + {pendingInvoices.length === 0 ? ( + ) : ( - {invoices.map((invoice, i) => { + {pendingInvoices.slice(0, MAX_ROWS).map((invoice, i) => { const badge = INVOICE_BADGE[invoice.status]; - const isPaid = invoice.status === Freight.InvoiceStatus.Paid; const isOverdue = invoice.status === Freight.InvoiceStatus.Overdue; - const dueText = isPaid - ? "Paid" - : isOverdue - ? "Overdue" - : `Due ${new Date(invoice.dueAt).toLocaleDateString()}`; - const DueIcon = isPaid ? CheckCircle2 : Clock3; - const dueIconColor = isPaid ? cv("edr-green.5") : cv("edr-muted"); + const dueText = isOverdue + ? "Overdue" + : `Due ${new Date(invoice.dueAt).toLocaleDateString()}`; + const dueIconColor = isOverdue ? cv("edr-red") : cv("edr-muted"); return ( {i > 0 && } - - - - - {invoice.invoiceNumber} - - - {titleCase(invoice.source)} · {titleCase(invoice.type)} - - - - {formatCurrency( - Number(invoice.totalAmount), - invoice.currency, - )} - - - - - - - {dueText} - - - {badge && ( - - - {badge.label} + + + + + + {invoice.invoiceNumber} + + + {titleCase(invoice.source)} · {titleCase(invoice.type)} - )} - - + + {formatCurrency( + Number(invoice.totalAmount), + invoice.currency, + )} + + + + + + + {dueText} + + + {badge && ( + + + {badge.label} + + + )} + + + ); })}