The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: go-live org-based billing
Kevin Grüneberg611462a0e762
diff --git a/studio/components/interfaces/BillingV2/SpendCapModal.tsx b/studio/components/interfaces/BillingV2/SpendCapModal.tsxindex ef662f146cd..d70e5b2e0de 100644--- a/studio/components/interfaces/BillingV2/SpendCapModal.tsx+++ b/studio/components/interfaces/BillingV2/SpendCapModal.tsx@@ -34,12 +34,12 @@ const SpendCapModal = ({ visible, onHide }: SpendCapModalProps) => {<div className="flex items-center px-4 py-1"><p className="w-[50%] text-sm">Database size</p><p className="w-[25%] text-sm">8GB</p>- <p className="w-[25%] text-sm">$0.125/GB</p>+ <p className="w-[25%] text-sm">$0.125 per GB</p></div><div className="flex items-center px-4 py-1">- <p className="w-[50%] text-sm">Database egress</p>- <p className="w-[25%] text-sm">50GB</p>- <p className="w-[25%] text-sm">$0.09/GB</p>+ <p className="w-[50%] text-sm">Egress</p>+ <p className="w-[25%] text-sm">250GB</p>+ <p className="w-[25%] text-sm">$0.09 per GB</p></div></div><div className="py-2">@@ -75,10 +75,8 @@ const SpendCapModal = ({ visible, onHide }: SpendCapModalProps) => {</Tooltip.Root></div><p className="w-[25%] text-sm">100,000</p>- <p className="w-[25%] text-sm">$0.00325/user</p>+ <p className="w-[25%] text-sm">$0.00325 per user</p></div>- </div>- <div className="py-2"><div className="flex items-center px-4 py-1"><div className="flex w-[50%] items-center space-x-2"><p className="text-sm">Single Sign-On (SAML 2.0) MAUs</p>@@ -111,19 +109,15 @@ const SpendCapModal = ({ visible, onHide }: SpendCapModalProps) => {</Tooltip.Root></div><p className="w-[25%] text-sm">50</p>- <p className="w-[25%] text-sm">$0.015/user</p>+ <p className="w-[25%] text-sm">$0.015 per user</p></div></div>+<div className="py-2"><div className="flex items-center px-4 py-1"><p className="w-[50%] text-sm">Storage size</p><p className="w-[25%] text-sm">100GB</p>- <p className="w-[25%] text-sm">$0.021/GB</p>- </div>- <div className="flex items-center px-4 py-1">- <p className="w-[50%] text-sm">Storage egress</p>- <p className="w-[25%] text-sm">200GB</p>- <p className="w-[25%] text-sm">$0.09/GB</p>+ <p className="w-[25%] text-sm">$0.021 per GB</p></div><div className="flex items-center px-4 py-1"><p className="w-[50%] text-sm">Storage Image Transformations</p>@@ -136,13 +130,13 @@ const SpendCapModal = ({ visible, onHide }: SpendCapModalProps) => {<div className="flex items-center px-4 py-1"><p className="w-[50%] text-sm">Realtime concurrent peak connections</p><p className="w-[25%] text-sm">500</p>- <p className="w-[25%] text-sm">$10/1000</p>+ <p className="w-[25%] text-sm">$10 per 1000</p></div><div className="flex items-center px-4 py-1"><p className="w-[50%] text-sm">Realtime messages</p><p className="w-[25%] text-sm">5 Million</p>- <p className="w-[25%] text-sm">$2.50/Million</p>+ <p className="w-[25%] text-sm">$2.50 per Million</p></div></div>@@ -161,7 +155,7 @@ const SpendCapModal = ({ visible, onHide }: SpendCapModalProps) => {</div></div>- <p>+ <p className="text-sm">See{' '}<Link href="https://supabase.com/pricing" passHref><a className="text-brand" target="_blank" rel="noreferrer">diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/PlanUpdateSidePanel.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/PlanUpdateSidePanel.tsxindex fd13a6dc6e2..03c23fb582d 100644--- a/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/PlanUpdateSidePanel.tsx+++ b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/PlanUpdateSidePanel.tsx@@ -266,7 +266,7 @@ const PlanUpdateSidePanel = () => {<div className="border-t my-6" /><ul role="list">- {(plan.featuresOrg || plan.features).map((feature) => (+ {(plan.features).map((feature) => (<li key={feature} className="flex py-2"><div className="w-[12px]"><IconCheckdiff --git a/studio/components/interfaces/Organization/GeneralSettings/MigrateOrganizationBillingButton.tsx b/studio/components/interfaces/Organization/GeneralSettings/MigrateOrganizationBillingButton.tsxindex 6fda726340d..6a2710f8a1a 100644--- a/studio/components/interfaces/Organization/GeneralSettings/MigrateOrganizationBillingButton.tsx+++ b/studio/components/interfaces/Organization/GeneralSettings/MigrateOrganizationBillingButton.tsx@@ -1,3 +1,4 @@+import * as Tooltip from '@radix-ui/react-tooltip'import { PermissionAction } from '@supabase/shared-types/out/constants'import { observer } from 'mobx-react-lite'import Link from 'next/link'@@ -20,7 +21,7 @@ import {import { SpendCapModal } from 'components/interfaces/BillingV2'import { useOrganizationBillingMigrationMutation } from 'data/organizations/organization-migrate-billing-mutation'import { useOrganizationBillingMigrationPreview } from 'data/organizations/organization-migrate-billing-preview-query'-import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'+import { useCheckPermissions, useFlag, useSelectedOrganization, useStore } from 'hooks'import { PRICING_TIER_LABELS_ORG } from 'lib/constants'import PaymentMethodSelection from '../BillingSettingsV2/Subscription/PaymentMethodSelection'import InformationBox from 'components/ui/InformationBox'@@ -30,6 +31,9 @@ const MigrateOrganizationBillingButton = observer(() => {const router = useRouter()const organization = useSelectedOrganization()+ const disableOrgBillingMigration = useFlag('disableOrgBillingMigration')+ const canMigrateOrg = useCheckPermissions(PermissionAction.UPDATE, 'organizations')+const [isOpen, setIsOpen] = useState(false)const [tier, setTier] = useState('')const [showSpendCapHelperModal, setShowSpendCapHelperModal] = useState(false)@@ -65,6 +69,7 @@ const MigrateOrganizationBillingButton = observer(() => {data: migrationPreviewData,error: migrationPreviewError,isLoading: migrationPreviewIsLoading,+ isSuccess: migrationPreviewIsSuccess,remove,refetch: previewMigration,} = useOrganizationBillingMigrationPreview(@@ -108,9 +113,37 @@ const MigrateOrganizationBillingButton = observer(() => {return (<><div>- <Button loading={!organization?.slug} onClick={() => setIsOpen(true)} type="primary">- Migrate organization- </Button>+ <Tooltip.Root delayDuration={0}>+ <Tooltip.Trigger>+ <Button+ loading={!organization?.slug}+ onClick={toggle}+ type="primary"+ disabled={!canMigrateOrg || disableOrgBillingMigration}+ >+ Migrate organization+ </Button>+ </Tooltip.Trigger>+ {(!canMigrateOrg || disableOrgBillingMigration) && (+ <Tooltip.Portal>+ <Tooltip.Content side="bottom">+ <Tooltip.Arrow className="radix-tooltip-arrow" />+ <div+ className={[+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow', // background+ 'border border-scale-200 ', //border+ ].join(' ')}+ >+ <span className="text-xs text-scale-1200">+ {!canMigrateOrg+ ? 'You need additional permissions to migrate this organization'+ : 'Migrations are temporarily disabled, please try again later.'}+ </span>+ </div>+ </Tooltip.Content>+ </Tooltip.Portal>+ )}+ </Tooltip.Root></div><Modalclosable@@ -125,48 +158,41 @@ const MigrateOrganizationBillingButton = observer(() => {}><div className="space-y-4 py-3">+ {migrationPreviewData?.addons_to_be_removed &&+ migrationPreviewData.addons_to_be_removed.length > 0 && (+ <>+ <Modal.Content>+ <div className="space-y-2">+ <Alert_Shadcn_ variant="warning">+ <IconAlertTriangle strokeWidth={2} />+ <AlertTitle_Shadcn_>Project addons will be removed</AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ <div>+ The following project addons will be removed when downgrading+ <ul className="list-disc list-inside pl-4">+ {migrationPreviewData.addons_to_be_removed.map((addon) =>+ addon.addons.map((variant) => (+ <li key={`${addon.projectRef}-${variant.variant}`}>+ {variant.type === 'pitr'+ ? 'PITR - '+ : variant.type === 'compute_instance'+ ? 'Compute Instance - '+ : ''}+ {variant.name} for project {addon.projectName || addon.projectRef}+ </li>+ ))+ )}+ </ul>+ </div>+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ </div>+ </Modal.Content>+ <Modal.Separator />+ </>+ )}<Modal.Content>- <div className="space-y-2">- <Alert_Shadcn_ variant="destructive">- <IconAlertCircle strokeWidth={2} />- <AlertTitle_Shadcn_>Irreversible</AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>- Once migrated to the new organization-based billing, you cannot go back to the old- project-level billing.- </AlertDescription_Shadcn_>- </Alert_Shadcn_>-- {migrationPreviewData?.addons_to_be_removed &&- migrationPreviewData.addons_to_be_removed.length > 0 && (- <Alert_Shadcn_ variant="warning">- <IconAlertTriangle strokeWidth={2} />- <AlertTitle_Shadcn_>Project addons will be removed</AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>- <div>- The following project addons will be removed when downgrading- <ul className="list-disc list-inside pl-4">- {migrationPreviewData.addons_to_be_removed.map((addon) =>- addon.addons.map((variant) => (- <li key={`${addon.projectRef}-${variant.variant}`}>- {variant.type === 'pitr'- ? 'PITR - '- : variant.type === 'compute_instance'- ? 'Compute Instance - '- : ''}- {variant.name} for project {addon.projectName || addon.projectRef}- </li>- ))- )}- </ul>- </div>- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- )}- </div>- </Modal.Content>- <Modal.Separator />- <Modal.Content>- <div className="text-scale-1000 text-sm space-y-2">+ <div className="text-scale-1100 text-sm space-y-2"><p>Migrating to new organization-based billing combines subscriptions for all projectsin the organization into a single subscription.@@ -180,7 +206,7 @@ const MigrateOrganizationBillingButton = observer(() => {</a></Link>. To transfer projects to a different organization, visit{' '}- <Link href="/projects/_/settings/general">+ <Link href="/project/_/settings/general"><a target="_blank" rel="noreferrer" className="underline">General settings</a>@@ -211,7 +237,7 @@ const MigrateOrganizationBillingButton = observer(() => {})}</Listbox>- <p className="text-sm text-scale-1000 mt-4">+ <p className="text-sm text-scale-1100 mt-4">The pricing plan, along with included usage limits will apply to your entireorganization. See{' '}<a@@ -229,7 +255,7 @@ const MigrateOrganizationBillingButton = observer(() => {<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{' '}+ least cost the compute instance hours used (min $10/month). See{' '}<Link href="https://supabase.com/docs/guides/platform/org-based-billing#usage-based-billing-for-compute"><a target="_blank" rel="noreferrer" className="underline">Compute Instance Usage Billing@@ -320,7 +346,7 @@ const MigrateOrganizationBillingButton = observer(() => {)}</Modal.Content>- {!migrationPreviewIsLoading && migrationPreviewData && dbTier !== 'tier_free' && (+ {migrationPreviewIsSuccess && dbTier !== 'tier_free' && (<Modal.Content><InformationBoxdefaultVisibility={false}@@ -389,13 +415,23 @@ const MigrateOrganizationBillingButton = observer(() => {)}<Modal.Content>+ <p className="mb-4 text-sm text-scale-1100">+ The migration can take up to 30 seconds, please do not cancel the request or close+ your browser.+ </p>+<Buttonblocksize="small"type="primary"htmlType="submit"loading={isMigrating}- disabled={migrationPreviewData === undefined || isMigrating || !tier}+ disabled={+ migrationPreviewData === undefined ||+ isMigrating ||+ !tier ||+ disableOrgBillingMigration+ }onClick={() => onConfirmMigrate()}>I understand, migrate this organizationdiff --git a/studio/components/interfaces/Organization/GeneralSettings/OrganizationBillingMigrationPanel.tsx b/studio/components/interfaces/Organization/GeneralSettings/OrganizationBillingMigrationPanel.tsxindex 8f8318d574a..80a75c570dc 100644--- a/studio/components/interfaces/Organization/GeneralSettings/OrganizationBillingMigrationPanel.tsx+++ b/studio/components/interfaces/Organization/GeneralSettings/OrganizationBillingMigrationPanel.tsx@@ -23,10 +23,8 @@ const OrganizationBillingMigrationPanel = observer(() => {<div className="space-y-2"><p className="text-sm text-scale-1100">You will have a single subscription for all projects inside the organization, rather- than individual subscriptions per project.- </p>- <p className="text-sm text-scale-1100">- Migrating your organization billing is not reversible.+ than individual subscriptions per project. Migrating to organization-based billing+ is not reversible.</p></div><div className="flex items-center gap-4 ml-12">diff --git a/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx b/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsxindex 372f9b28b39..e81f62ed73a 100644--- a/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx+++ b/studio/components/interfaces/Organization/NewOrg/NewOrgForm.tsx@@ -23,6 +23,7 @@ import { invalidateOrganizationsQuery } from 'data/organizations/organizations-qimport { useStore } from 'hooks'import { BASE_PATH, PRICING_TIER_LABELS_ORG } from 'lib/constants'import { getURL } from 'lib/helpers'+import { useParams } from 'common'const ORG_KIND_TYPES = {PERSONAL: 'Personal',@@ -57,6 +58,8 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {const stripe = useStripe()const elements = useElements()+ const { plan } = useParams()+const [orgName, setOrgName] = useState('')const [orgKind, setOrgKind] = useState(ORG_KIND_DEFAULT)const [orgSize, setOrgSize] = useState(ORG_SIZE_DEFAULT)@@ -64,7 +67,10 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {const [newOrgLoading, setNewOrgLoading] = useState(false)const [paymentMethod, setPaymentMethod] = useState<PaymentMethod>()- const [dbPricingTierKey, setDbPricingTierKey] = useState('FREE')+ // URL param support for passing plan+ const [dbPricingTierKey, setDbPricingTierKey] = useState(+ plan && ['free', 'team', 'pro'].includes(plan) ? plan.toUpperCase() : 'FREE'+ )const [showSpendCapHelperModal, setShowSpendCapHelperModal] = useState(false)const [isSpendCapEnabled, setIsSpendCapEnabled] = useState(true)@@ -133,7 +139,7 @@ const NewOrgForm = ({ onPaymentMethodReset }: NewOrgFormProps) => {elements,redirect: 'if_required',confirmParams: {- return_url: `${getURL()}/new-with-subscription`,+ return_url: `${getURL()}/new`,expand: ['payment_method'],},})diff --git a/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectButton.tsx b/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectButton.tsxindex b81b8f3f024..072b9c83c79 100644--- a/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectButton.tsx+++ b/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectButton.tsx@@ -18,7 +18,7 @@ import {import { useOrganizationsQuery } from 'data/organizations/organizations-query'import { useProjectTransferMutation } from 'data/projects/project-transfer-mutation'import { useProjectTransferPreviewQuery } from 'data/projects/project-transfer-preview-query'-import { useCheckPermissions, useSelectedProject, useStore } from 'hooks'+import { useCheckPermissions, useFlag, useSelectedProject, useStore } from 'hooks'const TransferProjectButton = () => {const { ui } = useStore()@@ -27,6 +27,7 @@ const TransferProjectButton = () => {const projectRef = project?.refconst projectOrgId = project?.organization_idconst { data: allOrganizations } = useOrganizationsQuery()+ const disableProjectTransfer = useFlag('disableProjectTransfer')const organizations = (allOrganizations || []).filter((it) => it.id !== projectOrgId)@@ -87,11 +88,15 @@ const TransferProjectButton = () => {<><Tooltip.Root delayDuration={0}><Tooltip.Trigger>- <Button onClick={toggle} type="default" disabled={!canTransferProject}>+ <Button+ onClick={toggle}+ type="default"+ disabled={!canTransferProject || disableProjectTransfer}+ >Transfer project</Button></Tooltip.Trigger>- {!canTransferProject && (+ {(!canTransferProject || disableProjectTransfer) && (<Tooltip.Portal><Tooltip.Content side="bottom"><Tooltip.Arrow className="radix-tooltip-arrow" />@@ -102,7 +107,9 @@ const TransferProjectButton = () => {].join(' ')}><span className="text-xs text-scale-1200">- You need additional permissions to transfer this project+ {!canTransferProject+ ? 'You need additional permissions to transfer this project'+ : 'Project transfers are temporarily disabled, please try again later.'}</span></div></Tooltip.Content>diff --git a/studio/components/layouts/AppLayout/OrganizationDropdown.tsx b/studio/components/layouts/AppLayout/OrganizationDropdown.tsxindex 2108e48d5ac..eb61f463219 100644--- a/studio/components/layouts/AppLayout/OrganizationDropdown.tsx+++ b/studio/components/layouts/AppLayout/OrganizationDropdown.tsx@@ -22,11 +22,10 @@ import {import ShimmeringLoader from 'components/ui/ShimmeringLoader'import { useOrganizationsQuery } from 'data/organizations/organizations-query'import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'-import { useFlag, useSelectedOrganization } from 'hooks'+import { useSelectedOrganization } from 'hooks'const OrganizationDropdown = () => {const router = useRouter()- const orgCreationV2 = useFlag('orgcreationv2')const selectedOrganization = useSelectedOrganization()const { data: organizations, isLoading: isLoadingOrganizations } = useOrganizationsQuery()@@ -97,13 +96,13 @@ const OrganizationDropdown = () => {</ScrollArea></CommandGroup_Shadcn_><CommandGroup_Shadcn_ className="border-t">- <Link passHref href={orgCreationV2 ? `/new-with-subscription` : `/new`}>+ <Link passHref href="new"><CommandItem_Shadcn_asChildclassName="cursor-pointer flex items-center space-x-2 w-full"onSelect={(e) => {setOpen(false)- router.push(orgCreationV2 ? `/new-with-subscription` : `/new`)+ router.push(`/new`)}}onClick={() => setOpen(false)}>diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/OrgDropdown.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/OrgDropdown.tsxindex f78daf82b4d..6e17d2db385 100644--- a/studio/components/layouts/ProjectLayout/LayoutHeader/OrgDropdown.tsx+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/OrgDropdown.tsx@@ -2,7 +2,7 @@ import { toJS } from 'mobx'import { useRouter } from 'next/router'import { useOrganizationsQuery } from 'data/organizations/organizations-query'-import { useFlag, useSelectedOrganization, useStore } from 'hooks'+import { useSelectedOrganization, useStore } from 'hooks'import { IS_PLATFORM } from 'lib/constants'import { Button, Dropdown, IconPlus } from 'ui'@@ -13,8 +13,6 @@ const OrgDropdown = () => {const { data: organizations } = useOrganizationsQuery()const selectedOrganization = useSelectedOrganization()- const orgCreationV2 = useFlag('orgcreationv2')-return IS_PLATFORM ? (<Dropdownside="bottom"@@ -54,10 +52,7 @@ const OrgDropdown = () => {})}<Dropdown.Separator />- <Dropdown.Item- icon={<IconPlus size="tiny" />}- onClick={() => router.push(orgCreationV2 ? `/new-with-subscription` : `/new`)}- >+ <Dropdown.Item icon={<IconPlus size="tiny" />} onClick={() => router.push(`/new`)}>New organization</Dropdown.Item></>diff --git a/studio/components/to-be-cleaned/Dropdown/OrganizationDropdown.js b/studio/components/to-be-cleaned/Dropdown/OrganizationDropdown.jsindex f522414b564..6dcbcaa358d 100644--- a/studio/components/to-be-cleaned/Dropdown/OrganizationDropdown.js+++ b/studio/components/to-be-cleaned/Dropdown/OrganizationDropdown.js@@ -1,12 +1,10 @@import { useRouter } from 'next/router'-import { useFlag } from 'hooks'import { Button, Dropdown, IconPlus } from 'ui'import { EMPTY_ARR } from 'lib/void'const OrganizationDropdown = ({ organizations = EMPTY_ARR }) => {const router = useRouter()- const orgCreationV2 = useFlag('orgcreationv2')return (<Dropdown@@ -29,7 +27,7 @@ const OrganizationDropdown = ({ organizations = EMPTY_ARR }) => {<Dropdown.Separator /><Dropdown.Itemicon={<IconPlus size="tiny" />}- onClick={() => router.push(orgCreationV2 ? `/new-with-subscription` : `/new`)}+ onClick={() => router.push(`/new`)}>New organization</Dropdown.Item>diff --git a/studio/data/subscriptions/org-subscription-update-mutation.ts b/studio/data/subscriptions/org-subscription-update-mutation.tsindex 0bd336be317..4e91365c39e 100644--- a/studio/data/subscriptions/org-subscription-update-mutation.ts+++ b/studio/data/subscriptions/org-subscription-update-mutation.ts@@ -4,6 +4,7 @@ import { API_URL } from 'lib/constants'import { toast } from 'react-hot-toast'import { ResponseError } from 'types/base'import { subscriptionKeys } from './keys'+import { usageKeys } from 'data/usage/keys'export type SubscriptionTier =| 'tier_free'@@ -54,7 +55,17 @@ export const useOrgSubscriptionUpdateMutation = ({{async onSuccess(data, variables, context) {const { slug } = variables- await queryClient.invalidateQueries(subscriptionKeys.orgSubscription(slug))++ // [Kevin] Backend can return stale data as it's waiting for the Stripe-sync to complete. Until that's solved in the backend+ // we are going back to monkey here and delay the invalidation+ await new Promise((resolve) => setTimeout(resolve, 2000))++ await Promise.all([+ queryClient.invalidateQueries(subscriptionKeys.orgSubscription(slug)),+ queryClient.invalidateQueries(subscriptionKeys.orgPlans(slug)),+ queryClient.invalidateQueries(usageKeys.orgUsage(slug)),+ ])+await onSuccess?.(data, variables, context)},async onError(data, variables, context) {diff --git a/studio/pages/new/[slug].tsx b/studio/pages/new/[slug].tsxindex 962f8ad281f..3179618a1d9 100644--- a/studio/pages/new/[slug].tsx+++ b/studio/pages/new/[slug].tsx@@ -474,16 +474,24 @@ const Wizard: NextPageWithLayout = () => {<span className="text-brand">{orgSubscription?.plan?.name} plan</span>.</p>+ {/* Show info when launching a new project in a paid org that has no project yet */}+ {orgSubscription?.plan?.id !== 'free' && orgProjectCount === 0 && (+ <div>+ <p>+ As this is the first project you're launching in this organization, it+ comes with no additional compute costs.+ </p>+ </div>+ )}+{/* Show info when launching a new project in a paid org that already has at least one project */}{orgSubscription?.plan?.id !== 'free' && orgProjectCount > 0 && (<div><p>Launching another project incurs additional compute costs, starting at- $0.01344 per hour (~$10/month).- </p>- <p>- You can also create a new organization under the free plan (unless you- have exceeded your 2 free project limit).+ $0.01344 per hour (~$10/month). You can also create a new organization+ under the free plan in case you have not exceeded your 2 free project+ limit.</p></div>)}diff --git a/studio/pages/new/index.tsx b/studio/pages/new/index.tsxindex be52ba18366..5a14b15fa9b 100644--- a/studio/pages/new/index.tsx+++ b/studio/pages/new/index.tsx@@ -1,161 +1,106 @@+import HCaptcha from '@hcaptcha/react-hcaptcha'+import { Elements } from '@stripe/react-stripe-js'+import { loadStripe } from '@stripe/stripe-js'+import { useParams, useTheme } from 'common'import { observer } from 'mobx-react-lite'-import { useRouter } from 'next/router'-import { useState } from 'react'-import { Button, Input, Listbox } from 'ui'+import { useCallback, useEffect, useState } from 'react'+import { NewOrgForm } from 'components/interfaces/Organization'import { WizardLayout } from 'components/layouts'-import Panel from 'components/ui/Panel'-import { useOrganizationCreateMutation } from 'data/organizations/organization-create-mutation'-import { useStore } from 'hooks'+import { useSetupIntent } from 'data/stripe/setup-intent-mutation'+import { STRIPE_PUBLIC_KEY } from 'lib/constants'+import { useIsHCaptchaLoaded } from 'stores/hcaptcha-loaded-store'import { NextPageWithLayout } from 'types'-const ORG_KIND_TYPES = {- PERSONAL: 'Personal',- EDUCATIONAL: 'Educational',- STARTUP: 'Startup',- AGENCY: 'Agency',- COMPANY: 'Company',- UNDISCLOSED: 'N/A',-}-const ORG_KIND_DEFAULT = 'PERSONAL'--const ORG_SIZE_TYPES = {- '1': '1 - 10',- '10': '10 - 49',- '50': '50 - 99',- '100': '100 - 299',- '300': 'More than 300',-}-const ORG_SIZE_DEFAULT = '1'+const stripePromise = loadStripe(STRIPE_PUBLIC_KEY)/*** No org selected yet, create a new one*/const Wizard: NextPageWithLayout = () => {- const { ui } = useStore()- const router = useRouter()-- const [orgName, setOrgName] = useState('')- const [orgKind, setOrgKind] = useState(ORG_KIND_DEFAULT)- const [orgSize, setOrgSize] = useState(ORG_SIZE_DEFAULT)-- const { mutate: createOrganization, isLoading: newOrgLoading } = useOrganizationCreateMutation({- onSuccess: async (org: any) => {- // [Joshen] API spec is wrong? its returning org type as only having id and name- router.push(`/new/${org.slug}`)- },- })-- function validateOrgName(name: any) {- return name.length >= 1- }+ const { isDarkMode } = useTheme()++ const [intent, setIntent] = useState<any>()+ const captchaLoaded = useIsHCaptchaLoaded()++ const [captchaToken, setCaptchaToken] = useState<string | null>(null)+ const [captchaRef, setCaptchaRef] = useState<HCaptcha | null>(null)- function onOrgNameChange(e: any) {- setOrgName(e.target.value)+ const { mutate: setupIntent } = useSetupIntent({ onSuccess: (res) => setIntent(res) })++ const captchaRefCallback = useCallback((node) => {+ setCaptchaRef(node)+ }, [])++ const initSetupIntent = async (hcaptchaToken: string | undefined) => {+ if (!hcaptchaToken) return console.error('Hcaptcha token is required')++ // Force a reload of Elements, necessary for Stripe+ setIntent(undefined)+ setupIntent({ hcaptchaToken })}- function onOrgKindChange(value: any) {- setOrgKind(value)+ const options = {+ clientSecret: intent ? intent.client_secret : '',+ appearance: { theme: isDarkMode ? 'night' : 'flat', labels: 'floating' },+ } as any++ const loadPaymentForm = async () => {+ if (captchaRef && captchaLoaded) {+ let token = captchaToken++ try {+ if (!token) {+ const captchaResponse = await captchaRef.execute({ async: true })+ token = captchaResponse?.response ?? null+ }+ } catch (error) {+ return+ }++ await initSetupIntent(token ?? undefined)+ resetCaptcha()+ }}- function onOrgSizeChange(value: any) {- setOrgSize(value)+ useEffect(() => {+ loadPaymentForm()+ }, [captchaRef, captchaLoaded])++ const resetSetupIntent = () => {+ return loadPaymentForm()}- async function onClickSubmit(e: any) {- e.preventDefault()- const trimmedOrgName = orgName ? orgName.trim() : ''- const isOrgNameValid = validateOrgName(trimmedOrgName)- if (!isOrgNameValid) {- return ui.setNotification({ category: 'error', message: 'Organization name is empty' })- }+ const onLocalCancel = () => {+ setIntent(undefined)+ }- createOrganization({- name: trimmedOrgName,- kind: orgKind,- ...(orgKind == 'COMPANY' ? { size: orgSize } : {}),- })+ const resetCaptcha = () => {+ setCaptchaToken(null)+ captchaRef?.resetCaptcha()}return (- <Panel- hideHeaderStyling- title={- <div key="panel-title">- <h4>Create a new organization</h4>- </div>- }- footer={- <div key="panel-footer" className="flex w-full items-center justify-between">- <Button type="default" onClick={() => router.push('/projects')}>- Cancel- </Button>- <div className="flex items-center space-x-3">- <p className="text-xs text-scale-900">You can rename your organization later</p>- <Button onClick={onClickSubmit} loading={newOrgLoading} disabled={newOrgLoading}>- Create organization- </Button>- </div>- </div>- }- >- <Panel.Content className="pt-0">- <p className="text-sm">This is your organization within Supabase.</p>- <p className="text-sm text-scale-1100">- For example, you can use the name of your company or department.- </p>- </Panel.Content>- <Panel.Content className="Form section-block--body has-inputs-centered">- <Input- autoFocus- label="Name"- type="text"- layout="horizontal"- placeholder="Organization name"- descriptionText="What's the name of your company or team?"- value={orgName}- onChange={onOrgNameChange}- />- </Panel.Content>- <Panel.Content className="Form section-block--body has-inputs-centered">- <Listbox- label="Type of organization"- layout="horizontal"- value={orgKind}- onChange={onOrgKindChange}- descriptionText="What would best describe your organization?"- >- {Object.entries(ORG_KIND_TYPES).map(([k, v]) => {- return (- <Listbox.Option key={k} label={v} value={k}>- {v}- </Listbox.Option>- )- })}- </Listbox>- </Panel.Content>- {orgKind == 'COMPANY' ? (- <Panel.Content className="Form section-block--body has-inputs-centered">- <Listbox- label="Company size"- layout="horizontal"- value={orgSize}- onChange={onOrgSizeChange}- descriptionText="How many people are in your company?"- >- {Object.entries(ORG_SIZE_TYPES).map(([k, v]) => {- return (- <Listbox.Option key={k} label={v} value={k}>- {v}- </Listbox.Option>- )- })}- </Listbox>- </Panel.Content>- ) : (- <></>+ <>+ <HCaptcha+ ref={captchaRefCallback}+ sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}+ size="invisible"+ onVerify={(token) => {+ setCaptchaToken(token)+ }}+ onClose={onLocalCancel}+ onExpire={() => {+ setCaptchaToken(null)+ }}+ />++ {intent && (+ <Elements stripe={stripePromise} options={options}>+ <NewOrgForm onPaymentMethodReset={() => resetSetupIntent()} />+ </Elements>)}- </Panel>+ </>)}diff --git a/studio/pages/old-org.tsx b/studio/pages/old-org.tsxnew file mode 100644index 00000000000..be52ba18366--- /dev/null+++ b/studio/pages/old-org.tsx@@ -0,0 +1,168 @@+import { observer } from 'mobx-react-lite'+import { useRouter } from 'next/router'+import { useState } from 'react'+import { Button, Input, Listbox } from 'ui'++import { WizardLayout } from 'components/layouts'+import Panel from 'components/ui/Panel'+import { useOrganizationCreateMutation } from 'data/organizations/organization-create-mutation'+import { useStore } from 'hooks'+import { NextPageWithLayout } from 'types'++const ORG_KIND_TYPES = {+ PERSONAL: 'Personal',+ EDUCATIONAL: 'Educational',+ STARTUP: 'Startup',+ AGENCY: 'Agency',+ COMPANY: 'Company',+ UNDISCLOSED: 'N/A',+}+const ORG_KIND_DEFAULT = 'PERSONAL'++const ORG_SIZE_TYPES = {+ '1': '1 - 10',+ '10': '10 - 49',+ '50': '50 - 99',+ '100': '100 - 299',+ '300': 'More than 300',+}+const ORG_SIZE_DEFAULT = '1'++/**+ * No org selected yet, create a new one+ */+const Wizard: NextPageWithLayout = () => {+ const { ui } = useStore()+ const router = useRouter()++ const [orgName, setOrgName] = useState('')+ const [orgKind, setOrgKind] = useState(ORG_KIND_DEFAULT)+ const [orgSize, setOrgSize] = useState(ORG_SIZE_DEFAULT)++ const { mutate: createOrganization, isLoading: newOrgLoading } = useOrganizationCreateMutation({+ onSuccess: async (org: any) => {+ // [Joshen] API spec is wrong? its returning org type as only having id and name+ router.push(`/new/${org.slug}`)+ },+ })++ function validateOrgName(name: any) {+ return name.length >= 1+ }++ function onOrgNameChange(e: any) {+ setOrgName(e.target.value)+ }++ function onOrgKindChange(value: any) {+ setOrgKind(value)+ }++ function onOrgSizeChange(value: any) {+ setOrgSize(value)+ }++ async function onClickSubmit(e: any) {+ e.preventDefault()+ const trimmedOrgName = orgName ? orgName.trim() : ''+ const isOrgNameValid = validateOrgName(trimmedOrgName)+ if (!isOrgNameValid) {+ return ui.setNotification({ category: 'error', message: 'Organization name is empty' })+ }++ createOrganization({+ name: trimmedOrgName,+ kind: orgKind,+ ...(orgKind == 'COMPANY' ? { size: orgSize } : {}),+ })+ }++ return (+ <Panel+ hideHeaderStyling+ title={+ <div key="panel-title">+ <h4>Create a new organization</h4>+ </div>+ }+ footer={+ <div key="panel-footer" className="flex w-full items-center justify-between">+ <Button type="default" onClick={() => router.push('/projects')}>+ Cancel+ </Button>+ <div className="flex items-center space-x-3">+ <p className="text-xs text-scale-900">You can rename your organization later</p>+ <Button onClick={onClickSubmit} loading={newOrgLoading} disabled={newOrgLoading}>+ Create organization+ </Button>+ </div>+ </div>+ }+ >+ <Panel.Content className="pt-0">+ <p className="text-sm">This is your organization within Supabase.</p>+ <p className="text-sm text-scale-1100">+ For example, you can use the name of your company or department.+ </p>+ </Panel.Content>+ <Panel.Content className="Form section-block--body has-inputs-centered">+ <Input+ autoFocus+ label="Name"+ type="text"+ layout="horizontal"+ placeholder="Organization name"+ descriptionText="What's the name of your company or team?"+ value={orgName}+ onChange={onOrgNameChange}+ />+ </Panel.Content>+ <Panel.Content className="Form section-block--body has-inputs-centered">+ <Listbox+ label="Type of organization"+ layout="horizontal"+ value={orgKind}+ onChange={onOrgKindChange}+ descriptionText="What would best describe your organization?"+ >+ {Object.entries(ORG_KIND_TYPES).map(([k, v]) => {+ return (+ <Listbox.Option key={k} label={v} value={k}>+ {v}+ </Listbox.Option>+ )+ })}+ </Listbox>+ </Panel.Content>+ {orgKind == 'COMPANY' ? (+ <Panel.Content className="Form section-block--body has-inputs-centered">+ <Listbox+ label="Company size"+ layout="horizontal"+ value={orgSize}+ onChange={onOrgSizeChange}+ descriptionText="How many people are in your company?"+ >+ {Object.entries(ORG_SIZE_TYPES).map(([k, v]) => {+ return (+ <Listbox.Option key={k} label={v} value={k}>+ {v}+ </Listbox.Option>+ )+ })}+ </Listbox>+ </Panel.Content>+ ) : (+ <></>+ )}+ </Panel>+ )+}++Wizard.getLayout = (page) => (+ <WizardLayout organization={null} project={null}>+ {page}+ </WizardLayout>+)++export default observer(Wizard)diff --git a/studio/pages/org/_/[[...routeSlug]].tsx b/studio/pages/org/_/[[...routeSlug]].tsxindex 65e036ed037..b7bec24174a 100644--- a/studio/pages/org/_/[[...routeSlug]].tsx+++ b/studio/pages/org/_/[[...routeSlug]].tsx@@ -77,7 +77,7 @@ const GenericOrganizationPage: NextPage = () => {</p></div><div>- <Link href={`/new`}>+ <Link href="/new"><a><Button icon={<IconPlus />}>New organization</Button></a>