mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-07-08 19:06:00 +00:00
feat: agrupar lançamentos por data
This commit is contained in:
1
drizzle/0033_demonic_supreme_intelligence.sql
Normal file
1
drizzle/0033_demonic_supreme_intelligence.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE "preferencias_usuario" ADD COLUMN "agrupar_lancamentos_por_data" boolean DEFAULT true NOT NULL;
|
||||
3002
drizzle/meta/0033_snapshot.json
Normal file
3002
drizzle/meta/0033_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -225,6 +225,13 @@
|
||||
"when": 1782569103402,
|
||||
"tag": "0032_bumpy_spencer_smythe",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 33,
|
||||
"version": "7",
|
||||
"when": 1782685465530,
|
||||
"tag": "0033_demonic_supreme_intelligence",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -235,6 +235,9 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
)}
|
||||
noteAsColumn={userPreferences?.statementNoteAsColumn ?? false}
|
||||
columnOrder={userPreferences?.transactionsColumnOrder ?? null}
|
||||
groupTransactionsByDate={
|
||||
userPreferences?.groupTransactionsByDate ?? true
|
||||
}
|
||||
attachmentMaxSizeMb={userPreferences?.attachmentMaxSizeMb ?? 50}
|
||||
/>
|
||||
</section>
|
||||
|
||||
@@ -212,6 +212,9 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
allowCreate
|
||||
noteAsColumn={userPreferences?.statementNoteAsColumn ?? false}
|
||||
columnOrder={userPreferences?.transactionsColumnOrder ?? null}
|
||||
groupTransactionsByDate={
|
||||
userPreferences?.groupTransactionsByDate ?? true
|
||||
}
|
||||
attachmentMaxSizeMb={userPreferences?.attachmentMaxSizeMb ?? 50}
|
||||
defaultCardId={card.id}
|
||||
defaultPaymentMethod="Cartão de crédito"
|
||||
|
||||
@@ -105,6 +105,9 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
allowCreate={true}
|
||||
noteAsColumn={userPreferences?.statementNoteAsColumn ?? false}
|
||||
columnOrder={userPreferences?.transactionsColumnOrder ?? null}
|
||||
groupTransactionsByDate={
|
||||
userPreferences?.groupTransactionsByDate ?? true
|
||||
}
|
||||
attachmentMaxSizeMb={userPreferences?.attachmentMaxSizeMb ?? 50}
|
||||
/>
|
||||
</main>
|
||||
|
||||
@@ -408,6 +408,9 @@ export default async function Page({ params, searchParams }: PageProps) {
|
||||
allowCreate={canEdit}
|
||||
noteAsColumn={userPreferences?.statementNoteAsColumn ?? false}
|
||||
columnOrder={userPreferences?.transactionsColumnOrder ?? null}
|
||||
groupTransactionsByDate={
|
||||
userPreferences?.groupTransactionsByDate ?? true
|
||||
}
|
||||
attachmentMaxSizeMb={userPreferences?.attachmentMaxSizeMb ?? 50}
|
||||
importPayerOptions={loggedUserOptionSets?.payerOptions}
|
||||
importSplitPayerOptions={
|
||||
|
||||
@@ -85,6 +85,9 @@ export default async function Page() {
|
||||
showTransactionSummary={
|
||||
userPreferences?.showTransactionSummary ?? true
|
||||
}
|
||||
groupTransactionsByDate={
|
||||
userPreferences?.groupTransactionsByDate ?? true
|
||||
}
|
||||
hideAnticipatedInstallments={
|
||||
userPreferences?.hideAnticipatedInstallments ?? false
|
||||
}
|
||||
|
||||
@@ -114,6 +114,9 @@ export default async function Page({ searchParams }: PageProps) {
|
||||
}}
|
||||
noteAsColumn={userPreferences?.statementNoteAsColumn ?? false}
|
||||
columnOrder={userPreferences?.transactionsColumnOrder ?? null}
|
||||
groupTransactionsByDate={
|
||||
userPreferences?.groupTransactionsByDate ?? true
|
||||
}
|
||||
attachmentMaxSizeMb={userPreferences?.attachmentMaxSizeMb ?? 50}
|
||||
/>
|
||||
</LogoPrefetchProvider>
|
||||
|
||||
@@ -157,6 +157,9 @@ export const userPreferences = pgTable("preferencias_usuario", {
|
||||
showTransactionSummary: boolean("mostrar_resumo_lancamento")
|
||||
.notNull()
|
||||
.default(true),
|
||||
groupTransactionsByDate: boolean("agrupar_lancamentos_por_data")
|
||||
.notNull()
|
||||
.default(true),
|
||||
hideAnticipatedInstallments: boolean("ocultar_parcelas_antecipadas")
|
||||
.notNull()
|
||||
.default(false),
|
||||
|
||||
@@ -69,6 +69,7 @@ const updatePreferencesSchema = z.object({
|
||||
transactionsColumnOrder: z.array(z.string()).nullable(),
|
||||
attachmentMaxSizeMb: z.number().int().min(1).max(100),
|
||||
showTransactionSummary: z.boolean(),
|
||||
groupTransactionsByDate: z.boolean(),
|
||||
hideAnticipatedInstallments: z.boolean(),
|
||||
});
|
||||
|
||||
@@ -585,6 +586,7 @@ export async function updatePreferencesAction(
|
||||
transactionsColumnOrder: validated.transactionsColumnOrder,
|
||||
attachmentMaxSizeMb: validated.attachmentMaxSizeMb,
|
||||
showTransactionSummary: validated.showTransactionSummary,
|
||||
groupTransactionsByDate: validated.groupTransactionsByDate,
|
||||
hideAnticipatedInstallments: validated.hideAnticipatedInstallments,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
@@ -597,6 +599,7 @@ export async function updatePreferencesAction(
|
||||
transactionsColumnOrder: validated.transactionsColumnOrder,
|
||||
attachmentMaxSizeMb: validated.attachmentMaxSizeMb,
|
||||
showTransactionSummary: validated.showTransactionSummary,
|
||||
groupTransactionsByDate: validated.groupTransactionsByDate,
|
||||
hideAnticipatedInstallments: validated.hideAnticipatedInstallments,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ interface PreferencesFormProps {
|
||||
transactionsColumnOrder: string[] | null;
|
||||
attachmentMaxSizeMb: number;
|
||||
showTransactionSummary: boolean;
|
||||
groupTransactionsByDate: boolean;
|
||||
hideAnticipatedInstallments: boolean;
|
||||
}
|
||||
|
||||
@@ -88,6 +89,7 @@ export function PreferencesForm({
|
||||
transactionsColumnOrder: initialColumnOrder,
|
||||
attachmentMaxSizeMb: initialAttachmentMaxSizeMb,
|
||||
showTransactionSummary: initialShowTransactionSummary,
|
||||
groupTransactionsByDate: initialGroupTransactionsByDate,
|
||||
hideAnticipatedInstallments: initialHideAnticipatedInstallments,
|
||||
}: PreferencesFormProps) {
|
||||
const router = useRouter();
|
||||
@@ -111,6 +113,9 @@ export function PreferencesForm({
|
||||
const [showTransactionSummary, setShowTransactionSummary] = useState(
|
||||
initialShowTransactionSummary,
|
||||
);
|
||||
const [groupTransactionsByDate, setGroupTransactionsByDate] = useState(
|
||||
initialGroupTransactionsByDate,
|
||||
);
|
||||
const [hideAnticipatedInstallments, setHideAnticipatedInstallments] =
|
||||
useState(initialHideAnticipatedInstallments);
|
||||
|
||||
@@ -139,6 +144,7 @@ export function PreferencesForm({
|
||||
transactionsColumnOrder: columnOrder,
|
||||
attachmentMaxSizeMb,
|
||||
showTransactionSummary,
|
||||
groupTransactionsByDate,
|
||||
hideAnticipatedInstallments,
|
||||
});
|
||||
|
||||
@@ -203,6 +209,26 @@ export function PreferencesForm({
|
||||
|
||||
<Separator />
|
||||
|
||||
<section className="flex items-center justify-between max-w-md gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="group-transactions-by-date" className="text-sm">
|
||||
Agrupar por data
|
||||
</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Mostra uma barra de data acima dos lançamentos daquele dia. Quando
|
||||
desativado, a data volta a aparecer em cada lançamento.
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
id="group-transactions-by-date"
|
||||
checked={groupTransactionsByDate}
|
||||
onCheckedChange={setGroupTransactionsByDate}
|
||||
disabled={isPending}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<Separator />
|
||||
|
||||
<section className="flex items-center justify-between max-w-md gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="hide-anticipated-installments" className="text-sm">
|
||||
|
||||
@@ -7,6 +7,7 @@ interface UserPreferences {
|
||||
transactionsColumnOrder: string[] | null;
|
||||
attachmentMaxSizeMb: number;
|
||||
showTransactionSummary: boolean;
|
||||
groupTransactionsByDate: boolean;
|
||||
hideAnticipatedInstallments: boolean;
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ export async function fetchUserPreferences(
|
||||
transactionsColumnOrder: schema.userPreferences.transactionsColumnOrder,
|
||||
attachmentMaxSizeMb: schema.userPreferences.attachmentMaxSizeMb,
|
||||
showTransactionSummary: schema.userPreferences.showTransactionSummary,
|
||||
groupTransactionsByDate: schema.userPreferences.groupTransactionsByDate,
|
||||
hideAnticipatedInstallments:
|
||||
schema.userPreferences.hideAnticipatedInstallments,
|
||||
})
|
||||
|
||||
@@ -82,6 +82,7 @@ interface TransactionsPageProps {
|
||||
allowCreate?: boolean;
|
||||
noteAsColumn?: boolean;
|
||||
columnOrder?: string[] | null;
|
||||
groupTransactionsByDate?: boolean;
|
||||
defaultCardId?: string | null;
|
||||
defaultPaymentMethod?: string | null;
|
||||
lockCardSelection?: boolean;
|
||||
@@ -119,6 +120,7 @@ export function TransactionsPage({
|
||||
allowCreate = true,
|
||||
noteAsColumn = false,
|
||||
columnOrder = null,
|
||||
groupTransactionsByDate = true,
|
||||
defaultCardId,
|
||||
defaultPaymentMethod,
|
||||
lockCardSelection,
|
||||
@@ -745,6 +747,7 @@ export function TransactionsPage({
|
||||
currentUserId={currentUserId}
|
||||
noteAsColumn={noteAsColumn}
|
||||
columnOrder={columnOrder}
|
||||
groupTransactionsByDate={groupTransactionsByDate}
|
||||
payerFilterOptions={payerFilterOptions}
|
||||
categoryFilterOptions={categoryFilterOptions}
|
||||
accountCardFilterOptions={accountCardFilterOptions}
|
||||
|
||||
@@ -51,6 +51,7 @@ type BuildColumnsArgs = {
|
||||
onConvertToRecurring?: (item: TransactionItem) => void;
|
||||
isSettlementLoading: (id: string) => boolean;
|
||||
showActions: boolean;
|
||||
showDateGroups: boolean;
|
||||
columnOrder?: string[] | null;
|
||||
};
|
||||
|
||||
@@ -115,6 +116,7 @@ function buildColumns({
|
||||
onConvertToRecurring,
|
||||
isSettlementLoading,
|
||||
showActions,
|
||||
showDateGroups,
|
||||
}: BuildColumnsArgs): ColumnDef<TransactionItem>[] {
|
||||
const noop = () => undefined;
|
||||
const handleEdit = onEdit ?? noop;
|
||||
@@ -194,12 +196,14 @@ function buildColumns({
|
||||
<span className="flex items-center gap-2">
|
||||
<EstablishmentLogo name={name} size={32} />
|
||||
<span className="flex flex-col py-0.5">
|
||||
<span className="text-xs text-muted-foreground flex items-center gap-2">
|
||||
{formatDate(purchaseDate)}
|
||||
{dueDateLabel ? (
|
||||
<span className="text-primary">{dueDateLabel}</span>
|
||||
) : null}
|
||||
</span>
|
||||
{showDateGroups ? null : (
|
||||
<span className="text-xs text-muted-foreground flex items-center gap-2">
|
||||
{formatDate(purchaseDate)}
|
||||
{dueDateLabel ? (
|
||||
<span className="text-primary">{dueDateLabel}</span>
|
||||
) : null}
|
||||
</span>
|
||||
)}
|
||||
<span className="flex items-center gap-1">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
@@ -254,6 +258,15 @@ function buildColumns({
|
||||
</Badge>
|
||||
) : null}
|
||||
|
||||
{showDateGroups && dueDateLabel ? (
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="px-2 text-xs text-primary"
|
||||
>
|
||||
{dueDateLabel}
|
||||
</Badge>
|
||||
) : null}
|
||||
|
||||
{isAnticipated && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from "@/shared/components/ui/tooltip";
|
||||
import { formatDate } from "@/shared/utils/date";
|
||||
import { formatDate, formatDateGroupLabel } from "@/shared/utils/date";
|
||||
import { getConditionIcon, getPaymentMethodIcon } from "@/shared/utils/icons";
|
||||
import { cn } from "@/shared/utils/ui";
|
||||
import type { TransactionItem } from "../types";
|
||||
@@ -43,6 +43,7 @@ type TransactionsMobileListProps = {
|
||||
onConvertToRecurring?: (item: TransactionItem) => void;
|
||||
isSettlementLoading: (id: string) => boolean;
|
||||
showActions?: boolean;
|
||||
showDateGroups?: boolean;
|
||||
};
|
||||
|
||||
export function TransactionsMobileList({
|
||||
@@ -61,28 +62,87 @@ export function TransactionsMobileList({
|
||||
onConvertToRecurring,
|
||||
isSettlementLoading,
|
||||
showActions = true,
|
||||
showDateGroups = true,
|
||||
}: TransactionsMobileListProps) {
|
||||
const groups = data.reduce<
|
||||
Array<{ date: string; label: string; items: TransactionItem[] }>
|
||||
>((acc, item) => {
|
||||
const date = item.purchaseDate?.slice(0, 10) ?? "";
|
||||
const existingGroup = acc.find((group) => group.date === date);
|
||||
if (existingGroup) {
|
||||
existingGroup.items.push(item);
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc.push({
|
||||
date,
|
||||
label: formatDateGroupLabel(item.purchaseDate),
|
||||
items: [item],
|
||||
});
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
if (!showDateGroups) {
|
||||
return (
|
||||
<div className="space-y-3 md:hidden">
|
||||
{data.map((item) => (
|
||||
<TransactionMobileCard
|
||||
key={item.id}
|
||||
item={item}
|
||||
currentUserId={currentUserId}
|
||||
onEdit={onEdit}
|
||||
onCopy={onCopy}
|
||||
onImport={onImport}
|
||||
onConfirmDelete={onConfirmDelete}
|
||||
onViewDetails={onViewDetails}
|
||||
onRefund={onRefund}
|
||||
onToggleSettlement={onToggleSettlement}
|
||||
onAnticipate={onAnticipate}
|
||||
onViewAnticipationHistory={onViewAnticipationHistory}
|
||||
onConvertToInstallment={onConvertToInstallment}
|
||||
onConvertToRecurring={onConvertToRecurring}
|
||||
isSettlementLoading={isSettlementLoading}
|
||||
showActions={showActions}
|
||||
showDate
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3 md:hidden">
|
||||
{data.map((item) => (
|
||||
<TransactionMobileCard
|
||||
key={item.id}
|
||||
item={item}
|
||||
currentUserId={currentUserId}
|
||||
onEdit={onEdit}
|
||||
onCopy={onCopy}
|
||||
onImport={onImport}
|
||||
onConfirmDelete={onConfirmDelete}
|
||||
onViewDetails={onViewDetails}
|
||||
onRefund={onRefund}
|
||||
onToggleSettlement={onToggleSettlement}
|
||||
onAnticipate={onAnticipate}
|
||||
onViewAnticipationHistory={onViewAnticipationHistory}
|
||||
onConvertToInstallment={onConvertToInstallment}
|
||||
onConvertToRecurring={onConvertToRecurring}
|
||||
isSettlementLoading={isSettlementLoading}
|
||||
showActions={showActions}
|
||||
/>
|
||||
<div className="space-y-4 md:hidden">
|
||||
{groups.map((group, groupIndex) => (
|
||||
<section
|
||||
key={`${group.date || group.label}-${groupIndex}`}
|
||||
className="space-y-2"
|
||||
>
|
||||
<div className="rounded-md border bg-muted/60 px-3 py-1.5 text-xs font-semibold tracking-wide text-muted-foreground">
|
||||
{group.label}
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
{group.items.map((item) => (
|
||||
<TransactionMobileCard
|
||||
key={item.id}
|
||||
item={item}
|
||||
currentUserId={currentUserId}
|
||||
onEdit={onEdit}
|
||||
onCopy={onCopy}
|
||||
onImport={onImport}
|
||||
onConfirmDelete={onConfirmDelete}
|
||||
onViewDetails={onViewDetails}
|
||||
onRefund={onRefund}
|
||||
onToggleSettlement={onToggleSettlement}
|
||||
onAnticipate={onAnticipate}
|
||||
onViewAnticipationHistory={onViewAnticipationHistory}
|
||||
onConvertToInstallment={onConvertToInstallment}
|
||||
onConvertToRecurring={onConvertToRecurring}
|
||||
isSettlementLoading={isSettlementLoading}
|
||||
showActions={showActions}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
@@ -90,6 +150,7 @@ export function TransactionsMobileList({
|
||||
|
||||
type TransactionMobileCardProps = Omit<TransactionsMobileListProps, "data"> & {
|
||||
item: TransactionItem;
|
||||
showDate?: boolean;
|
||||
};
|
||||
|
||||
function TransactionMobileCard({
|
||||
@@ -108,6 +169,7 @@ function TransactionMobileCard({
|
||||
onConvertToRecurring,
|
||||
isSettlementLoading,
|
||||
showActions = true,
|
||||
showDate = false,
|
||||
}: TransactionMobileCardProps) {
|
||||
const installmentBadge =
|
||||
item.currentInstallment && item.installmentCount
|
||||
@@ -156,10 +218,12 @@ function TransactionMobileCard({
|
||||
{item.name}
|
||||
</h3>
|
||||
<div className="mt-1 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground">
|
||||
<span className="inline-flex items-center gap-1">
|
||||
<RiCalendarEventLine className="size-3.5" aria-hidden />
|
||||
{formatDate(item.purchaseDate)}
|
||||
</span>
|
||||
{showDate ? (
|
||||
<span className="inline-flex items-center gap-1">
|
||||
<RiCalendarEventLine className="size-3.5" aria-hidden />
|
||||
{formatDate(item.purchaseDate)}
|
||||
</span>
|
||||
) : null}
|
||||
{dueDateLabel ? (
|
||||
<span className="font-medium text-primary">
|
||||
{dueDateLabel}
|
||||
|
||||
@@ -9,13 +9,14 @@ import {
|
||||
getCoreRowModel,
|
||||
getPaginationRowModel,
|
||||
getSortedRowModel,
|
||||
type Row,
|
||||
type RowSelectionState,
|
||||
type SortingState,
|
||||
useReactTable,
|
||||
type VisibilityState,
|
||||
} from "@tanstack/react-table";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { type ReactNode, useMemo, useState } from "react";
|
||||
import { Fragment, type ReactNode, useMemo, useState } from "react";
|
||||
import type {
|
||||
TransactionsExportContext,
|
||||
TransactionsPaginationState,
|
||||
@@ -37,6 +38,7 @@ import {
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/shared/components/ui/tooltip";
|
||||
import { formatDateGroupLabel } from "@/shared/utils/date";
|
||||
import { cn } from "@/shared/utils/ui";
|
||||
import { TransactionsExport } from "../transactions-export";
|
||||
import type {
|
||||
@@ -79,6 +81,7 @@ type TransactionsTableProps = {
|
||||
isSettlementLoading?: (id: string) => boolean;
|
||||
showActions?: boolean;
|
||||
showFilters?: boolean;
|
||||
groupTransactionsByDate?: boolean;
|
||||
};
|
||||
|
||||
export function TransactionsTable({
|
||||
@@ -110,6 +113,7 @@ export function TransactionsTable({
|
||||
isSettlementLoading,
|
||||
showActions = true,
|
||||
showFilters = true,
|
||||
groupTransactionsByDate = true,
|
||||
}: TransactionsTableProps) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
@@ -145,12 +149,14 @@ export function TransactionsTable({
|
||||
onViewAnticipationHistory,
|
||||
isSettlementLoading: isSettlementLoading ?? (() => false),
|
||||
showActions,
|
||||
showDateGroups: groupTransactionsByDate,
|
||||
columnOrder: columnOrderPreference,
|
||||
}),
|
||||
[
|
||||
currentUserId,
|
||||
noteAsColumn,
|
||||
columnOrderPreference,
|
||||
groupTransactionsByDate,
|
||||
onEdit,
|
||||
onCopy,
|
||||
onImport,
|
||||
@@ -191,6 +197,24 @@ export function TransactionsTable({
|
||||
|
||||
const rowModel = table.getRowModel();
|
||||
const hasRows = rowModel.rows.length > 0;
|
||||
const groupedRows = rowModel.rows.reduce<
|
||||
Array<{ date: string; label: string; rows: Row<TransactionItem>[] }>
|
||||
>((acc, row) => {
|
||||
const date = row.original.purchaseDate?.slice(0, 10) ?? "";
|
||||
const existingGroup = acc.find((group) => group.date === date);
|
||||
if (existingGroup) {
|
||||
existingGroup.rows.push(row);
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc.push({
|
||||
date,
|
||||
label: formatDateGroupLabel(row.original.purchaseDate),
|
||||
rows: [row],
|
||||
});
|
||||
return acc;
|
||||
}, []);
|
||||
const visibleColumnCount = table.getVisibleLeafColumns().length;
|
||||
const totalRows = isServerPaginated
|
||||
? (serverPagination?.totalItems ?? 0)
|
||||
: table.getCoreRowModel().rows.length;
|
||||
@@ -275,6 +299,25 @@ export function TransactionsTable({
|
||||
|
||||
const showTopControls =
|
||||
Boolean(createSlot) || Boolean(onMassAdd) || showFilters;
|
||||
const renderTransactionRow = (row: Row<TransactionItem>) => (
|
||||
<TableRow
|
||||
key={row.id}
|
||||
className={cn(
|
||||
row.original.paymentMethod === "Boleto" &&
|
||||
row.original.dueDate &&
|
||||
!row.original.isSettled &&
|
||||
new Date(row.original.dueDate) < new Date()
|
||||
? "bg-destructive/3 hover:bg-destructive/5"
|
||||
: undefined,
|
||||
)}
|
||||
>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
);
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
@@ -366,7 +409,7 @@ export function TransactionsTable({
|
||||
) : null}
|
||||
|
||||
<Card className="py-2">
|
||||
<CardContent className="px-2 py-4 sm:px-4">
|
||||
<CardContent className="px-2 sm:px-4">
|
||||
{hasRows ? (
|
||||
<>
|
||||
<TransactionsMobileList
|
||||
@@ -383,6 +426,7 @@ export function TransactionsTable({
|
||||
onViewAnticipationHistory={onViewAnticipationHistory}
|
||||
isSettlementLoading={isSettlementLoading ?? (() => false)}
|
||||
showActions={showActions}
|
||||
showDateGroups={groupTransactionsByDate}
|
||||
/>
|
||||
|
||||
<div className="hidden overflow-x-auto md:block">
|
||||
@@ -407,28 +451,23 @@ export function TransactionsTable({
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rowModel.rows.map((row) => (
|
||||
<TableRow
|
||||
key={row.id}
|
||||
className={cn(
|
||||
row.original.paymentMethod === "Boleto" &&
|
||||
row.original.dueDate &&
|
||||
!row.original.isSettled &&
|
||||
new Date(row.original.dueDate) < new Date()
|
||||
? "bg-destructive/3 hover:bg-destructive/5"
|
||||
: undefined,
|
||||
)}
|
||||
>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
{flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext(),
|
||||
)}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
{groupTransactionsByDate
|
||||
? groupedRows.map((group, groupIndex) => (
|
||||
<Fragment
|
||||
key={`${group.date || group.label}-${groupIndex}`}
|
||||
>
|
||||
<TableRow className="border-y bg-muted/40 hover:bg-muted/60">
|
||||
<TableCell
|
||||
colSpan={visibleColumnCount}
|
||||
className="h-9 px-3 py-2 text-xs font-semibold text-muted-foreground"
|
||||
>
|
||||
{group.label}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{group.rows.map(renderTransactionRow)}
|
||||
</Fragment>
|
||||
))
|
||||
: rowModel.rows.map(renderTransactionRow)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
@@ -331,6 +331,45 @@ export function formatDate(value: string | Date | null | undefined): string {
|
||||
.replace(" de", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a date-only value as a compact group label.
|
||||
* @example
|
||||
* formatDateGroupLabel("2026-06-26") // "SEX, 26 JUN 2026"
|
||||
*/
|
||||
export function formatDateGroupLabel(
|
||||
value: string | Date | null | undefined,
|
||||
): string {
|
||||
const dateString = toDateOnlyString(value);
|
||||
if (!dateString) {
|
||||
return "—";
|
||||
}
|
||||
|
||||
const parsed = parseUtcDateString(dateString);
|
||||
if (!parsed) {
|
||||
return "—";
|
||||
}
|
||||
|
||||
const parts = new Intl.DateTimeFormat("pt-BR", {
|
||||
weekday: "short",
|
||||
day: "2-digit",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
timeZone: "UTC",
|
||||
}).formatToParts(parsed);
|
||||
const weekday = parts.find((part) => part.type === "weekday")?.value;
|
||||
const day = parts.find((part) => part.type === "day")?.value;
|
||||
const month = parts.find((part) => part.type === "month")?.value;
|
||||
const year = parts.find((part) => part.type === "year")?.value;
|
||||
|
||||
if (!weekday || !day || !month || !year) {
|
||||
return "—";
|
||||
}
|
||||
|
||||
return `${weekday.replace(".", "").toUpperCase()}, ${day} ${month
|
||||
.replace(".", "")
|
||||
.toUpperCase()} ${year}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a date-only value (YYYY-MM-DD) using UTC to preserve the civil day
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user