The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: payment method preselection
Kevin Grüneberg35e650d80f5d
diff --git a/studio/components/interfaces/BillingV2/Subscription/CostControl/SpendCapSidePanel.tsx b/studio/components/interfaces/BillingV2/Subscription/CostControl/SpendCapSidePanel.tsxindex e42e2863d17..74fccb42c8d 100644--- a/studio/components/interfaces/BillingV2/Subscription/CostControl/SpendCapSidePanel.tsx+++ b/studio/components/interfaces/BillingV2/Subscription/CostControl/SpendCapSidePanel.tsx@@ -163,7 +163,7 @@ const SpendCapSidePanel = () => {</Table.tr>{usageItems.map((item: any) => {return (- <Table.tr key={item.name}>+ <Table.tr key={item.title}><Table.td><p className="text-xs pl-4">{item.title}</p></Table.td>diff --git a/studio/components/interfaces/BillingV2/Subscription/Tier/PaymentMethodSelection.tsx b/studio/components/interfaces/BillingV2/Subscription/Tier/PaymentMethodSelection.tsxindex f0008936b6a..bf3fe25b8de 100644--- a/studio/components/interfaces/BillingV2/Subscription/Tier/PaymentMethodSelection.tsx+++ b/studio/components/interfaces/BillingV2/Subscription/Tier/PaymentMethodSelection.tsx@@ -6,7 +6,7 @@ import { useOrganizationPaymentMethodsQuery } from 'data/organizations/organizatimport { checkPermissions, useStore } from 'hooks'import { BASE_PATH } from 'lib/constants'import { getURL } from 'lib/helpers'-import { useEffect, useState } from 'react'+import { useEffect, useMemo, useState } from 'react'import { Button, IconAlertCircle, IconCreditCard, IconLoader, IconPlus, Listbox } from 'ui'import AddNewPaymentMethodModal from './AddNewPaymentMethodModal'@@ -30,7 +30,7 @@ const PaymentMethodSelection = ({isSuccess: loadedPaymentMethods,refetch: refetchPaymentMethods,} = useOrganizationPaymentMethodsQuery({ slug })- const paymentMethods = data ?? []+ const paymentMethods = useMemo(() => data ?? [], [data])const { data: customerProfile, isSuccess: loadedCustomerProfile } =useOrganizationCustomerProfileQuery({ slug })@@ -42,16 +42,29 @@ const PaymentMethodSelection = ({useEffect(() => {if (loadedPaymentMethods && loadedCustomerProfile && paymentMethods.length > 0) {- const defaultPaymentMethod = paymentMethods.find(- (method) => method.id === customerProfile.invoice_settings.default_payment_method+ const selectedPaymentMethodExists = paymentMethods.some(+ (it) => it.id === selectedPaymentMethod)- if (defaultPaymentMethod !== undefined) {- onSelectPaymentMethod(defaultPaymentMethod.id)- } else {- onSelectPaymentMethod(paymentMethods[0].id)++ if (!selectedPaymentMethod || !selectedPaymentMethodExists) {+ const defaultPaymentMethod = paymentMethods.find(+ (method) => method.id === customerProfile.invoice_settings.default_payment_method+ )+ if (defaultPaymentMethod !== undefined) {+ onSelectPaymentMethod(defaultPaymentMethod.id)+ } else {+ onSelectPaymentMethod(paymentMethods[0].id)+ }}}- }, [loadedPaymentMethods, loadedCustomerProfile])+ }, [+ loadedPaymentMethods,+ loadedCustomerProfile,+ selectedPaymentMethod,+ customerProfile,+ paymentMethods,+ onSelectPaymentMethod,+ ])return (<>@@ -112,6 +125,7 @@ const PaymentMethodSelection = ({addOnBefore={() => {return (<img+ alt="Credit Card Brand"src={`${BASE_PATH}/img/payment-methods/${method.card.brand.replace(' ', '-').toLowerCase()}.png`}@@ -148,8 +162,13 @@ const PaymentMethodSelection = ({message: 'Successfully added new payment method',})const { data } = await refetchPaymentMethods()- if (!selectedPaymentMethod && data?.length) {- onSelectPaymentMethod(data[0].id)+ if (data?.length) {+ // Preselect the card that was just added+ const mostRecentPaymentMethod = data.reduce(+ (prev, current) => (prev.created > current.created ? prev : current),+ data[0]+ )+ onSelectPaymentMethod(mostRecentPaymentMethod.id)}}}/>diff --git a/studio/components/interfaces/BillingV2/Subscription/Tier/SubscriptionPaymentMethod.tsx b/studio/components/interfaces/BillingV2/Subscription/Tier/SubscriptionPaymentMethod.tsxindex 6e3b269fc57..8616af8b062 100644--- a/studio/components/interfaces/BillingV2/Subscription/Tier/SubscriptionPaymentMethod.tsx+++ b/studio/components/interfaces/BillingV2/Subscription/Tier/SubscriptionPaymentMethod.tsx@@ -12,6 +12,7 @@ import {import { checkPermissions, useStore } from 'hooks'import { BASE_PATH } from 'lib/constants'import { PermissionAction } from '@supabase/shared-types/out/constants'+import Link from 'next/link'export interface SubscriptionTierProps {subscription: ProjectSubscriptionResponse@@ -25,6 +26,8 @@ const SubscriptionPaymentMethod = ({const { ref: projectRef } = useParams()const { ui } = useStore()+ const currentOrgSlug = ui.selectedOrganization?.slug+const canUpdatePaymentMethod = checkPermissions(PermissionAction.BILLING_WRITE,'stripe.subscriptions'@@ -191,7 +194,17 @@ const SubscriptionPaymentMethod = ({<div className="py-6 space-y-2"><p className="text-sm">Upon clicking confirm, all future charges will be deducted from the selected payment- method. There are no immediate charges.+ method. There are no immediate charges. Changing the payment method for this project+ does not affect the payment method for other projects.+ </p>+ <p className="text-sm text-scale-1000">+ To remove unused or expired payment methods, head to your{' '}+ <Link href={`/org/${currentOrgSlug || '_'}/billing`} passHref>+ <a target="_blank" className="text-green-900 transition hover:text-green-1000">+ org billing settings+ </a>+ </Link>+ .</p><div className="!mt-6"><PaymentMethodSelectiondiff --git a/studio/components/interfaces/BillingV2/Subscription/Tier/SubscriptionTier.tsx b/studio/components/interfaces/BillingV2/Subscription/Tier/SubscriptionTier.tsxindex 1b8e7fc6fb8..a26e3eec82b 100644--- a/studio/components/interfaces/BillingV2/Subscription/Tier/SubscriptionTier.tsx+++ b/studio/components/interfaces/BillingV2/Subscription/Tier/SubscriptionTier.tsx@@ -139,15 +139,15 @@ const SubscriptionTier = ({}: SubscriptionTierProps) => {</Link>, it may become unresponsive.{' '}{currentPlan?.id === 'free' ? (- <span>+ <p className="pr-4">If you wish to exceed the included usage, you should upgrade to a paid plan.- </span>+ </p>) : (- <span>+ <p className="pr-4">You currently have Spend Cap enabled - when you exceed your plan's limit, youwill experience restrictions. To scale seamlessly and pay for over-usage, youcan adjust your Cost Control settings.- </span>+ </p>)}</p></Alert>diff --git a/studio/components/interfaces/BillingV2/Subscription/Tier/TierUpdateSidePanel.tsx b/studio/components/interfaces/BillingV2/Subscription/Tier/TierUpdateSidePanel.tsxindex 089315e1dc5..d2b685bb27c 100644--- a/studio/components/interfaces/BillingV2/Subscription/Tier/TierUpdateSidePanel.tsx+++ b/studio/components/interfaces/BillingV2/Subscription/Tier/TierUpdateSidePanel.tsx@@ -129,7 +129,7 @@ const TierUpdateSidePanel = () => {const tierMeta = subscriptionsPlans.find((it) => it.id === plan.id)const price = planMeta?.price ?? 0const isDowngradeOption = planMeta?.change_type === 'downgrade'- const isCurrentPlan = planMeta?.is_current ?? false+ const isCurrentPlan = planMeta?.id === subscription?.plan?.idif (plan.id === 'tier_enterprise') {return <EnterpriseCard key={plan.id} plan={plan} isCurrentPlan={isCurrentPlan} />