Skip to content

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

Bring in changes from master and resolve conflicts

Joshen Lim2ce0e71180d1
diff --cc studio/components/interfaces/Organization/GeneralSettings/MigrateOrganizationBillingButton.tsx
index fb36c0f1c4b,43d4b25d44e..a08dbc29da0
--- a/studio/components/interfaces/Organization/GeneralSettings/MigrateOrganizationBillingButton.tsx
+++ b/studio/components/interfaces/Organization/GeneralSettings/MigrateOrganizationBillingButton.tsx
@@@ -10,17 -8,22 +10,18 @@@ import { useOrganizationBillingMigratio
import { useOrganizationBillingMigrationPreview } from 'data/organizations/organization-migrate-billing-preview-query'
import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'
import { PRICING_TIER_LABELS_ORG } from 'lib/constants'
-import Link from 'next/link'
-import { useRouter } from 'next/router'
+ import PaymentMethodSelection from '../BillingSettingsV2/Subscription/PaymentMethodSelection'
const MigrateOrganizationBillingButton = observer(() => {
const { ui } = useStore()
const router = useRouter()
--
const organization = useSelectedOrganization()
const [isOpen, setIsOpen] = useState(false)
const [tier, setTier] = useState('')
const [showSpendCapHelperModal, setShowSpendCapHelperModal] = useState(false)
const [isSpendCapEnabled, setIsSpendCapEnabled] = useState(true)
+ const [paymentMethodId, setPaymentMethodId] = useState('')
- const [isSubmitting, setSubmitting] = useState(false)
const dbTier = useMemo(() => {
if (tier === '') return ''
@@@ -80,23 -70,31 +81,15 @@@
setIsOpen(!isOpen)
}
- const onValidate = (values: any) => {
- const errors: any = {}
- if (!values.tier) {
- errors.tier = 'Please select a plan.'
- }
- return errors
- }
-
- const onConfirmMigrate = async (values: any) => {
+ const onConfirmMigrate = async () => {
+ if (!tier) return
-
if (!canMigrateOrganization) {
return ui.setNotification({
category: 'error',
message: 'You do not have the required permissions to migrate this organization',
})
}
--
- migrateBilling({ organizationSlug: organization?.slug, tier: dbTier })
- setSubmitting(true)
-
- try {
- await migrateBilling({ organizationSlug: organization?.slug, tier: dbTier, paymentMethodId })
- ui.setNotification({
- message: 'Successfully migrated to organization-level billing',
- category: 'success',
- duration: 5000,
- })
- router.push('/projects')
- setIsOpen(false)
- } catch {
- } finally {
- setSubmitting(false)
- }
++ migrateBilling({ organizationSlug: organization?.slug, tier: dbTier, paymentMethodId })
}
return (
@@@ -118,167 -116,174 +111,174 @@@
</div>
}
>
- <Form
- validateOnBlur
- initialValues={{ tier: '', isSpendCapEnabled: true }}
- onSubmit={onConfirmMigrate}
- validate={onValidate}
- >
- {() => (
- <div className="space-y-4 py-3">
- <Modal.Content>
- <div className="space-y-2">
- <Alert title="About the migration" withIcon variant="info">
- <div className="text-sm space-y-2">
- <p>
- Migrating to new organization-level billing combines subscriptions for all
- projects in the organization into a single subscription. This cannot be
- reversed.{' '}
- </p>
+ <div className="space-y-4 py-3">
+ <Modal.Content>
+ <div className="space-y-2">
+ <Alert title="About the migration" withIcon variant="info">
+ <div className="text-sm space-y-2">
+ <p>
+ Migrating to new organization-level billing combines subscriptions for all
+ projects in the organization into a single subscription. This cannot be
+ reversed.{' '}
+ </p>
- <p>
- For a detailed breakdown of changes, see{' '}
- <Link href="https://www.notion.so/supabase/Organization-Level-Billing-9c159d69375b4af095f0b67881276582?pvs=4">
- <a target="_blank" rel="noreferrer" className="underline">
- Billing Migration Docs
- </a>
- </Link>
- . To transfer projects to a different organization, visit{' '}
- <Link href="/projects/_/settings/general">
- <a target="_blank" rel="noreferrer" className="underline">
- General settings
- </a>
- </Link>
- .
- </p>
- </div>
- </Alert>
+ <p>
+ For a detailed breakdown of changes, see{' '}
+ <Link href="https://www.notion.so/supabase/Organization-Level-Billing-9c159d69375b4af095f0b67881276582?pvs=4">
+ <a target="_blank" rel="noreferrer" className="underline">
+ Billing Migration Docs
+ </a>
+ </Link>
+ . To transfer projects to a different organization, visit{' '}
+ <Link href="/projects/_/settings/general">
+ <a target="_blank" rel="noreferrer" className="underline">
+ General settings
+ </a>
+ </Link>
+ .
+ </p>
</div>
- </Modal.Content>
- <Modal.Separator />
- <Modal.Content>
- <Listbox
- id="tier"
- label="Organization Pricing Plan"
- layout="horizontal"
- value={tier}
- onChange={setTier}
- className="flex items-center"
- >
- <Listbox.Option label="Select plan" value="" disabled className="hidden">
- Select Plan
+ </Alert>
+ </div>
+ </Modal.Content>
+ <Modal.Separator />
+ <Modal.Content>
+ <Listbox
+ id="tier"
+ label="Organization Pricing Plan"
+ layout="horizontal"
+ value={tier}
+ onChange={setTier}
+ className="flex items-center"
+ >
+ <Listbox.Option label="Select plan" value="" disabled className="hidden">
+ Select Plan
+ </Listbox.Option>
+ {Object.entries(PRICING_TIER_LABELS_ORG).map(([k, v]) => {
+ return (
+ <Listbox.Option key={k} label={v} value={k}>
+ {v}
</Listbox.Option>
- {Object.entries(PRICING_TIER_LABELS_ORG).map(([k, v]) => {
- return (
- <Listbox.Option key={k} label={v} value={k}>
- {v}
- </Listbox.Option>
- )
- })}
- </Listbox>
+ )
+ })}
+ </Listbox>
- <p className="text-sm text-scale-1000 mt-4">
- The pricing plan, along with included usage limits will apply to your entire
- organization. See{' '}
- <a
- className="underline"
- target="_blank"
- rel="noreferrer"
- href="https://supabase.com/pricing"
- >
- Pricing
- </a>{' '}
- for more details. Please contact support if you are an Enterprise customer.
+ <p className="text-sm text-scale-1000 mt-4">
+ The pricing plan, along with included usage limits will apply to your entire
+ organization. See{' '}
+ <a
+ className="underline"
+ target="_blank"
+ rel="noreferrer"
+ href="https://supabase.com/pricing"
+ >
+ Pricing
+ </a>{' '}
+ for more details. Please contact support if you are an Enterprise customer.
+ </p>
+
+ {tier !== '' && tier !== 'FREE' && (
+ <div className="my-2 space-y-1 pb-4">
+ <p className="text-sm text-scale-1000">
+ Paid plans come with one compute instance included. Additional projects will at
+ least cost the compute instance hours used (min $7/month). See{' '}
+ <Link href="https://www.notion.so/supabase/Organization-Level-Billing-9c159d69375b4af095f0b67881276582?pvs=4">
+ <a target="_blank" rel="noreferrer" className="underline">
+ Compute Instance Usage Billing
+ </a>
+ </Link>{' '}
+ for more details.
</p>
+ </div>
+ )}
+ </Modal.Content>
- {tier !== '' && tier !== 'FREE' && (
- <div className="my-2 space-y-1 pb-4">
- <p className="text-sm text-scale-1000">
- Paid plans come with one compute instance included. Additional projects will
- at least cost the compute instance hours used (min $7/month). See{' '}
- <Link href="https://www.notion.so/supabase/Organization-Level-Billing-9c159d69375b4af095f0b67881276582?pvs=4">
- <a target="_blank" rel="noreferrer" className="underline">
- Compute Instance Usage Billing
- </a>
- </Link>{' '}
- for more details.
- </p>
- </div>
- )}
- <Modal.Separator />
- {tier === 'PRO' && (
- <div className="mt-4 grid grid-cols-8 gap-8 ">
- <div className="space-y-2 col-span-5">
- <h4 className="flex items-center gap-4">
- Spend Cap{' '}
- <IconHelpCircle
- size={16}
- strokeWidth={1.5}
- className="transition opacity-50 cursor-pointer hover:opacity-100"
- onClick={() => setShowSpendCapHelperModal(true)}
- />
- </h4>
- <p className="text-sm text-scale-1000">
- When enabled, usage is limited to the plan's quota, with restrictions when
- limits are exceeded.{' '}
- </p>
- <p className="text-sm text-scale-1000">
- To scale beyond Pro limits without restrictions, disable the spend cap and
- pay for over-usage beyond the quota.
- </p>
- </div>
+ <Modal.Separator />
- <div className="col-span-3">
- <Toggle
- id="isSpendCapEnabled"
- layout="vertical"
- label={
- <div className="flex space-x-4">
- <span>Enable Spend Cap</span>
- </div>
- }
- checked={isSpendCapEnabled}
- onChange={() => setIsSpendCapEnabled(!isSpendCapEnabled)}
+ {tier === 'PRO' && (
+ <>
+ <Modal.Content>
+ <div className="mt-4 grid grid-cols-8 gap-x-8 gap-y-2">
+ <div className="space-y-2 col-span-4">
+ <p className="text-sm flex items-center gap-4">
+ Enable spend cap{' '}
+ <IconHelpCircle
+ size={16}
+ strokeWidth={1.5}
+ className="transition opacity-50 cursor-pointer hover:opacity-100"
+ onClick={() => setShowSpendCapHelperModal(true)}
/>
- </div>
+ </p>
+ </div>
- <SpendCapModal
- visible={showSpendCapHelperModal}
- onHide={() => setShowSpendCapHelperModal(false)}
+ <div className="col-span-8">
+ <Toggle
+ id="isSpendCapEnabled"
+ layout="vertical"
+ checked={isSpendCapEnabled}
+ onChange={() => setIsSpendCapEnabled(!isSpendCapEnabled)}
/>
</div>
- )}
- </Modal.Content>
- <Modal.Content>
- <Loading active={tier !== '' && migrationPreviewIsLoading}>
- {migrationPreviewError && (
- <Alert title="Organization cannot be migrated" variant="danger">
- <span>{migrationPreviewError.message}</span>
- </Alert>
- )}
- </Loading>
- {migrationError && (
- <Alert title="Organization cannot be migrated" variant="danger">
- <span>{migrationError.message}</span>
- </Alert>
- )}
+ <div className="col-span-12">
+ <p className="text-sm text-scale-1000">
+ When enabled, usage is limited to the plan's quota, with restrictions when
+ limits are exceeded. To scale beyond Pro limits without restrictions, disable
+ the spend cap and pay for over-usage beyond the quota.
+ </p>
+ </div>
+
+ <SpendCapModal
+ visible={showSpendCapHelperModal}
+ onHide={() => setShowSpendCapHelperModal(false)}
+ />
+ </div>
</Modal.Content>
+ <Modal.Separator />
+ </>
+ )}
+
+ {tier && tier !== 'FREE' && (
+ <>
<Modal.Content>
- <Button
- block
- size="small"
- type="primary"
- htmlType="submit"
- loading={isMigrating}
- disabled={migrationPreviewData === undefined || isMigrating}
- >
- I understand, migrate this organization
- </Button>
+ <PaymentMethodSelection
+ layout="horizontal"
+ onSelectPaymentMethod={(pm) => setPaymentMethodId(pm)}
+ />
</Modal.Content>
- </div>
+ <Modal.Separator />
+ </>
)}
- </Form>
+
+ <Modal.Content>
+ <Loading active={tier !== '' && migrationPreviewIsLoading}>
+ {migrationPreviewError && (
+ <Alert title="Organization cannot be migrated" variant="danger">
+ <span>{migrationPreviewError.message}</span>
+ </Alert>
+ )}
+ </Loading>
+
+ {migrationError && (
+ <Alert title="Organization cannot be migrated" variant="danger">
+ <span>{migrationError.message}</span>
+ </Alert>
+ )}
+ </Modal.Content>
+ <Modal.Content>
+ <Button
+ block
+ size="small"
+ type="primary"
+ htmlType="submit"
- loading={isSubmitting}
- disabled={migrationPreviewData === undefined || isSubmitting || !tier}
++ loading={isMigrating}
++ disabled={migrationPreviewData === undefined || isMigrating || !tier}
+ onClick={() => onConfirmMigrate()}
+ >
+ I understand, migrate this organization
+ </Button>
+ </Modal.Content>
+ </div>
</Modal>
</>
)
diff --cc studio/components/interfaces/Settings/Addons/Addons.tsx
index f45dd985633,9e5dd9fda1c..e9bb25a6338
--- a/studio/components/interfaces/Settings/Addons/Addons.tsx
+++ b/studio/components/interfaces/Settings/Addons/Addons.tsx
@@@ -5,6 -5,6 +5,7 @@@ import { useMemo } from 'react
import { useParams, useTheme } from 'common'
import { getAddons } from 'components/interfaces/BillingV2/Subscription/Subscription.utils'
import ProjectUpdateDisabledTooltip from 'components/interfaces/Organization/BillingSettings/ProjectUpdateDisabledTooltip'
++import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import {
ScaffoldContainer,
ScaffoldDivider,
@@@ -17,7 -15,8 +18,8 @@@ import { GenericSkeletonLoader } from '
import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
import { useFlag } from 'hooks'
-import { BASE_PATH } from 'lib/constants'
+ import { getCloudProviderArchitecture } from 'lib/cloudprovider-utils'
+import { BASE_PATH } from 'lib/constants'
import { useSubscriptionPageStateSnapshot } from 'state/subscription-page'
import { Alert, Button, IconChevronRight, IconExternalLink } from 'ui'
import { ComputeInstanceSidePanel, CustomDomainSidePanel, PITRSidePanel } from './'
diff --cc studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
index f8850e94a82,49a9cf08b6e..c8c0a009d21
--- a/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
+++ b/studio/components/interfaces/Settings/Addons/ComputeInstanceSidePanel.tsx
@@@ -65,47 -67,11 +66,48 @@@ const ComputeInstanceSidePanel = () =>
const { data: addons, isLoading } = useProjectAddonsQuery({ projectRef })
const { data: subscription } = useProjectSubscriptionV2Query({ projectRef })
- const { mutateAsync: updateAddon } = useProjectAddonUpdateMutation()
- const { mutateAsync: removeAddon } = useProjectAddonRemoveMutation()
+ const { mutate: updateAddon, isLoading: isUpdating } = useProjectAddonUpdateMutation({
+ onSuccess: () => {
+ ui.setNotification({
+ duration: 8000,
+ category: 'success',
+ message: `Successfully updated compute instance to ${selectedCompute?.name}. Your project is currently being restarted to update its instance`,
+ })
+ setProjectStatus(queryClient, projectRef!, PROJECT_STATUS.RESTORING)
+ onClose()
+ router.push(`/project/${projectRef}`)
+ },
+ onError: (error) => {
+ ui.setNotification({
+ error,
+ category: 'error',
+ message: `Unable to update compute instance: ${error.message}`,
+ })
+ },
+ })
+ const { mutate: removeAddon, isLoading: isRemoving } = useProjectAddonRemoveMutation({
+ onSuccess: () => {
+ ui.setNotification({
+ duration: 8000,
+ category: 'success',
+ message: `Successfully updated compute instance to Micro. Your project is currently being restarted to update its instance`,
+ })
+ setProjectStatus(queryClient, projectRef!, PROJECT_STATUS.RESTORING)
+ onClose()
+ router.push(`/project/${projectRef}`)
+ },
+ onError: (error) => {
+ ui.setNotification({
+ error,
+ category: 'error',
+ message: `Unable to update compute instance: ${error.message}`,
+ })
+ },
+ })
+ const isSubmitting = isUpdating || isRemoving
const projectId = selectedProject?.id
+ const cpuArchitecture = getCloudProviderArchitecture(selectedProject?.cloud_provider)
const selectedAddons = addons?.selected_addons ?? []
const availableAddons = addons?.available_addons ?? []
diff --cc studio/data/organizations/organization-migrate-billing-mutation.ts
index dae2e44d37b,565aa053ba3..b8817494ed8
--- a/studio/data/organizations/organization-migrate-billing-mutation.ts
+++ b/studio/data/organizations/organization-migrate-billing-mutation.ts
@@@ -9,8 -6,13 +9,9 @@@ import { organizationKeys } from './key
export type OrganizationBillingMigrationVariables = {
organizationSlug?: string
tier?: string
+ paymentMethodId?: string
}
-type OrganizationBillingMigrationError = {
- message: string
-}
-
export async function migrateBilling({
organizationSlug,
tier,