diff --git a/src/components/dashboard/dashboard-hero.tsx b/src/components/dashboard/dashboard-hero.tsx index 3023381..d2971c2 100644 --- a/src/components/dashboard/dashboard-hero.tsx +++ b/src/components/dashboard/dashboard-hero.tsx @@ -12,7 +12,7 @@ import { api } from "@/convex/_generated/api" import type { Id } from "@/convex/_generated/dataModel" import { useAuth } from "@/lib/auth-client" import { DEFAULT_TENANT_ID } from "@/lib/constants" -import { cn, formatDateDM, formatDateDMY } from "@/lib/utils" +import { cn, formatDateDM, formatDateDMY, formatMinutesHuman } from "@/lib/utils" import { Badge } from "@/components/ui/badge" import { Card, @@ -205,7 +205,7 @@ export function DashboardHero() { {overview?.firstResponse ? ( overview.firstResponse.averageMinutes !== null ? ( - `${overview.firstResponse.averageMinutes.toFixed(1)} min` + formatMinutesHuman(overview.firstResponse.averageMinutes) ) : ( "—" ) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 25f470f..3c6447a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -17,6 +17,20 @@ export function formatHoursCompact(value: number, locale: string = "pt-BR"): str return `${nf.format(hours)} h` } +// Format minutes to h/m when reaching the 1h mark; below that keep 1 decimal minute precision. +// Examples: 45.3 -> "45,3 min"; 60 -> "1h"; 185 -> "3h5m" +export function formatMinutesHuman(value: number, locale: string = "pt-BR"): string { + const minutes = Number.isFinite(value) ? Math.max(value, 0) : 0 + if (minutes < 60) { + const nf = new Intl.NumberFormat(locale, { minimumFractionDigits: 1, maximumFractionDigits: 1 }) + return `${nf.format(minutes)} min` + } + const rounded = Math.round(minutes) + const hours = Math.floor(rounded / 60) + const remainingMinutes = rounded % 60 + return remainingMinutes === 0 ? `${hours}h` : `${hours}h${remainingMinutes}m` +} + // Format date to dd/MM or dd/MM/yyyy. Accepts Date or ISO-like string (YYYY-MM-DD). export function formatDateDM(value: Date | string | number): string { const d = typeof value === "string" || typeof value === "number" ? new Date(value) : value