The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
address CR feedback
Steven Tey8cf0891cf7f5
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsxindex cbf95dda79..373d326f3c 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx@@ -34,7 +34,14 @@ import { Minus } from "@dub/ui/icons";import { cn, currencyFormatter, formatDate } from "@dub/utils";import { CommissionType } from "@prisma/client";import { useParams } from "next/navigation";-import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";+import {+ Dispatch,+ SetStateAction,+ useEffect,+ useMemo,+ useRef,+ useState,+} from "react";import { Controller, useForm } from "react-hook-form";import { toast } from "sonner";import useSWR from "swr";@@ -234,8 +241,11 @@ function CreateCommissionSheetContent({);const stripeInvoices = stripeInvoicesData?.invoices ?? [];+ const paidStripeInvoiceCount = stripeInvoices.filter(+ (inv) => !inv.refunded,+ ).length;const unimportedStripeInvoices = stripeInvoices.filter(- (inv) => !inv.dubCommissionId,+ (inv) => !inv.dubCommissionId && !inv.refunded,);const unimportedStripeInvoiceIdsKey = unimportedStripeInvoices.map((invoice) => invoice.id)@@ -251,10 +261,42 @@ function CreateCommissionSheetContent({selectedStripeInvoiceIds ?? unimportedStripeInvoiceIds;const noStripeCustomerId = stripeInvoicesData?.noStripeCustomerId ?? false;const noStripeCustomerMessage = stripeInvoicesData?.message;+ const stripeInvoiceSelectionScopeRef = useRef({+ customerId,+ importStripeInvoices,+ });useEffect(() => {- setSelectedStripeInvoiceIds(null);- }, [customerId, importStripeInvoices, unimportedStripeInvoiceIdsKey]);+ const scope = stripeInvoiceSelectionScopeRef.current;+ const scopeChanged =+ scope.customerId !== customerId ||+ scope.importStripeInvoices !== importStripeInvoices;++ stripeInvoiceSelectionScopeRef.current = {+ customerId,+ importStripeInvoices,+ };++ // null selects every eligible invoice. Only restore that default when the+ // customer or import mode changes; a refreshed invoice list should keep+ // an explicit selection that is still eligible.+ if (scopeChanged) {+ setSelectedStripeInvoiceIds(null);+ return;+ }++ const eligibleIds = new Set(unimportedStripeInvoiceIds);++ setSelectedStripeInvoiceIds((current) => {+ if (current === null) {+ return null;+ }++ const retained = current.filter((id) => eligibleIds.has(id));++ return retained.length === current.length ? current : retained;+ });+ }, [customerId, importStripeInvoices, unimportedStripeInvoiceIds]);useEffect(() => {if (commissionType === "custom") {@@ -757,6 +799,16 @@ function CreateCommissionSheetContent({<buttontype="button"className="flex items-center"+ aria-label="Select all invoices"+ aria-checked={+ selectedInvoiceIdsToImport.length ===+ unimportedStripeInvoiceIds.length+ ? true+ : selectedInvoiceIdsToImport.length > 0+ ? "mixed"+ : false+ }+ role="checkbox"onClick={() => {const allSelected =selectedInvoiceIdsToImport.length ===@@ -783,59 +835,72 @@ function CreateCommissionSheetContent({</button>)}<p className="text-xs font-medium text-neutral-500">- Paid invoices ({stripeInvoices.length})+ Paid invoices ({paidStripeInvoiceCount})</p></div><div className="flex max-h-96 flex-col gap-1 overflow-y-auto p-1.5">{stripeInvoices.map((inv) => {const imported = Boolean(inv.dubCommissionId);+ const disabled = imported || inv.refunded;const selected =- !imported &&+ !disabled &&selectedInvoiceIdsToImport.includes(inv.id);+ const toggleSelected = () => {+ setSelectedStripeInvoiceIds((current) => {+ const selectedIds =+ current ?? unimportedStripeInvoiceIds;++ return selectedIds.includes(inv.id)+ ? selectedIds.filter(+ (id) => id !== inv.id,+ )+ : [...selectedIds, inv.id];+ });+ };return (<divkey={inv.id}className={cn("flex items-center gap-3 rounded-md px-2.5 py-1.5",- imported- ? "opacity-60"- : "cursor-pointer hover:bg-neutral-50",+ disabled && "opacity-60",selected && "bg-neutral-100",)}- onClick={() => {- if (imported) {- return;- }-- setSelectedStripeInvoiceIds(- (current) => {- const selectedIds =- current ??- unimportedStripeInvoiceIds;-- return selectedIds.includes(inv.id)- ? selectedIds.filter(- (id) => id !== inv.id,- )- : [...selectedIds, inv.id];- },- );- }}>- <InvoiceCheckbox- checked={selected}- disabled={imported}- />+ <span className="relative inline-flex size-4 shrink-0 rounded-sm focus-within:ring-2 focus-within:ring-black focus-within:ring-offset-2">+ <input+ id={`stripe-invoice-${inv.id}`}+ type="checkbox"+ checked={selected}+ disabled={disabled}+ aria-label={`Select invoice ${inv.id}`}+ onChange={toggleSelected}+ onKeyDown={(event) => {+ if (+ event.key !== "Enter" ||+ disabled+ ) {+ return;+ }++ event.preventDefault();+ toggleSelected();+ }}+ className="absolute inset-0 z-10 cursor-pointer opacity-0 disabled:cursor-not-allowed"+ />+ <InvoiceCheckbox+ checked={selected}+ disabled={disabled}+ />+ </span><div className="min-w-0 flex-1"><ahref={`https://dashboard.stripe.com/invoices/${inv.id}`}target="_blank"rel="noopener noreferrer"- onClick={(e) => e.stopPropagation()}className={cn("cursor-alias font-mono text-sm font-medium decoration-dotted underline-offset-2 hover:underline",- imported+ disabled? "text-neutral-500": "text-neutral-800",)}@@ -843,7 +908,14 @@ function CreateCommissionSheetContent({{inv.id}</a><p className="mt-0.5 flex flex-wrap items-center gap-x-2 text-xs text-neutral-500">- Paid on {formatDate(inv.createdAt)}+ <label+ htmlFor={`stripe-invoice-${inv.id}`}+ className={cn(+ !disabled && "cursor-pointer",+ )}+ >+ Paid on {formatDate(inv.createdAt)}+ </label>{inv.refunded ? (<span className="rounded-md bg-neutral-200/80 px-1.5 py-0.5 text-xs text-neutral-500">Refunded@@ -852,9 +924,6 @@ function CreateCommissionSheetContent({<ahref={`/${slug}/program/commissions?partnerId=${partnerId}&customerId=${customerId}`}target="_blank"- onClick={(e) =>- e.stopPropagation()- }className="rounded bg-neutral-200/80 px-1.5 py-0.5 text-neutral-500 hover:bg-neutral-200 hover:text-neutral-900">Already imported@@ -862,16 +931,17 @@ function CreateCommissionSheetContent({) : null}</p></div>- <span+ <label+ htmlFor={`stripe-invoice-${inv.id}`}className={cn("shrink-0 text-sm font-medium",- imported+ disabled? "text-neutral-500"- : "text-neutral-700",+ : "cursor-pointer text-neutral-700",)}>{currencyFormatter(inv.amount)}- </span>+ </label></div>);})}