Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

improve invoice/payouts

Steven Tey9d299786a0b3
diff --git a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/partner-payout-invoice.tsx b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/partner-payout-invoice.tsx
index 82d6dc0e1b..29d9804b7a 100644
--- a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/partner-payout-invoice.tsx
+++ b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/partner-payout-invoice.tsx
@@ -182,6 +182,18 @@ export async function PartnerPayoutInvoice({
label: "Invoice total",
value: `${currencyFormatter(invoice.total)}${nonUsdTransactionDisplay}`,
},
+ ...(invoice.refundedAmount > 0
+ ? [
+ {
+ label: "Refunded amount",
+ value: `-${currencyFormatter(invoice.refundedAmount)}`,
+ },
+ {
+ label: "Refund reason",
+ value: invoice.refundReason ?? "-",
+ },
+ ]
+ : []),
// if customer is in EU or AU, add VAT/GST reverse charge note
...(EU_CUSTOMER || AU_CUSTOMER
? [
@@ -368,15 +380,16 @@ export async function PartnerPayoutInvoice({
))}
{/* Stacked avatars and View +N more row */}
- {(hiddenPayouts.length > 0 || remainingPayoutsTotal > 0) && (
- <View
- style={tw(
- "flex-row items-center gap-2 p-3.5 w-full text-sm font-medium text-neutral-700 border-neutral-200 border-t",
- )}
- >
- {/* Stacked avatars for hidden partners */}
- <View style={tw("flex-row -space-x-1")}>
- {hiddenPayouts.slice(0, 4).map((payout, index) => (
+ <View
+ style={tw(
+ "flex-row items-center gap-2 p-3.5 w-full text-sm font-medium text-neutral-700 border-neutral-200 border-t",
+ )}
+ >
+ {/* Stacked avatars for hidden partners */}
+ <View style={tw("flex-row -space-x-1")}>
+ {(hiddenPayouts.length > 0 ? hiddenPayouts : visiblePayouts)
+ .slice(0, 4)
+ .map((payout, index) => (
<Image
key={index}
src={
@@ -388,19 +401,25 @@ export async function PartnerPayoutInvoice({
)}
/>
))}
- </View>
- <Link
- href={`${APP_DOMAIN}/${workspace.slug}/program/payouts?invoiceId=${invoice.id}`}
- style={tw("text-blue-600")}
- >
- View +
- {nFormatter(hiddenPayouts.length + remainingPayoutsTotal, {
- full: true,
- })}{" "}
- more payouts
- </Link>
</View>
- )}
+ <Link
+ href={`${APP_DOMAIN}/${workspace.slug}/program/payouts?invoiceId=${invoice.id}`}
+ style={tw("text-blue-600")}
+ >
+ View{" "}
+ {hiddenPayouts.length
+ ? `+ ${nFormatter(
+ hiddenPayouts.length + remainingPayoutsTotal,
+ {
+ full: true,
+ },
+ )} more payouts`
+ : visiblePayouts.length > 1
+ ? "all payouts"
+ : "payout"}{" "}
+ in Dub
+ </Link>
+ </View>
</View>
)}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/[payoutId]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/[payoutId]/page.tsx
index 635e833b69..e2e07d544f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/[payoutId]/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/[payoutId]/page.tsx
@@ -4,6 +4,7 @@ import { clientAccessCheck } from "@/lib/client-access-check";
import { usePayout } from "@/lib/swr/use-payout";
import useWorkspace from "@/lib/swr/use-workspace";
import { CommissionResponse, PayoutResponse } from "@/lib/types";
+import { CLAWBACK_REASONS_MAP } from "@/lib/zod/schemas/commissions";
import { CustomerAvatar } from "@/ui/customers/customer-avatar";
import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
@@ -325,7 +326,9 @@ function PayoutDetailsContent({
</Link>
) : (
<span className="max-w-xs truncate text-sm text-neutral-700">
- {getCommissionTypeLabel(row.original)}
+ {row.original.type === "custom" && row.original.description
+ ? row.original.description
+ : getCommissionTypeLabel(row.original)}
</span>
)}
<span className="text-xs text-neutral-500">
@@ -351,7 +354,40 @@ function PayoutDetailsContent({
minSize: 120,
size: 120,
maxSize: 120,
- cell: ({ row }) => currencyFormatter(row.original.earnings),
+ cell: ({ row }) => {
+ const commission = row.original;
+ const earnings = currencyFormatter(commission.earnings);
+
+ if (commission.description) {
+ const reason =
+ CLAWBACK_REASONS_MAP[commission.description]?.description ??
+ commission.description;
+
+ return (
+ <Tooltip content={reason}>
+ <span
+ className={cn(
+ "cursor-help truncate underline decoration-dotted underline-offset-2",
+ commission.earnings < 0 && "text-red-600",
+ )}
+ >
+ {earnings}
+ </span>
+ </Tooltip>
+ );
+ }
+
+ return (
+ <span
+ className={cn(
+ commission.earnings < 0 && "text-red-600",
+ "truncate",
+ )}
+ >
+ {earnings}
+ </span>
+ );
+ },
},
{
id: "menu",
diff --git a/apps/web/prisma/schema/invoice.prisma b/apps/web/prisma/schema/invoice.prisma
index ba277762ac..1e5d444d2d 100644
--- a/apps/web/prisma/schema/invoice.prisma
+++ b/apps/web/prisma/schema/invoice.prisma
@@ -28,9 +28,11 @@ model Invoice {
paymentMethod PaymentMethod?
amount Int @default(0) // amount in usd cents
fee Int @default(0) // fee in usd cents
+ refundedAmount Int @default(0) // refunded amount in usd cents
total Int @default(0) // amount + fee in usd cents
externalAmount Int @default(0) // amount in usd cents for external payouts
receiptUrl String? @db.Text
+ refundReason String? @db.Text
failedReason String? @db.Text
registeredDomains Json? @db.Json // Array of RegisteredDomain
stripeChargeMetadata Json? @db.Json // Stripe charge metadata