Skip to content

Commit

Permalink
fix flow
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Jan 26, 2025
1 parent 81ee24b commit fa6a7ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import usePaymentMethods from "@/lib/swr/use-payment-methods";
import useWorkspace from "@/lib/swr/use-workspace";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import ManageSubscriptionButton from "@/ui/workspaces/manage-subscription-button";
import { Badge, Button, CreditCard } from "@dub/ui";
import { cn } from "@dub/utils";
import { useState } from "react";
import { Stripe } from "stripe";
import { PaymentMethodTypesList } from "./payment-method-types";

export default function PaymentMethods() {
const { stripeId, partnersEnabled } = useWorkspace();
const { slug, stripeId, partnersEnabled } = useWorkspace();
const { paymentMethods } = usePaymentMethods();

const regularPaymentMethods = paymentMethods?.filter(
Expand All @@ -22,6 +21,22 @@ export default function PaymentMethods() {
(pm) => pm.type === "us_bank_account",
);

const [isLoading, setIsLoading] = useState(false);

const managePaymentMethods = async (method?: string) => {
setIsLoading(true);
const { url } = await fetch(
`/api/workspaces/${slug}/billing/payment-methods`,
{
method: "POST",
body: JSON.stringify({ method }),
},
).then((res) => res.json());

window.open(url, "_blank");
setIsLoading(false);
};

return (
<div className="rounded-lg border border-neutral-200 bg-white">
<div className="flex flex-col items-start justify-between gap-y-4 p-6 md:flex-row md:items-center md:p-8">
Expand All @@ -32,7 +47,13 @@ export default function PaymentMethods() {
</p>
</div>
{stripeId && (
<ManageSubscriptionButton text="Manage" className="w-fit" />
<Button
variant="secondary"
text="Manage"
className="h-9 w-fit"
onClick={() => managePaymentMethods()}
loading={isLoading}
/>
)}
</div>
<div className="grid gap-4 border-t border-neutral-200 p-6">
Expand Down Expand Up @@ -143,7 +164,7 @@ const PaymentMethodCard = ({
{!paymentMethod && (
<Button
variant="primary"
className="h-8 w-fit"
className="h-9 w-fit"
text="Connect"
onClick={() => managePaymentMethods(type)}
loading={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function PlanUsage() {
href={`/${slug}/settings/billing/invoices`}
className={cn(
buttonVariants({ variant: "secondary" }),
"flex h-8 w-full items-center justify-center rounded-md border px-4 text-sm",
"flex h-9 w-full items-center justify-center rounded-md border px-4 text-sm",
)}
>
View invoices
Expand Down Expand Up @@ -165,7 +165,7 @@ export default function PlanUsage() {
href={`/${slug}/upgrade`}
className={cn(
buttonVariants(),
"flex h-8 w-fit items-center justify-center rounded-md border px-3 text-sm",
"flex h-9 w-fit items-center justify-center rounded-md border px-3 text-sm",
)}
>
Upgrade to {nextPlan.name}
Expand Down

0 comments on commit fa6a7ce

Please sign in to comment.