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.

wip

Kiran Kaa5851ee23b0
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-methods.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-methods.tsx
index f9f33ddff8..2b047ccd03 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-methods.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/payment-methods.tsx
@@ -2,8 +2,9 @@
import usePaymentMethods from "@/lib/swr/use-payment-methods";
import useWorkspace from "@/lib/swr/use-workspace";
+import { useAddPayoutMethodModal } from "@/ui/modals/add-payout-method-modal";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
-import { Badge, Button, CreditCard, MoneyBill2 } from "@dub/ui";
+import { Badge, Button, CreditCard, GreekTemple, MoneyBill2 } from "@dub/ui";
import { cn } from "@dub/utils";
import Link from "next/link";
import { useRouter } from "next/navigation";
@@ -91,6 +92,7 @@ export default function PaymentMethods() {
<PaymentMethodCardSkeleton />
</>
)}
+
{partnersEnabled && (
<>
{achPaymentMethods && achPaymentMethods.length > 0 ? (
@@ -99,10 +101,11 @@ export default function PaymentMethods() {
key={paymentMethod.id}
type={paymentMethod.type}
paymentMethod={paymentMethod}
+ forPayouts={true}
/>
))
) : (
- <PaymentMethodCard type="us_bank_account" />
+ <PaymentMethodCard forPayouts={true} />
)}
</>
)}
@@ -114,13 +117,17 @@ export default function PaymentMethods() {
const PaymentMethodCard = ({
type,
paymentMethod,
+ forPayouts = false,
}: {
- type: Stripe.PaymentMethod.Type;
+ type?: Stripe.PaymentMethod.Type;
paymentMethod?: Stripe.PaymentMethod;
+ forPayouts?: boolean;
}) => {
const router = useRouter();
const { slug } = useWorkspace();
const [isLoading, setIsLoading] = useState(false);
+ const { setShowAddPayoutMethodModal, AddPayoutMethodModal } =
+ useAddPayoutMethodModal();
const result = PaymentMethodTypesList(paymentMethod);
@@ -129,7 +136,11 @@ const PaymentMethodCard = ({
icon: Icon,
iconBgColor,
description,
- } = result.find((method) => method.type === type) || result[0];
+ } = result.find((method) => method.type === type) || {
+ title: "Bank account",
+ icon: GreekTemple,
+ description: "Not connected",
+ };
const addPaymentMethod = async (method: string) => {
setIsLoading(true);
@@ -145,41 +156,45 @@ const PaymentMethodCard = ({
};
return (
- <RecommendedForPayoutsWrapper recommended={type === "us_bank_account"}>
- <div className="flex items-center justify-between rounded-lg border border-neutral-200 bg-white p-4 drop-shadow-sm">
- <div className="flex items-center gap-4">
- <div
- className={cn(
- "flex size-12 items-center justify-center rounded-lg bg-neutral-100",
- iconBgColor,
- )}
- >
- <Icon className="size-6 text-neutral-700" />
- </div>
- <div>
- <div className="flex items-center gap-2">
- <p className="font-medium text-neutral-900">{title}</p>
- {paymentMethod &&
- (type === "us_bank_account" || paymentMethod.link?.email) && (
- <Badge className="border-transparent bg-green-200 text-[0.625rem] text-green-900">
- Connected
- </Badge>
- )}
+ <>
+ {AddPayoutMethodModal}
+ <RecommendedForPayoutsWrapper recommended={forPayouts}>
+ <div className="flex items-center justify-between rounded-lg border border-neutral-200 bg-white p-4 drop-shadow-sm">
+ <div className="flex items-center gap-4">
+ <div
+ className={cn(
+ "flex size-12 items-center justify-center rounded-lg bg-neutral-100",
+ iconBgColor,
+ )}
+ >
+ <Icon className="size-6 text-neutral-700" />
+ </div>
+ <div>
+ <div className="flex items-center gap-2">
+ <p className="font-medium text-neutral-900">{title}</p>
+ {paymentMethod &&
+ (type === "us_bank_account" || paymentMethod.link?.email) && (
+ <Badge className="border-transparent bg-green-200 text-[0.625rem] text-green-900">
+ Connected
+ </Badge>
+ )}
+ </div>
+ <p className="text-sm text-neutral-500">{description}</p>
</div>
- <p className="text-sm text-neutral-500">{description}</p>
</div>
+
+ {!paymentMethod && (
+ <Button
+ variant="primary"
+ className="h-9 w-fit"
+ text="Connect"
+ onClick={() => setShowAddPayoutMethodModal(true)}
+ loading={isLoading}
+ />
+ )}
</div>
- {!paymentMethod && (
- <Button
- variant="primary"
- className="h-9 w-fit"
- text="Connect"
- onClick={() => addPaymentMethod(type)}
- loading={isLoading}
- />
- )}
- </div>
- </RecommendedForPayoutsWrapper>
+ </RecommendedForPayoutsWrapper>
+ </>
);
};
diff --git a/apps/web/ui/modals/add-payout-method-modal.tsx b/apps/web/ui/modals/add-payout-method-modal.tsx
new file mode 100644
index 0000000000..45ae689c7f
--- /dev/null
+++ b/apps/web/ui/modals/add-payout-method-modal.tsx
@@ -0,0 +1,132 @@
+"use client";
+
+import { X } from "@/ui/shared/icons";
+import { AnimatedSizeContainer, GreekTemple, Modal, Stripe } from "@dub/ui";
+import { CSSProperties, Dispatch, SetStateAction, useState } from "react";
+
+const PAYMENT_PROCESSORS = [
+ {
+ id: "us_bank_account",
+ location: "US",
+ method: "ACH",
+ icon: Stripe,
+ },
+ {
+ id: "acss_debit",
+ location: "CA",
+ method: "ACSS Debit",
+ icon: Stripe,
+ },
+ {
+ id: "sepa_debit",
+ location: "EU",
+ method: "SEPA Debit",
+ icon: Stripe,
+ },
+ {
+ id: "au_becs_debit",
+ location: "AUS",
+ method: "AU BECS Debit",
+ icon: Stripe,
+ },
+];
+
+function AddPayoutMethodModal({
+ showAddPayoutMethodModal,
+ setShowAddPayoutMethodModal,
+}: {
+ showAddPayoutMethodModal: boolean;
+ setShowAddPayoutMethodModal: Dispatch<SetStateAction<boolean>>;
+}) {
+ return (
+ <Modal
+ showModal={showAddPayoutMethodModal}
+ setShowModal={setShowAddPayoutMethodModal}
+ className="max-h-[calc(100dvh-100px)] max-w-xl"
+ >
+ <AddPayoutMethodModalInner
+ setShowAddPayoutMethodModal={setShowAddPayoutMethodModal}
+ />
+ </Modal>
+ );
+}
+
+function AddPayoutMethodModalInner({
+ setShowAddPayoutMethodModal,
+}: {
+ setShowAddPayoutMethodModal: Dispatch<SetStateAction<boolean>>;
+}) {
+ const [paymentProcessorIndex, setPaymentProcessorIndex] = useState<
+ number | null
+ >(null);
+
+ return (
+ <AnimatedSizeContainer
+ height
+ transition={{ duration: 0.1, ease: "easeInOut" }}
+ >
+ <div className="p-4 sm:p-8">
+ <button
+ type="button"
+ onClick={() => setShowAddPayoutMethodModal(false)}
+ className="group absolute right-4 top-4 z-[1] hidden rounded-full p-2 text-neutral-500 transition-all duration-75 hover:bg-neutral-100 focus:outline-none active:bg-neutral-200 md:block"
+ >
+ <X className="size-5" />
+ </button>
+
+ <div>
+ <div className="flex size-12 items-center justify-center rounded-full border border-neutral-200 text-neutral-900">
+ <GreekTemple className="size-8 [&_*]:stroke-1 [&_circle]:hidden" />
+ </div>
+ <h3 className="mt-6 text-lg font-semibold text-neutral-800">
+ Connect your bank account
+ </h3>
+ <p className="mt-2 text-base text-neutral-500">
+ Select your bank’s location to
+ </p>
+ <div
+ className="mt-6 grid grid-cols-2 gap-4 sm:grid-cols-[repeat(var(--cols),minmax(0,1fr))]"
+ style={
+ {
+ "--cols": PAYMENT_PROCESSORS.length,
+ } as CSSProperties
+ }
+ >
+ {PAYMENT_PROCESSORS.map(
+ ({ icon: Icon, name, shortName }, index) => (
+ <button
+ key={index}
+ type="button"
+ className="group flex flex-col items-center rounded-lg bg-neutral-200/40 p-8 pb-6 transition-colors duration-100 hover:bg-neutral-200/60"
+ onClick={() => {
+ setPaymentProcessorIndex(index);
+ }}
+ >
+ <Icon className="h-11 transition-transform duration-100 group-hover:-translate-y-0.5" />
+ <span className="mt-3 text-center text-sm font-medium text-neutral-700 sm:mt-8">
+ {shortName || name}
+ </span>
+ </button>
+ ),
+ )}
+ </div>
+ </div>
+ </div>
+ </AnimatedSizeContainer>
+ );
+}
+
+export function useAddPayoutMethodModal() {
+ const [showAddPayoutMethodModal, setShowAddPayoutMethodModal] =
+ useState(false);
+
+ return {
+ setShowAddPayoutMethodModal,
+ AddPayoutMethodModal: (
+ <AddPayoutMethodModal
+ showAddPayoutMethodModal={showAddPayoutMethodModal}
+ setShowAddPayoutMethodModal={setShowAddPayoutMethodModal}
+ />
+ ),
+ };
+}