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 payout.failureReason, add payoutMethod to usePartnerProfile

Steven Teycd83285fabac
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/partner-payout-details-sheet.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/partner-payout-details-sheet.tsx
index 145607e762..c153df0fd4 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/partner-payout-details-sheet.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/payouts/partner-payout-details-sheet.tsx
@@ -14,6 +14,7 @@ import {
Button,
CircleArrowRight,
CopyText,
+ DynamicTooltipWrapper,
InvoiceDollar,
LoadingSpinner,
Sheet,
@@ -45,7 +46,7 @@ type PayoutDetailsSheetProps = {
};
function PayoutDetailsSheetContent({ payout }: PayoutDetailsSheetProps) {
- const { partner } = usePartnerProfile();
+ const { partner, payoutMethod } = usePartnerProfile();
const {
data: earnings,
@@ -61,106 +62,150 @@ function PayoutDetailsSheetContent({ payout }: PayoutDetailsSheetProps) {
const invoiceData = useMemo(() => {
const statusBadge = PayoutStatusBadges[payout.status];
- return {
- Program: (
- <ConditionalLink
- href={`/programs/${payout.program.slug}`}
- target="_blank"
- >
- <img
- src={
- payout.program.logo || `${OG_AVATAR_URL}${payout.program.name}`
- }
- alt={payout.program.name}
- className="mr-1.5 inline-flex size-4 rounded-sm"
- />
- {payout.program.name}
- </ConditionalLink>
- ),
-
- Period: formatPeriod(payout),
+ return [
+ {
+ key: "Program",
+ value: (
+ <ConditionalLink
+ href={`/programs/${payout.program.slug}`}
+ target="_blank"
+ >
+ <img
+ src={
+ payout.program.logo || `${OG_AVATAR_URL}${payout.program.name}`
+ }
+ alt={payout.program.name}
+ className="mr-1.5 inline-flex size-4 rounded-sm"
+ />
+ {payout.program.name}
+ </ConditionalLink>
+ ),
+ },
+ {
+ key: "Period",
+ value: formatPeriod(payout),
+ },
+ {
+ key: "Amount",
+ value: (
+ <div className="flex items-center gap-2">
+ <strong>{currencyFormatter(payout.amount)}</strong>
- Status: (
- <StatusBadge variant={statusBadge.variant} icon={statusBadge.icon}>
- {statusBadge.label}
- </StatusBadge>
- ),
+ {payout.mode === "external" && (
+ <Tooltip
+ content={
+ payout.status === PayoutStatus.pending
+ ? `This payout will be made externally through your ${payout.program.name} account after approval.`
+ : `This payout was made externally through your ${payout.program.name} account.`
+ }
+ >
+ <CircleArrowRight className="size-3.5 shrink-0 text-neutral-500" />
+ </Tooltip>
+ )}
- Initiated: payout.initiatedAt ? (
- <TimestampTooltip
- timestamp={payout.initiatedAt}
- side="right"
- rows={["local", "utc"]}
- >
- <span className="hover:text-content-emphasis underline decoration-dotted underline-offset-2">
- {formatDateTimeSmart(payout.initiatedAt)}
- </span>
- </TimestampTooltip>
- ) : (
- "-"
- ),
+ {payout.mode === "internal" &&
+ INVOICE_AVAILABLE_PAYOUT_STATUSES.includes(payout.status) && (
+ <Tooltip content="View invoice">
+ <div className="flex h-5 w-5 items-center justify-center rounded-md transition-colors duration-150 hover:border hover:border-neutral-200 hover:bg-neutral-100">
+ <Link
+ href={`/invoices/${payout.id}`}
+ className="text-neutral-700"
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ <InvoiceDollar className="size-4" />
+ </Link>
+ </div>
+ </Tooltip>
+ )}
+ </div>
+ ),
+ },
- Paid: payout.paidAt ? (
- <TimestampTooltip
- timestamp={payout.paidAt}
- side="right"
- rows={["local", "utc"]}
- >
- <span className="hover:text-content-emphasis underline decoration-dotted underline-offset-2">
- {formatDateTimeSmart(payout.paidAt)}
- </span>
- </TimestampTooltip>
- ) : (
- "-"
- ),
+ {
+ key: "Description",
+ value: payout.description || "-",
+ },
- ...(payout.traceId && {
- "Trace ID": (
- <CopyText
- value={payout.traceId}
- className="text-left font-mono text-sm text-neutral-500"
- >
- {payout.traceId}
- </CopyText>
+ {
+ key: "Status",
+ value: (
+ <StatusBadge variant={statusBadge.variant} icon={statusBadge.icon}>
+ {statusBadge.label}
+ </StatusBadge>
),
- }),
-
- Amount: (
- <div className="flex items-center gap-2">
- <strong>{currencyFormatter(payout.amount)}</strong>
+ },
- {payout.mode === "external" && (
- <Tooltip
- content={
- payout.status === PayoutStatus.pending
- ? `This payout will be made externally through your ${payout.program.name} account after approval.`
- : `This payout was made externally through your ${payout.program.name} account.`
- }
- >
- <CircleArrowRight className="size-3.5 shrink-0 text-neutral-500" />
- </Tooltip>
- )}
+ ...(payout.failureReason
+ ? [
+ {
+ key: "Failure reason",
+ value: (
+ <span className="text-red-600">{payout.failureReason}</span>
+ ),
+ tooltip: `Payout failures are usually due to ${payoutMethod === "paypal" ? "incorrect PayPal account configuration" : "invalid bank account details"}. Once you've updated your account, ${
+ payoutMethod === "paypal"
+ ? "you can retry the payout"
+ : "the payout will be retried automatically"
+ }.`,
+ },
+ ]
+ : []),
- {payout.mode === "internal" &&
- INVOICE_AVAILABLE_PAYOUT_STATUSES.includes(payout.status) && (
- <Tooltip content="View invoice">
- <div className="flex h-5 w-5 items-center justify-center rounded-md transition-colors duration-150 hover:border hover:border-neutral-200 hover:bg-neutral-100">
- <Link
- href={`/invoices/${payout.id}`}
- className="text-neutral-700"
- target="_blank"
- rel="noopener noreferrer"
- >
- <InvoiceDollar className="size-4" />
- </Link>
- </div>
- </Tooltip>
- )}
- </div>
- ),
+ {
+ key: "Initiated",
+ value: payout.initiatedAt ? (
+ <TimestampTooltip
+ timestamp={payout.initiatedAt}
+ side="right"
+ rows={["local", "utc"]}
+ >
+ <span className="hover:text-content-emphasis underline decoration-dotted underline-offset-2">
+ {formatDateTimeSmart(payout.initiatedAt)}
+ </span>
+ </TimestampTooltip>
+ ) : (
+ "-"
+ ),
+ tooltip:
+ "Date and time when the payout was initiated by the program. Payouts usually take up to 5 business days to be fully processed.",
+ },
+ {
+ key: "Paid",
+ value: payout.paidAt ? (
+ <TimestampTooltip
+ timestamp={payout.paidAt}
+ side="right"
+ rows={["local", "utc"]}
+ >
+ <span className="hover:text-content-emphasis underline decoration-dotted underline-offset-2">
+ {formatDateTimeSmart(payout.paidAt)}
+ </span>
+ </TimestampTooltip>
+ ) : (
+ "-"
+ ),
+ tooltip:
+ "Date and time when the payout was fully processed by the program and paid to your account.",
+ },
- Description: payout.description || "-",
- };
+ ...(payout.traceId
+ ? [
+ {
+ key: "Trace ID",
+ value: (
+ <CopyText
+ value={payout.traceId}
+ className="text-left font-mono text-sm text-neutral-500"
+ >
+ {payout.traceId}
+ </CopyText>
+ ),
+ tooltip: `Banks can take up to 5 business days to process payouts. If you haven't received your payout${payout.paidAt ? ` by \`${formatDateTimeSmart(addBusinessDays(payout.paidAt, 5))}\`` : ""}, you can contact your bank and provide the following trace ID as reference.`,
+ },
+ ]
+ : []),
+ ];
}, [payout, earnings]);
const table = useTable({
@@ -255,33 +300,21 @@ function PayoutDetailsSheetContent({ payout }: PayoutDetailsSheetProps) {
Invoice details
</div>
<div className="grid grid-cols-2 gap-3 text-sm">
- {Object.entries(invoiceData).map(([key, value]) => (
+ {invoiceData.map(({ key, value, tooltip }) => (
<Fragment key={key}>
- <div className="flex items-center font-medium text-neutral-500">
- {key === "Initiated" ? (
- <Tooltip content="Date and time when the payout was initiated by the program. Payouts usually take up to 5 business days to be fully processed.">
- <span className="cursor-help underline decoration-dotted underline-offset-2">
- {key}
- </span>
- </Tooltip>
- ) : key === "Paid" ? (
- <Tooltip content="Date and time when the payout was fully processed by the program and paid to your account.">
- <span className="cursor-help underline decoration-dotted underline-offset-2">
- {key}
- </span>
- </Tooltip>
- ) : key === "Trace ID" ? (
- <Tooltip
- content={`Banks can take up to 5 business days to process payouts. If you haven't received your payout${payout.paidAt ? ` by \`${formatDateTimeSmart(addBusinessDays(payout.paidAt, 5))}\`` : ""}, you can contact your bank and provide the following trace ID as reference.`}
- >
- <span className="cursor-help underline decoration-dotted underline-offset-2">
- {key}
- </span>
- </Tooltip>
- ) : (
- key
- )}
- </div>
+ <DynamicTooltipWrapper
+ tooltipProps={tooltip ? { content: tooltip } : undefined}
+ >
+ <div
+ className={cn(
+ "flex items-center font-medium text-neutral-500",
+ tooltip &&
+ "cursor-help underline decoration-dotted underline-offset-2",
+ )}
+ >
+ {key}
+ </div>
+ </DynamicTooltipWrapper>
<div className="text-neutral-800">{value}</div>
</Fragment>
))}
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 03966fb574..3499d4c743 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
@@ -15,12 +15,7 @@ import { PAYOUT_STATUS_DESCRIPTIONS } from "@/ui/partners/payout-status-descript
import { AlertCircleFill } from "@/ui/shared/icons";
import { PayoutStatus } from "@dub/prisma/client";
import { Button, Tooltip } from "@dub/ui";
-import {
- cn,
- CONNECT_SUPPORTED_COUNTRIES,
- currencyFormatter,
- PAYPAL_SUPPORTED_COUNTRIES,
-} from "@dub/utils";
+import { cn, currencyFormatter } from "@dub/utils";
import { HelpCircle } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
import { toast } from "sonner";
@@ -117,7 +112,7 @@ function PayoutStatsCard({
}
export function PayoutStats() {
- const { partner } = usePartnerProfile();
+ const { payoutMethod } = usePartnerProfile();
const { payoutsCount, error } = usePartnerPayoutsCount<PayoutsCount[]>({
groupBy: "status",
@@ -127,16 +122,6 @@ export function PayoutStats() {
payoutsCount?.map((p) => [p.status, p]) || [],
) as Record<PayoutStatus, PayoutsCount>;
- let payoutMethod: "stripe" | "paypal" | undefined = undefined;
-
- 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
? PAYOUT_STATUS_DESCRIPTIONS[payoutMethod]
: undefined;
diff --git a/apps/web/lib/swr/use-partner-profile.ts b/apps/web/lib/swr/use-partner-profile.ts
index 87f848e94f..de6867e6ba 100644
--- a/apps/web/lib/swr/use-partner-profile.ts
+++ b/apps/web/lib/swr/use-partner-profile.ts
@@ -1,4 +1,8 @@
-import { fetcher } from "@dub/utils";
+import {
+ CONNECT_SUPPORTED_COUNTRIES,
+ fetcher,
+ PAYPAL_SUPPORTED_COUNTRIES,
+} from "@dub/utils";
import { useSession } from "next-auth/react";
import useSWR from "swr";
import { PartnerProps } from "../types";
@@ -23,6 +27,13 @@ export default function usePartnerProfile() {
return {
partner,
+ payoutMethod: partner?.country
+ ? partner.country in PAYPAL_SUPPORTED_COUNTRIES
+ ? "paypal"
+ : partner.country in CONNECT_SUPPORTED_COUNTRIES
+ ? "stripe"
+ : undefined
+ : undefined,
error,
loading: status === "loading" || isLoading,
mutate,
diff --git a/apps/web/ui/partners/connect-payout-button.tsx b/apps/web/ui/partners/connect-payout-button.tsx
index 4fdcb52de2..644f09861e 100644
--- a/apps/web/ui/partners/connect-payout-button.tsx
+++ b/apps/web/ui/partners/connect-payout-button.tsx
@@ -5,11 +5,7 @@ import { generateStripeAccountLink } from "@/lib/actions/partners/generate-strip
import { hasPermission } from "@/lib/auth/partner-users/partner-user-permissions";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import { Button, ButtonProps, TooltipContent } from "@dub/ui";
-import {
- CONNECT_SUPPORTED_COUNTRIES,
- COUNTRIES,
- PAYPAL_SUPPORTED_COUNTRIES,
-} from "@dub/utils";
+import { COUNTRIES } from "@dub/utils";
import { useAction } from "next-safe-action/hooks";
import { useRouter } from "next/navigation";
import { useCallback, useMemo } from "react";
@@ -17,7 +13,7 @@ import { toast } from "sonner";
export function ConnectPayoutButton(props: ButtonProps) {
const router = useRouter();
- const { partner } = usePartnerProfile();
+ const { partner, payoutMethod } = usePartnerProfile();
const { executeAsync: executeStripeAsync, isPending: isStripePending } =
useAction(generateStripeAccountLink, {
@@ -60,9 +56,9 @@ export function ConnectPayoutButton(props: ButtonProps) {
return;
}
- if (PAYPAL_SUPPORTED_COUNTRIES.includes(partner.country)) {
+ if (payoutMethod === "paypal") {
await executePaypalAsync();
- } else if (CONNECT_SUPPORTED_COUNTRIES.includes(partner.country)) {
+ } else if (payoutMethod === "stripe") {
await executeStripeAsync();
} else {
toast.error(
@@ -70,16 +66,13 @@ export function ConnectPayoutButton(props: ButtonProps) {
);
return;
}
- }, [executeStripeAsync, executePaypalAsync, partner]);
+ }, [executeStripeAsync, executePaypalAsync, partner, payoutMethod]);
const errorMessage = useMemo(
() =>
!partner?.country
? "You haven't set your country yet. Please update your country or contact support."
- : ![
- ...CONNECT_SUPPORTED_COUNTRIES,
- ...PAYPAL_SUPPORTED_COUNTRIES,
- ].includes(partner.country)
+ : !payoutMethod
? `Your current country (${COUNTRIES[partner.country]}) is not supported for payout. Please update your country or contact support.`
: undefined,
[partner?.country],
@@ -94,9 +87,7 @@ export function ConnectPayoutButton(props: ButtonProps) {
onClick={onClick}
loading={isStripePending || isPaypalPending}
text={
- partner?.country && PAYPAL_SUPPORTED_COUNTRIES.includes(partner.country)
- ? "Connect PayPal"
- : "Connect bank account"
+ payoutMethod === "paypal" ? "Connect PayPal" : "Connect bank account"
}
disabledTooltip={
errorMessage && (
diff --git a/apps/web/ui/partners/payout-methods-dropdown.tsx b/apps/web/ui/partners/payout-methods-dropdown.tsx
index 4d4c324240..a090d7ee55 100644
--- a/apps/web/ui/partners/payout-methods-dropdown.tsx
+++ b/apps/web/ui/partners/payout-methods-dropdown.tsx
@@ -5,12 +5,7 @@ import { generateStripeAccountLink } from "@/lib/actions/partners/generate-strip
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import { PartnerProps } from "@/lib/types";
import { Button, MatrixLines, Paypal, Popover, StripeIcon } from "@dub/ui";
-import {
- cn,
- CONNECT_SUPPORTED_COUNTRIES,
- fetcher,
- PAYPAL_SUPPORTED_COUNTRIES,
-} from "@dub/utils";
+import { cn, fetcher } from "@dub/utils";
import { ChevronsUpDown } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
import { useRouter } from "next/navigation";
@@ -22,7 +17,11 @@ import useSWR from "swr";
export function PayoutMethodsDropdown() {
const router = useRouter();
const [openPopover, setOpenPopover] = useState(false);
- const { partner, loading: isPartnerLoading } = usePartnerProfile();
+ const {
+ partner,
+ payoutMethod,
+ loading: isPartnerLoading,
+ } = usePartnerProfile();
const { data: bankAccount, isLoading: isBankAccountLoading } =
useSWR<Stripe.BankAccount>(
@@ -73,9 +72,7 @@ export function PayoutMethodsDropdown() {
? `Account ${partner.paypalEmail}`
: "Not connected",
isVisible: (partner: Pick<PartnerProps, "country" | "paypalEmail">) =>
- (partner.country &&
- PAYPAL_SUPPORTED_COUNTRIES.includes(partner.country)) ||
- partner.paypalEmail,
+ payoutMethod === "paypal" || partner.paypalEmail,
},
{
id: "stripe",
@@ -97,9 +94,7 @@ export function PayoutMethodsDropdown() {
);
},
isVisible: (partner: Pick<PartnerProps, "country" | "stripeConnectId">) =>
- (partner.country &&
- CONNECT_SUPPORTED_COUNTRIES.includes(partner.country)) ||
- partner.stripeConnectId,
+ payoutMethod === "stripe" || partner.stripeConnectId,
},
];
diff --git a/apps/web/ui/partners/payout-row-menu.tsx b/apps/web/ui/partners/payout-row-menu.tsx
index 2f847b9fe6..376f269dce 100644
--- a/apps/web/ui/partners/payout-row-menu.tsx
+++ b/apps/web/ui/partners/payout-row-menu.tsx
@@ -4,7 +4,7 @@ import { PartnerPayoutResponse } from "@/lib/types";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
import { Button, Icon, Popover } from "@dub/ui";
import { Dots, Refresh2 } from "@dub/ui/icons";
-import { cn, PAYPAL_SUPPORTED_COUNTRIES } from "@dub/utils";
+import { cn } from "@dub/utils";
import { Row } from "@tanstack/react-table";
import { Command } from "cmdk";
import { useAction } from "next-safe-action/hooks";
@@ -12,7 +12,7 @@ import { useState } from "react";
import { toast } from "sonner";
export function PayoutRowMenu({ row }: { row: Row<PartnerPayoutResponse> }) {
- const { partner } = usePartnerProfile();
+ const { payoutMethod } = usePartnerProfile();
const [isOpen, setIsOpen] = useState(false);
const { executeAsync: executeRetryPayout, isPending: isRetryPayoutPending } =
@@ -42,9 +42,7 @@ export function PayoutRowMenu({ row }: { row: Row<PartnerPayoutResponse> }) {
});
const canRetry =
- row.original.status === "failed" &&
- partner?.country &&
- PAYPAL_SUPPORTED_COUNTRIES.includes(partner.country);
+ row.original.status === "failed" && payoutMethod === "paypal";
if (!canRetry) {
return null;
diff --git a/apps/web/ui/partners/program-card.tsx b/apps/web/ui/partners/program-card.tsx
index 2619075d98..0c310462e1 100644
--- a/apps/web/ui/partners/program-card.tsx
+++ b/apps/web/ui/partners/program-card.tsx
@@ -5,6 +5,7 @@ import { BlurImage, Link4, MiniAreaChart } from "@dub/ui";
import { formatDate, getPrettyUrl, OG_AVATAR_URL } from "@dub/utils";
import NumberFlow from "@number-flow/react";
import Link from "next/link";
+import { useRouter } from "next/navigation";
import { useMemo } from "react";
export function ProgramCard({
@@ -12,6 +13,7 @@ export function ProgramCard({
}: {
programEnrollment: ProgramEnrollmentProps;
}) {
+ const router = useRouter();
const { program, status, createdAt, group } = programEnrollment;
const defaultLink = programEnrollment.links?.[0];
@@ -64,12 +66,16 @@ export function ProgramCard({
) : statusDescription ? (
<p>
{statusDescription}{" "}
- <Link
- href={`/messages/${program.slug}`}
+ <button
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ router.push(`/messages/${program.slug}`);
+ }}
className="text-neutral-400 underline decoration-dotted underline-offset-2 hover:text-neutral-700"
>
Reach out to the {program.name} team
- </Link>{" "}
+ </button>{" "}
if you have any questions.
</p>
) : null}