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.

rename

Kiran Kd0e1853721e4
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts
index b6f435f11d..e807c675ba 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts
@@ -1,15 +1,14 @@
import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
+import { PARTNER_PAYOUT_METHODS } from "@/lib/payment-methods";
import { stripe } from "@/lib/stripe";
import { APP_DOMAIN } from "@dub/utils";
import { NextResponse } from "next/server";
import { z } from "zod";
const addPaymentMethodSchema = z.object({
- method: z
- .enum(["card", "us_bank_account", "acss_debit", "sepa_debit"])
- .optional(),
+ method: z.enum(["card", ...PARTNER_PAYOUT_METHODS]).optional(),
});
const stripePaymentMethodOptions = {
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 ae04bbee07..fa4b8abccb 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
@@ -1,8 +1,12 @@
"use client";
+import {
+ PARTNER_PAYOUT_METHOD,
+ PARTNER_PAYOUT_METHODS,
+} from "@/lib/payment-methods";
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 { useAddPaymentMethodModal } from "@/ui/modals/add-payment-method-modal";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { Badge, Button, CreditCard, GreekTemple, MoneyBill2 } from "@dub/ui";
import { cn } from "@dub/utils";
@@ -12,8 +16,6 @@ import { useState } from "react";
import { Stripe } from "stripe";
import { PaymentMethodTypesList } from "./payment-method-types";
-const PARTNER_PAYMENT_METHODS = ["us_bank_account", "acss_debit", "sepa_debit"];
-
export default function PaymentMethods() {
const router = useRouter();
const { paymentMethods } = usePaymentMethods();
@@ -21,11 +23,11 @@ export default function PaymentMethods() {
const { slug, stripeId, partnersEnabled, plan } = useWorkspace();
const regularPaymentMethods = paymentMethods?.filter(
- (pm) => !PARTNER_PAYMENT_METHODS.includes(pm.type),
+ (pm) => !PARTNER_PAYOUT_METHODS.includes(pm.type as PARTNER_PAYOUT_METHOD),
);
const partnerPaymentMethods = paymentMethods?.filter((pm) =>
- PARTNER_PAYMENT_METHODS.includes(pm.type),
+ PARTNER_PAYOUT_METHODS.includes(pm.type as PARTNER_PAYOUT_METHOD),
);
const managePaymentMethods = async () => {
@@ -125,9 +127,6 @@ const PaymentMethodCard = ({
paymentMethod?: Stripe.PaymentMethod;
forPayouts?: boolean;
}) => {
- const { setShowAddPayoutMethodModal, AddPayoutMethodModal } =
- useAddPayoutMethodModal();
-
const result = PaymentMethodTypesList(paymentMethod);
const {
@@ -139,7 +138,6 @@ const PaymentMethodCard = ({
return (
<>
- {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">
@@ -155,7 +153,9 @@ const PaymentMethodCard = ({
<div className="flex items-center gap-2">
<p className="font-medium text-neutral-900">{title}</p>
{paymentMethod &&
- (PARTNER_PAYMENT_METHODS.includes(type ?? "") ||
+ (PARTNER_PAYOUT_METHODS.includes(
+ type as (typeof PARTNER_PAYOUT_METHODS)[number],
+ ) ||
paymentMethod.link?.email) && (
<Badge className="border-transparent bg-green-200 text-[0.625rem] text-green-900">
Connected
@@ -165,15 +165,6 @@ const PaymentMethodCard = ({
<p className="text-sm text-neutral-500">{description}</p>
</div>
</div>
-
- {!paymentMethod && (
- <Button
- variant="primary"
- className="h-9 w-fit"
- text="Connect"
- onClick={() => setShowAddPayoutMethodModal(true)}
- />
- )}
</div>
</RecommendedForPayoutsWrapper>
</>
@@ -181,12 +172,12 @@ const PaymentMethodCard = ({
};
const NoPartnerPaymentMethods = () => {
- const { setShowAddPayoutMethodModal, AddPayoutMethodModal } =
- useAddPayoutMethodModal();
+ const { setShowAddPaymentMethodModal, AddPaymentMethodModal } =
+ useAddPaymentMethodModal();
return (
<>
- {AddPayoutMethodModal}
+ {AddPaymentMethodModal}
<RecommendedForPayoutsWrapper recommended={true}>
<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">
@@ -210,7 +201,7 @@ const NoPartnerPaymentMethods = () => {
variant="primary"
className="h-9 w-fit"
text="Connect"
- onClick={() => setShowAddPayoutMethodModal(true)}
+ onClick={() => setShowAddPaymentMethodModal(true)}
/>
</div>
</RecommendedForPayoutsWrapper>
diff --git a/apps/web/lib/payment-methods.ts b/apps/web/lib/payment-methods.ts
new file mode 100644
index 0000000000..67d006919b
--- /dev/null
+++ b/apps/web/lib/payment-methods.ts
@@ -0,0 +1,7 @@
+export const PARTNER_PAYOUT_METHODS = [
+ "us_bank_account",
+ "acss_debit",
+ "sepa_debit",
+] as const;
+
+export type PARTNER_PAYOUT_METHOD = (typeof PARTNER_PAYOUT_METHODS)[number];
diff --git a/apps/web/ui/modals/add-payout-method-modal.tsx b/apps/web/ui/modals/add-payment-method-modal.tsx
similarity index 76%
rename from apps/web/ui/modals/add-payout-method-modal.tsx
rename to apps/web/ui/modals/add-payment-method-modal.tsx
index 49b13d552d..4d30c11c1f 100644
--- a/apps/web/ui/modals/add-payout-method-modal.tsx
+++ b/apps/web/ui/modals/add-payment-method-modal.tsx
@@ -1,5 +1,6 @@
"use client";
+import { PARTNER_PAYOUT_METHOD } from "@/lib/payment-methods";
import useWorkspace from "@/lib/swr/use-workspace";
import { X } from "@/ui/shared/icons";
import { AnimatedSizeContainer, GreekTemple, Modal } from "@dub/ui";
@@ -7,14 +8,8 @@ import { useRouter } from "next/navigation";
import { CSSProperties, Dispatch, SetStateAction, useState } from "react";
import { toast } from "sonner";
-type PaymentMethods =
- | "us_bank_account"
- | "acss_debit"
- | "sepa_debit"
- | "au_becs_debit";
-
const PAYMENT_METHODS: {
- id: PaymentMethods;
+ id: PARTNER_PAYOUT_METHOD;
location: string;
method: string;
icon: string;
@@ -37,44 +32,38 @@ const PAYMENT_METHODS: {
method: "SEPA Debit",
icon: "https://flag.vercel.app/m/US.svg", // TODO: update the flag icon
},
- // {
- // id: "au_becs_debit",
- // location: "AUS",
- // method: "AU BECS Debit",
- // icon: "https://flag.vercel.app/m/AU.svg",
- // },
];
-function AddPayoutMethodModal({
- showAddPayoutMethodModal,
- setShowAddPayoutMethodModal,
+function AddPaymentMethodModal({
+ showAddPaymentMethodModal,
+ setShowAddPaymentMethodModal,
}: {
- showAddPayoutMethodModal: boolean;
- setShowAddPayoutMethodModal: Dispatch<SetStateAction<boolean>>;
+ showAddPaymentMethodModal: boolean;
+ setShowAddPaymentMethodModal: Dispatch<SetStateAction<boolean>>;
}) {
return (
<Modal
- showModal={showAddPayoutMethodModal}
- setShowModal={setShowAddPayoutMethodModal}
+ showModal={showAddPaymentMethodModal}
+ setShowModal={setShowAddPaymentMethodModal}
className="max-h-[calc(100dvh-100px)] max-w-xl"
>
- <AddPayoutMethodModalInner
- setShowAddPayoutMethodModal={setShowAddPayoutMethodModal}
+ <AddPaymentMethodModalInner
+ setShowAddPaymentMethodModal={setShowAddPaymentMethodModal}
/>
</Modal>
);
}
-function AddPayoutMethodModalInner({
- setShowAddPayoutMethodModal,
+function AddPaymentMethodModalInner({
+ setShowAddPaymentMethodModal,
}: {
- setShowAddPayoutMethodModal: Dispatch<SetStateAction<boolean>>;
+ setShowAddPaymentMethodModal: Dispatch<SetStateAction<boolean>>;
}) {
const router = useRouter();
const { slug } = useWorkspace();
const [isLoading, setIsLoading] = useState(false);
- const addPaymentMethod = async (method: PaymentMethods) => {
+ const addPaymentMethod = async (method: PARTNER_PAYOUT_METHOD) => {
setIsLoading(true);
const response = await fetch(
@@ -104,7 +93,7 @@ function AddPayoutMethodModalInner({
<div className="p-4 sm:p-8">
<button
type="button"
- onClick={() => setShowAddPayoutMethodModal(false)}
+ onClick={() => setShowAddPaymentMethodModal(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" />
@@ -164,16 +153,16 @@ function AddPayoutMethodModalInner({
);
}
-export function useAddPayoutMethodModal() {
- const [showAddPayoutMethodModal, setShowAddPayoutMethodModal] =
+export function useAddPaymentMethodModal() {
+ const [showAddPaymentMethodModal, setShowAddPaymentMethodModal] =
useState(false);
return {
- setShowAddPayoutMethodModal,
- AddPayoutMethodModal: (
- <AddPayoutMethodModal
- showAddPayoutMethodModal={showAddPayoutMethodModal}
- setShowAddPayoutMethodModal={setShowAddPayoutMethodModal}
+ setShowAddPaymentMethodModal,
+ AddPaymentMethodModal: (
+ <AddPaymentMethodModal
+ showAddPaymentMethodModal={showAddPaymentMethodModal}
+ setShowAddPaymentMethodModal={setShowAddPaymentMethodModal}
/>
),
};