corrige importacao de lancamentos compartilhados

This commit is contained in:
Felipe Coutinho
2026-06-09 20:41:41 -03:00
parent c81584095b
commit 4cbdddb12e
6 changed files with 31 additions and 12 deletions

View File

@@ -92,7 +92,7 @@ export function TransactionActionsMenu({
</DropdownMenuItem>
) : null}
{!item.readonly && !isOwnData ? (
{!isOwnData ? (
<DropdownMenuItem
onSelect={() => onImport?.(item)}
disabled={!onImport}

View File

@@ -139,6 +139,7 @@ function buildColumns({
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
disabled={!row.getCanSelect()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Selecionar linha"
/>

View File

@@ -175,7 +175,10 @@ export function TransactionsTable({
: getPaginationRowModel(),
manualPagination: isServerPaginated,
pageCount: serverPagination?.totalPages,
enableRowSelection: (row) => !row.original.readonly,
enableRowSelection: (row) =>
row.original.userId === currentUserId
? !row.original.readonly
: Boolean(onBulkImport),
});
const rowModel = table.getRowModel();
@@ -184,11 +187,21 @@ export function TransactionsTable({
? (serverPagination?.totalItems ?? 0)
: table.getCoreRowModel().rows.length;
const selectedRows = table.getFilteredSelectedRowModel().rows;
const selectedOwnRows = selectedRows.filter(
(row) => row.original.userId === currentUserId,
);
const selectedImportRows = selectedRows.filter(
(row) => row.original.userId !== currentUserId,
);
const selectedCount = selectedRows.length;
const selectedTotal = selectedRows.reduce(
(total, row) => total + (row.original.amount ?? 0),
0,
);
const selectedImportTotal = selectedImportRows.reduce(
(total, row) => total + (row.original.amount ?? 0),
0,
);
const currentPage = isServerPaginated
? (serverPagination?.page ?? 1)
: table.getState().pagination.pageIndex + 1;
@@ -211,8 +224,8 @@ export function TransactionsTable({
};
const handleBulkImport = () => {
if (onBulkImport && selectedCount > 0) {
onBulkImport(selectedRows.map((row) => row.original));
if (onBulkImport && selectedImportRows.length > 0) {
onBulkImport(selectedImportRows.map((row) => row.original));
setRowSelection({});
}
};
@@ -326,7 +339,7 @@ export function TransactionsTable({
{selectedCount > 0 &&
onBulkDelete &&
selectedRows.every((row) => row.original.userId === currentUserId) ? (
selectedOwnRows.length === selectedCount ? (
<TransactionsBulkBar
selectedCount={selectedCount}
selectedTotal={selectedTotal}
@@ -335,12 +348,10 @@ export function TransactionsTable({
/>
) : null}
{selectedCount > 0 &&
onBulkImport &&
selectedRows.some((row) => row.original.userId !== currentUserId) ? (
{selectedCount > 0 && onBulkImport && selectedImportRows.length > 0 ? (
<TransactionsBulkBar
selectedCount={selectedCount}
selectedTotal={selectedTotal}
selectedCount={selectedImportRows.length}
selectedTotal={selectedImportTotal}
mode="import"
onAction={handleBulkImport}
/>