Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Shift fetching payment methods on new project page to RQ

Joshen Lim8e59e9ff02ec
diff --git a/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx b/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx
index c18d3297dfd..b453da92d71 100644
--- a/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx
+++ b/studio/components/interfaces/Organization/BillingSettings/BillingSettings.tsx
@@ -1,19 +1,19 @@
+import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { useParams } from 'common'
import { useEffect, useState } from 'react'
-import { useParams } from 'common/hooks'
+import { ScaffoldContainerLegacy } from 'components/layouts/Scaffold'
import { useProjectsQuery } from 'data/projects/projects-query'
import { useCheckPermissions, useFlag, useSelectedOrganization, useStore } from 'hooks'
-import { PermissionAction } from '@supabase/shared-types/out/constants'
import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
+import OrganizationBillingMigrationPanel from '../GeneralSettings/OrganizationBillingMigrationPanel'
import BillingAddress from './BillingAddress/BillingAddress'
import BillingEmail from './BillingEmail'
import CreditBalance from './CreditBalance'
import PaymentMethods from './PaymentMethods'
import ProjectsSummary from './ProjectsSummary'
import TaxID from './TaxID/TaxID'
-import OrganizationBillingMigrationPanel from '../GeneralSettings/OrganizationBillingMigrationPanel'
-import { ScaffoldContainer, ScaffoldContainerLegacy } from 'components/layouts/Scaffold'
const BillingSettings = () => {
const { ui } = useStore()
diff --git a/studio/components/interfaces/Organization/InvoicesSettings/InvoicesSettings.tsx b/studio/components/interfaces/Organization/InvoicesSettings/InvoicesSettings.tsx
index 5b3d9534538..61a002132ac 100644
--- a/studio/components/interfaces/Organization/InvoicesSettings/InvoicesSettings.tsx
+++ b/studio/components/interfaces/Organization/InvoicesSettings/InvoicesSettings.tsx
@@ -12,11 +12,11 @@ import { useInvoicesCountQuery } from 'data/invoices/invoices-count-query'
import { useInvoicesQuery } from 'data/invoices/invoices-query'
import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'
import { Button, IconChevronLeft, IconChevronRight, IconDownload, IconFileText, Loading } from 'ui'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import AlertError from 'components/ui/AlertError'
const PAGE_LIMIT = 10
-// Refactor: Split invoices by projects so it's easier for users to identify
-
const InvoicesSettings = () => {
const { ui } = useStore()
const [page, setPage] = useState(1)
@@ -31,7 +31,7 @@ const InvoicesSettings = () => {
customerId: stripe_customer_id,
slug,
})
- const { data, isLoading } = useInvoicesQuery({
+ const { data, error, isLoading, isError, isSuccess } = useInvoicesQuery({
customerId: stripe_customer_id,
slug,
offset,
@@ -61,7 +61,11 @@ const InvoicesSettings = () => {
return (
<ScaffoldContainerLegacy>
- <Loading active={isLoading}>
+ {isLoading && <GenericSkeletonLoader />}
+
+ {isError && <AlertError error={error} subject="Failed to retrieve invoices" />}
+
+ {isSuccess && (
<Table
head={[
<Table.th key="header-icon"></Table.th>,
@@ -155,7 +159,7 @@ const InvoicesSettings = () => {
)
}
/>
- </Loading>
+ )}
</ScaffoldContainerLegacy>
)
}
diff --git a/studio/data/organizations/organization-payment-methods-query.ts b/studio/data/organizations/organization-payment-methods-query.ts
index 6118492f797..ca5faad6d9d 100644
--- a/studio/data/organizations/organization-payment-methods-query.ts
+++ b/studio/data/organizations/organization-payment-methods-query.ts
@@ -31,7 +31,7 @@ export type OrganizationPaymentMethod = {
}
}
-export async function getOrganizations(
+export async function getOrganizationPaymentMethods(
{ slug }: OrganizationPaymentMethodsVariables,
signal?: AbortSignal
) {
@@ -43,7 +43,9 @@ export async function getOrganizations(
return response.data as OrganizationPaymentMethod[]
}
-export type OrganizationPaymentMethodsData = Awaited<ReturnType<typeof getOrganizations>>
+export type OrganizationPaymentMethodsData = Awaited<
+ ReturnType<typeof getOrganizationPaymentMethods>
+>
export type OrganizationPaymentMethodsError = unknown
export const useOrganizationPaymentMethodsQuery = <TData = OrganizationPaymentMethodsData>(
@@ -55,7 +57,7 @@ export const useOrganizationPaymentMethodsQuery = <TData = OrganizationPaymentMe
) =>
useQuery<OrganizationPaymentMethodsData, OrganizationPaymentMethodsError, TData>(
organizationKeys.paymentMethods(slug),
- ({ signal }) => getOrganizations({ slug }, signal),
+ ({ signal }) => getOrganizationPaymentMethods({ slug }, signal),
{ enabled: enabled, ...options }
)
@@ -67,7 +69,7 @@ export const useOrganizationPaymentMethodsPrefetch = ({
return useCallback(
() =>
client.prefetchQuery(organizationKeys.paymentMethods(slug), ({ signal }) =>
- getOrganizations({ slug }, signal)
+ getOrganizationPaymentMethods({ slug }, signal)
),
[]
)
diff --git a/studio/pages/new/[slug].tsx b/studio/pages/new/[slug].tsx
index ac424100810..70f25698dde 100644
--- a/studio/pages/new/[slug].tsx
+++ b/studio/pages/new/[slug].tsx
@@ -1,11 +1,23 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { useParams } from 'common'
import generator from 'generate-password'
import { debounce, isUndefined } from 'lodash'
import { observer } from 'mobx-react-lite'
+import Link from 'next/link'
import Router, { useRouter } from 'next/router'
import { useEffect, useRef, useState } from 'react'
+import {
+ Alert,
+ Button,
+ IconExternalLink,
+ IconHelpCircle,
+ IconInfo,
+ IconUsers,
+ Input,
+ Listbox,
+ Toggle,
+} from 'ui'
-import { useParams } from 'common/hooks'
import { SpendCapModal } from 'components/interfaces/BillingV2'
import {
EmptyPaymentMethodWarning,
@@ -18,10 +30,12 @@ import InformationBox from 'components/ui/InformationBox'
import Panel from 'components/ui/Panel'
import PasswordStrengthBar from 'components/ui/PasswordStrengthBar'
import { useFreeProjectLimitCheckQuery } from 'data/organizations/free-project-limit-check-query'
+import { useOrganizationPaymentMethodsQuery } from 'data/organizations/organization-payment-methods-query'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
+import { useProjectsQuery } from 'data/projects/projects-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useCheckPermissions, useFlag, useStore, withAuth } from 'hooks'
-import { get, post } from 'lib/common/fetch'
+import { post } from 'lib/common/fetch'
import {
API_URL,
AWS_REGIONS,
@@ -38,19 +52,6 @@ import {
} from 'lib/constants'
import { passwordStrength, pluckObjectFields } from 'lib/helpers'
import { NextPageWithLayout } from 'types'
-import {
- Alert,
- Button,
- IconExternalLink,
- IconHelpCircle,
- IconInfo,
- IconUsers,
- Input,
- Listbox,
- Toggle,
-} from 'ui'
-import Link from 'next/link'
-import { useProjectsQuery } from 'data/projects/projects-query'
const Wizard: NextPageWithLayout = () => {
const router = useRouter()
@@ -73,16 +74,16 @@ const Wizard: NextPageWithLayout = () => {
const [passwordStrengthMessage, setPasswordStrengthMessage] = useState('')
const [passwordStrengthWarning, setPasswordStrengthWarning] = useState('')
const [passwordStrengthScore, setPasswordStrengthScore] = useState(0)
- const [paymentMethods, setPaymentMethods] = useState<any[] | undefined>(undefined)
-
const [showSpendCapHelperModal, setShowSpendCapHelperModal] = useState(false)
-
const [isSpendCapEnabled, setIsSpendCapEnabled] = useState(true)
const { data: organizations, isSuccess: isOrganizationsSuccess } = useOrganizationsQuery()
const currentOrg = organizations?.find((o: any) => o.slug === slug)
const billedViaOrg = Boolean(currentOrg?.subscription_id)
+ const { data: paymentMethods, refetch: refetchPaymentMethods } =
+ useOrganizationPaymentMethodsQuery({ slug })
+
const { data: orgSubscription } = useOrgSubscriptionQuery(
{ orgSlug: slug },
{ enabled: billedViaOrg }
@@ -148,25 +149,6 @@ const Wizard: NextPageWithLayout = () => {
}
}, [])
- async function getPaymentMethods(slug: string) {
- const { data: paymentMethods, error } = await get(`${API_URL}/organizations/${slug}/payments`)
- if (!error) {
- setPaymentMethods(paymentMethods)
- } else {
- ui.setNotification({
- error,
- category: 'error',
- message: `Failed to retrieve payment methods: ${error.message}`,
- })
- }
- }
-
- useEffect(() => {
- if (slug) {
- getPaymentMethods(slug as string)
- }
- }, [slug])
-
function onProjectNameChange(e: any) {
e.target.value = e.target.value.replace(/\./g, '')
setProjectName(e.target.value)
@@ -196,12 +178,6 @@ const Wizard: NextPageWithLayout = () => {
setDbPricingTierKey(value)
}
- function onPaymentMethodAdded() {
- if (slug) {
- return getPaymentMethods(slug)
- }
- }
-
async function checkPasswordStrength(value: any) {
const { message, warning, strength } = await passwordStrength(value)
setPasswordStrengthScore(strength)
@@ -575,7 +551,7 @@ const Wizard: NextPageWithLayout = () => {
)}
{!billedViaOrg && !isSelectFreeTier && isEmptyPaymentMethod && (
- <EmptyPaymentMethodWarning onPaymentMethodAdded={onPaymentMethodAdded} />
+ <EmptyPaymentMethodWarning onPaymentMethodAdded={() => refetchPaymentMethods()} />
)}
</Panel.Content>
)}