The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add selectedRows
Kiran Kbd6ca9b5f483
diff --git a/apps/web/ui/partners/payout-invoice-sheet.tsx b/apps/web/ui/partners/payout-invoice-sheet.tsxindex d46a32ca2b..63f15722ad 100644--- a/apps/web/ui/partners/payout-invoice-sheet.tsx+++ b/apps/web/ui/partners/payout-invoice-sheet.tsx@@ -9,16 +9,10 @@ import { PayoutResponse } from "@/lib/types";import { X } from "@/ui/shared/icons";import { Button, Sheet, Table, useRouterStuff, useTable } from "@dub/ui";import { cn, currencyFormatter, DICEBEAR_AVATAR_URL } from "@dub/utils";+import { Row } from "@tanstack/react-table";import { useAction } from "next-safe-action/hooks";import { useParams } from "next/navigation";-import {- Dispatch,- Fragment,- SetStateAction,- useEffect,- useMemo,- useState,-} from "react";+import { Dispatch, Fragment, SetStateAction, useMemo, useState } from "react";import { toast } from "sonner";interface PayoutInvoiceSheetProps {@@ -64,13 +58,6 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {[payouts],);- // Select all pending payouts by default- useEffect(() => {- if (pendingPayouts) {- setSelectedPayouts(pendingPayouts);- }- }, [pendingPayouts]);-const invoiceData = useMemo(() => {if (!selectedPayouts) {return {@@ -173,10 +160,14 @@ function PayoutInvoiceSheetContent({ setIsOpen }: PayoutInvoiceSheetProps) {error: payoutsError? "Failed to load payouts for this invoice.": undefined,- onRowSelectionChange: (rows) => {- setSelectedPayouts(rows.map((row) => row.original));- },- getRowId: (originalRow) => originalRow.id,++ getRowId: (originalRow: PayoutResponse) => originalRow.id,+ onRowSelectionChange: (rows: Row<PayoutResponse>[]) =>+ setSelectedPayouts(rows.map((row) => row.original)),+ selectedRows: selectedPayouts?.reduce((acc, payout) => {+ acc[payout.id] = true;+ return acc;+ }, {}),} as any);return (diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsxindex a1c9a9ac65..c0841d1835 100644--- a/packages/ui/src/table/table.tsx+++ b/packages/ui/src/table/table.tsx@@ -55,9 +55,13 @@ type UseTableProps<T> = {columnPinning?: ColumnPinningState;resourceName?: (plural: boolean) => string;onRowClick?: (row: Row<T>, e: MouseEvent) => void;++ // Row selectiononRowSelectionChange?: (rows: Row<T>[]) => void;+ selectedRows?: RowSelectionState;getRowId?: (row: T) => string;+ // Table stylesclassName?: string;containerClassName?: string;scrollWrapperClassName?: string;@@ -88,16 +92,16 @@ export function useTable<T extends any>(columnPinning,pagination,onPaginationChange,- getRowId+ getRowId,} = props;const [columnVisibility, setColumnVisibility] = useState<VisibilityState>(props.columnVisibility ?? {},);- const [rowSelection, setRowSelection] = useState<RowSelectionState>({});-- console.log(rowSelection)+ const [rowSelection, setRowSelection] = useState<RowSelectionState>(+ props.selectedRows ?? {},+ );// Update internal columnVisibility when prop value changesuseEffect(() => {@@ -133,9 +137,9 @@ export function useTable<T extends any>(getCoreRowModel: getCoreRowModel(),onPaginationChange,onColumnVisibilityChange: (visibility) => setColumnVisibility(visibility),- onRowSelectionChange: (selection) => setRowSelection(selection),+ onRowSelectionChange: setRowSelection,state: {- pagination: pagination,+ pagination,columnVisibility,columnPinning: { left: [], right: [], ...columnPinning },rowSelection,@@ -143,7 +147,7 @@ export function useTable<T extends any>(manualPagination: true,autoResetPageIndex: false,manualSorting: true,- getRowId+ getRowId,});return {