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.

Update payout-stats.tsx

Kiran K518a173ceedf
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
index 1be13eabc1..c60ffefac1 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/payout-stats.tsx
@@ -3,10 +3,18 @@
import usePartnerPayoutsCount from "@/lib/swr/use-partner-payouts-count";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import { PayoutsCount } from "@/lib/types";
+import { ConnectPayoutButton } from "@/ui/partners/connect-payout-button";
import { PayoutStatusBadges } from "@/ui/partners/payout-status-badges";
+import { AlertCircleFill } from "@/ui/shared/icons";
import { PayoutStatus } from "@dub/prisma/client";
-import { InfoTooltip } from "@dub/ui";
-import { cn, currencyFormatter } from "@dub/utils";
+import { Tooltip } from "@dub/ui";
+import {
+ cn,
+ CONNECT_SUPPORTED_COUNTRIES,
+ currencyFormatter,
+ PAYPAL_SUPPORTED_COUNTRIES,
+} from "@dub/utils";
+import { HelpCircle } from "lucide-react";
import { ReactNode } from "react";
import { usePartnerPayoutSettingsModal } from "./partner-payout-settings-modal";
@@ -38,6 +46,7 @@ function PayoutStatsCard({
tooltip,
sublabel,
error,
+ showConnectButton,
}: {
label: string;
amount: number;
@@ -46,7 +55,10 @@ function PayoutStatsCard({
tooltip?: string;
sublabel?: () => ReactNode;
error?: boolean;
+ showConnectButton?: boolean;
}) {
+ const { partner } = usePartnerProfile();
+
const isLoading = amount === undefined || error;
return (
@@ -60,41 +72,66 @@ function PayoutStatsCard({
>
<Icon className="size-4" />
</div>
+
<span className="text-xs font-medium leading-3 text-neutral-500">
{label}
</span>
{tooltip && (
- <InfoTooltip content={tooltip} side="top" className="size-3.5" />
+ <Tooltip content={tooltip} side="top">
+ <div>
+ <HelpCircle className="size-3.5 text-neutral-500" />
+ </div>
+ </Tooltip>
)}
</div>
- <div className="flex items-center gap-2">
- {!isLoading ? (
- <div className="flex items-center gap-2">
- <span className="h-7 text-base font-medium leading-6 text-neutral-800 sm:text-xl sm:leading-7">
- {error ? (
- "-"
- ) : (
- <>
- {amount > 0
- ? currencyFormatter(amount / 100, {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- })
- : "$0.00"}
- </>
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ {!isLoading ? (
+ <div className="flex items-center gap-2">
+ {partner && !partner.payoutsEnabledAt && (
+ <Tooltip
+ content="You need to connect your bank account to be able to receive payouts from the programs you are enrolled in."
+ side="right"
+ >
+ <div>
+ <AlertCircleFill className="size-5 text-black" />
+ </div>
+ </Tooltip>
)}
- </span>
- {sublabel && (
- <span className="items-center gap-6 rounded-md bg-neutral-100 px-2 py-1 text-xs font-medium leading-4 text-neutral-700">
- {sublabel()}
+ <span className="h-7 text-base font-medium leading-6 text-neutral-800 sm:text-xl sm:leading-7">
+ {error ? (
+ "-"
+ ) : (
+ <>
+ {amount > 0
+ ? currencyFormatter(amount / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })
+ : "$0.00"}
+ </>
+ )}
</span>
- )}
- </div>
- ) : (
- <div className="h-7 w-20 animate-pulse rounded bg-neutral-200 sm:h-7 sm:w-24" />
+
+ {sublabel && (
+ <span className="items-center gap-6 rounded-md bg-neutral-100 px-2 py-1 text-xs font-medium leading-4 text-neutral-700">
+ {sublabel()}
+ </span>
+ )}
+ </div>
+ ) : (
+ <div className="h-7 w-20 animate-pulse rounded bg-neutral-200 sm:h-7 sm:w-24" />
+ )}
+ </div>
+
+ {showConnectButton && (
+ <ConnectPayoutButton
+ className="h-8 w-fit rounded-lg px-2.5 py-2"
+ text="Connect payouts"
+ />
)}
</div>
</div>
@@ -111,20 +148,22 @@ export function PayoutStats() {
const { PartnerPayoutSettingsModal, setShowPartnerPayoutSettingsModal } =
usePartnerPayoutSettingsModal();
+ const payoutStatusMap = Object.fromEntries(
+ payoutsCount?.map((p) => [p.status, p]) || [],
+ ) as Record<PayoutStatus, PayoutsCount>;
+
let payoutMethod: "stripe" | "paypal" | undefined = undefined;
- if (partner?.stripeConnectId) {
- payoutMethod = "stripe";
- } else if (partner?.paypalEmail) {
- payoutMethod = "paypal";
+ if (partner?.country) {
+ if (PAYPAL_SUPPORTED_COUNTRIES.includes(partner.country)) {
+ payoutMethod = "paypal";
+ } else if (CONNECT_SUPPORTED_COUNTRIES.includes(partner.country)) {
+ payoutMethod = "stripe";
+ }
}
const tooltip = payoutMethod ? tooltips[payoutMethod] : undefined;
- const payoutStatusMap = Object.fromEntries(
- payoutsCount?.map((p) => [p.status, p]) || [],
- ) as Record<PayoutStatus, PayoutsCount>;
-
const payoutStats = [
{
label: "Pending",
@@ -133,7 +172,9 @@ export function PayoutStats() {
iconClassName: "bg-orange-100 text-orange-500",
tooltip: tooltip?.pending,
error: !!error,
+ showConnectButton: partner && !partner.payoutsEnabledAt,
},
+
{
label: "Processing",
amount: payoutStatusMap?.processing?.amount,
@@ -143,7 +184,7 @@ export function PayoutStats() {
error: !!error,
},
- ...(payoutMethod === "stripe"
+ ...(payoutMethod !== "paypal"
? [
{
label: "Sent",