The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: introduce team plan to dashboard (#11341)
Kevin Grüneberg4b4b96c7bd50
diff --git a/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsxindex 3495972be9f..c2c52459e0e 100644--- a/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx+++ b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.tsx@@ -15,6 +15,9 @@ interface Props {const PlanSelection: FC<Props> = ({ visible, tiers, currentPlan, onSelectPlan }) => {const formattedTiers = formatTierOptions(tiers)+ // [Kevin] TODO Remove after team plan is generally available+ const gridCols = formattedTiers.length === 3 ? 'gap-8 xl:grid-cols-3' : 'gap-4 xl:grid-cols-4'+return (<Transitionshow={visible}@@ -22,13 +25,12 @@ const PlanSelection: FC<Props> = ({ visible, tiers, currentPlan, onSelectPlan })enterFrom="transform opacity-0 -translate-x-10"enterTo="transform opacity-100 translate-x-0">- <div className="space-y-8">- <h4 className="text-lg">Change your project's subscription</h4>- {/* FE will make a call to fetch all plans first at the page level */}- <div className="grid lg:grid-cols-3 gap-8 py-8">+ <div>+ <h4 className="text-lg mb-8">Change your project's subscription</h4>+ <div className={`grid py-8 grid-cols-2 ${gridCols}`}><Plans plans={formattedTiers} currentPlan={currentPlan} onSelectPlan={onSelectPlan} /></div>- <div className="flex justify-center items-center">+ <div className="flex justify-center items-center mt-4"><Link href="https://supabase.com/pricing"><atarget="_blank"diff --git a/studio/components/interfaces/Billing/PlanSelection/PlanSelection.utils.ts b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.utils.tsindex e5ec5902acb..3f9b842ff7a 100644--- a/studio/components/interfaces/Billing/PlanSelection/PlanSelection.utils.ts+++ b/studio/components/interfaces/Billing/PlanSelection/PlanSelection.utils.ts@@ -14,8 +14,13 @@ export const formatTierOptions = (tiers: any[]) => {}// Fix the order of plans here- return tiers- .filter((tier: any) => tier.id === STRIPE_PRODUCT_IDS.FREE)- .concat(tiers.filter((tier: any) => tier.id === STRIPE_PRODUCT_IDS.PRO))- .concat([enterpriseOption])+ return (+ tiers+ .filter((tier: any) => tier.id === STRIPE_PRODUCT_IDS.FREE)+ .concat(tiers.filter((tier: any) => tier.id === STRIPE_PRODUCT_IDS.PRO))+ .concat(tiers.filter((tier: any) => tier.id === STRIPE_PRODUCT_IDS.TEAM))+ .concat([enterpriseOption])+ // Team plan might not be enabled yet, make sure to filter out null/undefined+ .filter(Boolean)+ )}diff --git a/studio/components/interfaces/Billing/PlanSelection/Plans/PlanCTAButton.tsx b/studio/components/interfaces/Billing/PlanSelection/Plans/PlanCTAButton.tsxindex 369105dbce8..05dbf005a53 100644--- a/studio/components/interfaces/Billing/PlanSelection/Plans/PlanCTAButton.tsx+++ b/studio/components/interfaces/Billing/PlanSelection/Plans/PlanCTAButton.tsx@@ -16,10 +16,18 @@ interface Props {const PlanCTAButton: FC<Props> = ({ plan, currentPlan, onSelectPlan }) => {const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')- const getButtonType = (plan: any) => {- if (plan.name === 'Enterprise' || plan.id === STRIPE_PRODUCT_IDS.FREE) {+ const getButtonType = (plan: any, currentPlan: any) => {+ if (['Enterprise', 'Free tier'].includes(plan.name)) {+ // Enterprise/Free are always default+ return 'default'+ } else if (currentPlan.prod_id === STRIPE_PRODUCT_IDS.FREE) {+ // If the current plan is free, other plans are primary+ return 'primary'+ } else if (currentPlan.prod_id === STRIPE_PRODUCT_IDS.TEAM && plan.name !== 'Team tier') {+ // Non-free plans are default (pro), when team tier is selectedreturn 'default'}+return 'primary'}@@ -37,6 +45,8 @@ const PlanCTAButton: FC<Props> = ({ plan, currentPlan, onSelectPlan }) => {if (plan.id === STRIPE_PRODUCT_IDS.PRO) {if (currentPlan.prod_id === STRIPE_PRODUCT_IDS.FREE) {return 'Upgrade to Pro'+ } else if (currentPlan.prod_id === STRIPE_PRODUCT_IDS.TEAM) {+ return 'Downgrade to Pro'} else if (currentPlan.prod_id === STRIPE_PRODUCT_IDS.PRO ||currentPlan.prod_id === STRIPE_PRODUCT_IDS.PAYG@@ -46,6 +56,20 @@ const PlanCTAButton: FC<Props> = ({ plan, currentPlan, onSelectPlan }) => {return 'Contact sales'}}++ if (plan.id === STRIPE_PRODUCT_IDS.TEAM) {+ if (currentPlan.prod_id === STRIPE_PRODUCT_IDS.TEAM) {+ return 'Edit plan configuration'+ } else if (+ [STRIPE_PRODUCT_IDS.FREE, STRIPE_PRODUCT_IDS.PRO, STRIPE_PRODUCT_IDS.PAYG].includes(+ currentPlan.prod_id+ )+ ) {+ return 'Upgrade to Team'+ } else {+ return 'Contact sales'+ }+ }}if (!currentPlan)@@ -57,7 +81,7 @@ const PlanCTAButton: FC<Props> = ({ plan, currentPlan, onSelectPlan }) => {</div>)- const type = getButtonType(plan)+ const type = getButtonType(plan, currentPlan)const ctaText = getButtonText(plan, currentPlan)const disabled =plan.id === STRIPE_PRODUCT_IDS.FREE && currentPlan.prod_id === STRIPE_PRODUCT_IDS.FREEdiff --git a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.Constants.ts b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.Constants.tsindex 28b917a56ec..1e8b6f8e918 100644--- a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.Constants.ts+++ b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.Constants.ts@@ -34,7 +34,7 @@ export const PRICING_META = {href: '#',from: true,priceMonthly: 25,- warning: '+ additional use',+ warning: '+ any additional usage',description: 'For production applications with the option to scale.',features: ['8GB database & 100GB file storage',@@ -52,10 +52,34 @@ export const PRICING_META = {],scale: 'Additional fees apply for usage and storage beyond the limits above.',shutdown: '',- preface: 'Everything below included in the base plan',+ preface: 'Everything in the base plan, plus',additional: 'Need more? Turn off your spend cap to Pay As You Grow ',cta: 'Get Started',},+ [STRIPE_PRODUCT_IDS.TEAM]: {+ name: 'Team',+ href: '#',+ from: true,+ priceMonthly: 599,+ warning: '+ usage',+ description: 'For collaborative teams with different permissions and access.',+ features: [+ 'Usage-based pricing',+ '100,000 monthly active users included',+ 'Organization member roles (ABAC)',+ 'Standardised Security Questionnaire',+ 'SOC2',+ 'SSO for Supabase Dashboard',+ 'Priority email support & SLAs',+ '1 XS compute instance',+ '14 day backups',+ '28 day log retention',+ ],+ scale: '',+ shutdown: '',+ additional: '',+ cta: 'Get Started',+ },Enterprise: {name: 'Enterprise',href: '/contact/enterprise',diff --git a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsxindex caf3f42a7d1..a08e0b5b14c 100644--- a/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx+++ b/studio/components/interfaces/Billing/PlanSelection/Plans/Plans.tsx@@ -6,17 +6,11 @@ import { StripeProduct } from 'components/interfaces/Billing'import PlanCTAButton from './PlanCTAButton'import { PRICING_META } from './Plans.Constants'-interface Props {- plans: any[]- currentPlan?: StripeProduct- onSelectPlan: (plan: any) => void-}-const AnimatedGradientBackground = () => (<divclassName={['absolute top-0 left-0 h-full w-full animate-sway',- 'bg-gradient-to-b from-transparent via-transparent to-green-800',+ 'bg-gradient-to-b from-transparent via-transparent to-green-900',].join(' ')}/>)@@ -34,6 +28,12 @@ const CurrentSubscriptionBanner = () => (</div>)+interface Props {+ plans: any[]+ currentPlan?: StripeProduct+ onSelectPlan: (plan: any) => void+}+/*** JSX below for the mapped plans is also very similar to www/pages/pricing* TO DO: move to use shared components for these@@ -44,6 +44,7 @@ const CurrentSubscriptionBanner = () => (const Plans: FC<Props> = ({ plans, currentPlan, onSelectPlan }) => {return (<>+ {/* Existing available plans */}{plans.map((plan) => {const isCurrentPlan =plan.id === currentPlan?.prod_id ||@@ -59,7 +60,7 @@ const Plans: FC<Props> = ({ plans, currentPlan, onSelectPlan }) => {)}<div className="flex h-full flex-col overflow-hidden rounded border">{isCurrentPlan && <CurrentSubscriptionBanner />}- <div className="bg-white px-8 py-6 dark:bg-scale-300">+ <div className="bg-white px-6 py-6 dark:bg-scale-300"><spanclassName="text-cd inline-flex rounded-full text-base font-normal tracking-wide text-scale-1200"id="tier-standard"@@ -70,20 +71,18 @@ const Plans: FC<Props> = ({ plans, currentPlan, onSelectPlan }) => {<div className="flex space-x-2">{PRICING_META[plan.id].priceMonthly !== undefined ? (<>- <div className="flex items-end gap-1">+ <div>{PRICING_META[plan.id].from && (- <span className="text-base font-medium text-scale-1200">From</span>+ <span className="text-sm font-medium text-scale-1200 mr-1">From</span>)}- <div>- <span className="text-2xl">${PRICING_META[plan.id].priceMonthly}</span>- <span className="ml-1 text-xl font-medium text-scale-900">/mo</span>- </div>+ <span className="text-2xl">${PRICING_META[plan.id].priceMonthly}</span>+ <span className="text-xl font-medium text-scale-900">/mo</span></div></>) : (<span className="text-2xl">Contact Us</span>)}- <div className="flex h-8">+ <div className="flex h-8 -mt-[2px]">{PRICING_META[plan.id].warning && (<div className="mt-2 rounded-md bg-brand-300 bg-opacity-30 px-2 py-1 text-xs text-brand-1000">{PRICING_META[plan.id].warning}@@ -106,26 +105,30 @@ const Plans: FC<Props> = ({ plans, currentPlan, onSelectPlan }) => {'flex-1 flex-col justify-between','space-y-6 border-t dark:border-scale-400','bg-scale-100 dark:bg-scale-300',- 'hidden h-full px-8 py-6 lg:flex',+ 'hidden h-full px-6 py-6 lg:flex',].join(' ')}>- {PRICING_META[plan.id].preface && (- <p className="text-sm text-scale-1200">{PRICING_META[plan.id].preface}</p>- )}- <ul role="list" className="divide-y dark:divide-scale-400">- {PRICING_META[plan.id].features.map((feature) => (- <li key={feature} className="flex items-center py-2">- <IconCheck- className="h-3 w-3 text-brand-900 "- aria-hidden="true"- strokeWidth={3}- />- <p className="mb-0 ml-3 text-xs text-scale-1100 dark:text-scale-1200">- {feature}- </p>- </li>- ))}- </ul>+ <div className="space-y-6">+ {PRICING_META[plan.id].preface && (+ <p className="text-sm text-scale-1200">{PRICING_META[plan.id].preface}</p>+ )}+ <ul role="list" className="divide-y dark:divide-scale-400">+ {PRICING_META[plan.id].features.map((feature) => (+ <li key={feature} className="flex py-2">+ <div className="w-[12px]">+ <IconCheck+ className="h-3 w-3 text-brand-900 translate-y-[2.5px]"+ aria-hidden="true"+ strokeWidth={3}+ />+ </div>+ <p className="mb-0 ml-3 text-xs text-scale-1100 dark:text-scale-1200">+ {feature}+ </p>+ </li>+ ))}+ </ul>+ </div><div className="flex flex-col gap-6"><div className="space-y-2">{PRICING_META[plan.id].additional && (diff --git a/studio/components/interfaces/Billing/TeamUpgrade.tsx b/studio/components/interfaces/Billing/TeamUpgrade.tsxnew file mode 100644index 00000000000..7cc18e7847a--- /dev/null+++ b/studio/components/interfaces/Billing/TeamUpgrade.tsx@@ -0,0 +1,348 @@+import { FC, useEffect, useRef, useState } from 'react'+import { Transition } from '@headlessui/react'+import { useRouter } from 'next/router'++import { useStore, useFlag } from 'hooks'+import { post, patch } from 'lib/common/fetch'+import { API_URL, PROJECT_STATUS } from 'lib/constants'+import { getURL } from 'lib/helpers'+import Divider from 'components/ui/Divider'+import {+ PaymentSummaryPanel,+ ComputeSizeSelection,+ PITRDurationSelection,+ CustomDomainSelection,+ StripeSubscription,+ AddNewPaymentMethodModal,+} from './'+import { STRIPE_PRODUCT_IDS } from 'lib/constants'+import UpdateSuccess from './UpdateSuccess'+import { PaymentMethod, SubscriptionPreview } from './Billing.types'+import { formSubscriptionUpdatePayload, getCurrentAddons } from './Billing.utils'+import { SubscriptionAddon } from './AddOns/AddOns.types'+import {+ formatComputeSizes,+ formatCustomDomainOptions,+ formatPITROptions,+} from './AddOns/AddOns.utils'+import BackButton from 'components/ui/BackButton'+import SupportPlan from './AddOns/SupportPlan'+import HCaptcha from '@hcaptcha/react-hcaptcha'++// Do not allow compute size changes for af-south-1++interface Props {+ products: { tiers: any[]; addons: SubscriptionAddon[] }+ paymentMethods?: PaymentMethod[]+ currentSubscription: StripeSubscription+ isLoadingPaymentMethods: boolean+ onSelectBack: () => void+}++const TeamUpgrade: FC<Props> = ({+ products,+ paymentMethods,+ currentSubscription,+ isLoadingPaymentMethods,+ onSelectBack,+}) => {+ const { app, ui } = useStore()+ const router = useRouter()+ const isCustomDomainsEnabled = useFlag('customDomains')+ const isPITRSelfServeEnabled = useFlag('pitrSelfServe')++ const [captchaToken, setCaptchaToken] = useState<string | null>(null)+ const captchaRef = useRef<HCaptcha>(null)++ const { addons } = products+ const computeSizes = formatComputeSizes(addons)+ const pitrDurationOptions = formatPITROptions(addons)+ const customDomainOptions = formatCustomDomainOptions(addons)+ const currentAddons = getCurrentAddons(currentSubscription, addons)++ const projectId = ui.selectedProject?.id ?? -1+ const projectRef = ui.selectedProject?.ref+ const projectRegion = ui.selectedProject?.region ?? ''++ const [isRefreshingPreview, setIsRefreshingPreview] = useState(false)+ const [isSubmitting, setIsSubmitting] = useState(false)+ const [isSuccessful, setIsSuccessful] = useState(false)+ const [showAddPaymentMethodModal, setShowAddPaymentMethodModal] = useState(false)++ // [Joshen TODO] Ideally we just have a state to hold all the add ons selection, rather than individual+ // Even better if we can just use the <Form> component to handle all of these. Mainly to reduce the amount+ // of unnecessary state management on this complex page.+ const [selectedComputeSize, setSelectedComputeSize] = useState<SubscriptionAddon>(+ currentAddons.computeSize+ )+ const [selectedPITRDuration, setSelectedPITRDuration] = useState<SubscriptionAddon>(+ currentAddons.pitrDuration+ )+ const [selectedCustomDomainOption, setSelectedCustomDomainOption] = useState<SubscriptionAddon>(+ currentAddons.customDomains+ )++ // [Joshen TODO] Future - We may need to also include any add ons outside of+ // compute size, pitr, custom domain and support plan, although we dont have any now+ const nonChangeableAddons = [currentAddons.supportPlan].filter(+ (x) => x !== undefined+ ) as SubscriptionAddon[]++ // [Joshen] Scaffolded here+ const selectedAddons = {+ computeSize: selectedComputeSize,+ pitrDuration: selectedPITRDuration,+ customDomains: selectedCustomDomainOption,+ }++ const [selectedPaymentMethodId, setSelectedPaymentMethodId] = useState<string>('')+ const [subscriptionPreview, setSubscriptionPreview] = useState<SubscriptionPreview>()++ const selectedTier = products?.tiers.find((tier: any) => tier.id === STRIPE_PRODUCT_IDS.TEAM)++ const isManagingTeamSubscription = currentSubscription.tier.prod_id === STRIPE_PRODUCT_IDS.TEAM++ const isChangingComputeSize = currentAddons.computeSize?.id !== selectedAddons.computeSize.id++ useEffect(() => {+ if (!isLoadingPaymentMethods && paymentMethods && paymentMethods.length > 0) {+ setSelectedPaymentMethodId(paymentMethods[0].id)+ }+ }, [isLoadingPaymentMethods, paymentMethods])++ useEffect(() => {+ getSubscriptionPreview()+ }, [selectedComputeSize, selectedPITRDuration, selectedCustomDomainOption])++ const getSubscriptionPreview = async () => {+ const payload = formSubscriptionUpdatePayload(+ currentSubscription,+ selectedTier,+ selectedAddons,+ nonChangeableAddons,+ selectedPaymentMethodId,+ projectRegion+ )++ setIsRefreshingPreview(true)+ const preview = await post(`${API_URL}/projects/${projectRef}/subscription/preview`, payload)+ if (preview.error) {+ ui.setNotification({+ category: 'error',+ message: `Failed to fetch subscription preview: ${preview.error.message}`,+ })+ }+ setSubscriptionPreview(preview)+ setIsRefreshingPreview(false)+ }++ const resetCaptcha = () => {+ setCaptchaToken(null)+ captchaRef.current?.resetCaptcha()+ }++ const beforeConfirmPayment = async (): Promise<boolean> => {+ setIsSubmitting(true)+ let token = captchaToken++ try {+ if (!token) {+ const captchaResponse = await captchaRef.current?.execute({ async: true })+ token = captchaResponse?.response ?? null+ setCaptchaToken(token)+ }+ } catch (error) {+ setIsSubmitting(false)+ return false+ }++ setIsSubmitting(false)+ return true+ }++ const teamTierEnabled = useFlag('teamTier')++ const onConfirmPayment = async () => {+ if (!teamTierEnabled) {+ return ui.setNotification({+ category: 'error',+ message: 'Team Plan is not enabled yet.',+ })+ }+ const payload = formSubscriptionUpdatePayload(+ currentSubscription,+ selectedTier,+ selectedAddons,+ nonChangeableAddons,+ selectedPaymentMethodId,+ projectRegion+ )+ const res = await patch(`${API_URL}/projects/${projectRef}/subscription`, payload)+ resetCaptcha()++ if (res?.error) {+ ui.setNotification({+ category: 'error',+ message: `Failed to update subscription: ${res?.error?.message}`,+ })+ } else {+ if (isChangingComputeSize) {+ app.onProjectStatusUpdated(projectId, PROJECT_STATUS.RESTORING)+ ui.setNotification({+ category: 'success',+ message:+ 'Your project has been updated and is currently restarting to update its instance size',+ duration: 8000,+ })+ router.push(`/project/${projectRef}`)+ } else {+ setIsSuccessful(true)+ }+ }+ setIsSubmitting(false)+ }++ if (!isSubmitting && isSuccessful) {+ return (+ <UpdateSuccess+ projectRef={projectRef || ''}+ title="Your project has been updated!"+ message="Let us know if you have any feedback at [email protected]."+ />+ )+ }++ return (+ <>+ <Transition+ show+ enter="transition ease-out duration-300"+ enterFrom="transform opacity-0 translate-x-10"+ enterTo="transform opacity-100 translate-x-0"+ className="flex items-start justify-between w-full"+ >+ <div className="flex-grow mt-10">+ <div className="relative space-y-4">+ <div className="px-32 mx-auto space-y-4 2xl:min-w-5xl">+ <BackButton onClick={() => onSelectBack()} />+ <h4 className="text-lg text-scale-900 !mb-8">Change your project's subscription</h4>+ </div>++ <div+ className="px-32 pb-8 mx-auto space-y-8 overflow-y-auto 2xl:min-w-5xl"+ style={{ height: 'calc(100vh - 9rem - 57px)' }}+ >+ <div className="space-y-2">+ {!isManagingTeamSubscription ? (+ <>+ <h3 className="text-xl">+ Welcome to <span className="text-brand-900">Team</span>+ </h3>+ <p className="text-base text-scale-1100">+ Your new subscription will begin immediately after payment+ </p>+ </>+ ) : (+ <>+ <h3 className="text-3xl">+ Managing your <span className="text-brand-900">Team</span> plan+ </h3>+ </>+ )}+ </div>++ {projectRegion !== 'af-south-1' && (+ <>+ {currentAddons.supportPlan !== undefined && (+ <>+ <Divider light />+ <SupportPlan currentOption={currentAddons.supportPlan} />+ </>+ )}+ {isCustomDomainsEnabled && customDomainOptions.length > 0 && (+ <>+ <Divider light />+ <CustomDomainSelection+ options={customDomainOptions}+ currentOption={+ isManagingTeamSubscription ? currentAddons.customDomains : undefined+ }+ selectedOption={selectedAddons.customDomains}+ onSelectOption={setSelectedCustomDomainOption}+ />+ </>+ )}+ {isPITRSelfServeEnabled && pitrDurationOptions.length > 0 && (+ <>+ <Divider light />+ <PITRDurationSelection+ pitrDurationOptions={pitrDurationOptions}+ currentPitrDuration={+ isManagingTeamSubscription ? currentAddons.pitrDuration : undefined+ }+ selectedPitrDuration={selectedAddons.pitrDuration}+ onSelectOption={setSelectedPITRDuration}+ />+ </>+ )}+ <Divider light />+ <ComputeSizeSelection+ computeSizes={computeSizes || []}+ currentComputeSize={currentAddons.computeSize}+ selectedComputeSize={selectedAddons.computeSize}+ onSelectOption={setSelectedComputeSize}+ />+ </>+ )}+ </div>+ </div>+ </div>+ <div className="w-[34rem]">+ <PaymentSummaryPanel+ isRefreshingPreview={isRefreshingPreview}+ subscriptionPreview={subscriptionPreview}+ isSpendCapEnabled={false}+ // Current subscription configuration based on DB+ currentPlan={currentSubscription.tier}+ currentAddons={currentAddons}+ currentSubscription={currentSubscription}+ // Selected subscription configuration based on UI+ selectedPlan={selectedTier}+ selectedAddons={selectedAddons}+ paymentMethods={paymentMethods}+ isLoadingPaymentMethods={isLoadingPaymentMethods}+ selectedPaymentMethod={selectedPaymentMethodId}+ onSelectPaymentMethod={setSelectedPaymentMethodId}+ onSelectAddNewPaymentMethod={() => {+ setShowAddPaymentMethodModal(true)+ }}+ beforeConfirmPayment={beforeConfirmPayment}+ onConfirmPayment={onConfirmPayment}+ isSubmitting={isSubmitting}+ captcha={+ <HCaptcha+ ref={captchaRef}+ sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}+ size="invisible"+ onVerify={(token) => {+ setCaptchaToken(token)+ }}+ onExpire={() => {+ setCaptchaToken(null)+ }}+ />+ }+ />+ </div>+ </Transition>++ <AddNewPaymentMethodModal+ visible={showAddPaymentMethodModal}+ returnUrl={`${getURL()}/project/${projectRef}/settings/billing/update/team`}+ onCancel={() => setShowAddPaymentMethodModal(false)}+ />+ </>+ )+}++export default TeamUpgradediff --git a/studio/components/interfaces/Settings/Logs/Logs.constants.ts b/studio/components/interfaces/Settings/Logs/Logs.constants.tsindex b3daf72b8de..a859c9d7406 100644--- a/studio/components/interfaces/Settings/Logs/Logs.constants.ts+++ b/studio/components/interfaces/Settings/Logs/Logs.constants.ts@@ -631,5 +631,6 @@ export const TIER_QUERY_LIMITS: {FREE: { text: '1 day', value: 1, unit: 'day', promptUpgrade: true },PRO: { text: '7 days', value: 7, unit: 'day', promptUpgrade: true },PAYG: { text: '90 days', value: 90, unit: 'day', promptUpgrade: false },+ TEAM: { text: '90 days', value: 90, unit: 'day', promptUpgrade: false },ENTERPRISE: { text: '90 days', value: 90, unit: 'day', promptUpgrade: false },}diff --git a/studio/components/interfaces/Settings/Logs/Logs.utils.ts b/studio/components/interfaces/Settings/Logs/Logs.utils.tsindex c989eba5d64..d039b002740 100644--- a/studio/components/interfaces/Settings/Logs/Logs.utils.ts+++ b/studio/components/interfaces/Settings/Logs/Logs.utils.ts@@ -173,16 +173,22 @@ export const genSingleLogQuery = (table: LogsTableName, id: string) =>*/export const maybeShowUpgradePrompt = (from: string | null | undefined,- tierKey?: StripeSubscription['tier']["key"]+ tierKey?: StripeSubscription['tier']['key']) => {const day = Math.abs(dayjs().diff(dayjs(from), 'day'))- return (day > 1 && tierKey === 'FREE') || (day > 7 && tierKey === 'PRO') || day > 90 && tierKey === 'ENTERPRISE'+ return (+ (day > 1 && tierKey === 'FREE') ||+ (day > 7 && tierKey === 'PRO') ||+ (day > 28 && tierKey === 'TEAM') ||+ (day > 90 && tierKey === 'ENTERPRISE')+ )}export const genCountQuery = (table: LogsTableName, filters: Filters): string => {const where = _genWhereStatement(table, filters)- return `SELECT count(*) as count FROM ${table} ${where}`}+ return `SELECT count(*) as count FROM ${table} ${where}`+}/** calculates how much the chart start datetime should be offset given the current datetime filter params */export const calcChartStart = (params: Partial<LogsEndpointParams>): [Dayjs, string] => {@@ -224,10 +230,11 @@ SELECTFROM${table} tcross join unnest(t.metadata) as metadata- ${where+ ${+ where? where + ` and t.timestamp > '${startOffset.toISOString()}'`: `where t.timestamp > '${startOffset.toISOString()}'`- }+ }GROUP BYtimestampORDER BYdiff --git a/studio/components/interfaces/Settings/Logs/UpgradePrompt.tsx b/studio/components/interfaces/Settings/Logs/UpgradePrompt.tsxindex efc906ed4c6..f6351377d9d 100644--- a/studio/components/interfaces/Settings/Logs/UpgradePrompt.tsx+++ b/studio/components/interfaces/Settings/Logs/UpgradePrompt.tsx@@ -3,6 +3,7 @@ import { Button, Modal } from 'ui'import { TIER_QUERY_LIMITS } from '.'import Link from 'next/link'import { useRouter } from 'next/router'+import { useFlag } from 'hooks'interface Props {show: boolean@@ -13,6 +14,8 @@ const UpgradePrompt: React.FC<Props> = ({ show, setShowUpgradePrompt }) => {const router = useRouter()const { ref } = router.query+ const teamTierEnabled = useFlag('teamTier')+return (<ModalhideFooter@@ -43,6 +46,12 @@ const UpgradePrompt: React.FC<Props> = ({ show, setShowUpgradePrompt }) => {<p className="w-[40%] text-sm">Pro</p><p className="w-[60%] text-sm">{TIER_QUERY_LIMITS.PRO.text}</p></div>+ {teamTierEnabled && (+ <div className="flex items-center px-4 py-1">+ <p className="w-[40%] text-sm">Team</p>+ <p className="w-[60%] text-sm">{TIER_QUERY_LIMITS.TEAM.text}</p>+ </div>+ )}<div className="flex items-center px-4 py-1"><p className="w-[40%] text-sm">Enterprise</p><p className="w-[60%] text-sm">{TIER_QUERY_LIMITS.ENTERPRISE.text}</p>diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsxindex cd06e465b3d..a282bae88e9 100644--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx@@ -23,6 +23,7 @@ const ProjectUsage: FC<Props> = ({ projectRef }) => {const projectHasNoLimits =subscriptionTier === PRICING_TIER_PRODUCT_IDS.PAYG ||+ subscriptionTier === PRICING_TIER_PRODUCT_IDS.TEAM ||subscriptionTier === PRICING_TIER_PRODUCT_IDS.ENTERPRISEconst showUsageExceedMessage = subscriptionTier !== undefined && !projectHasNoLimits@@ -31,6 +32,7 @@ const ProjectUsage: FC<Props> = ({ projectRef }) => {[PRICING_TIER_PRODUCT_IDS.FREE]: 'Free',[PRICING_TIER_PRODUCT_IDS.PRO]: 'Pro',[PRICING_TIER_PRODUCT_IDS.PAYG]: 'Pro',+ [PRICING_TIER_PRODUCT_IDS.TEAM]: 'Team',[PRICING_TIER_PRODUCT_IDS.ENTERPRISE]: 'Enterprise',}diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsxindex b541753edb0..aba20873737 100644--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx@@ -20,7 +20,8 @@ const ProjectUsageMinimal: FC<ProjectUsageMinimalProps> = ({ projectRef, filterif (subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.PAYG ||- subscription?.tier.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.ENTERPRISE+ subscription?.tier.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.ENTERPRISE ||+ subscription?.tier.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.TEAM) {return <></>}diff --git a/studio/components/interfaces/Support/SupportForm.tsx b/studio/components/interfaces/Support/SupportForm.tsxindex f0dbaf22e0a..5b910242968 100644--- a/studio/components/interfaces/Support/SupportForm.tsx+++ b/studio/components/interfaces/Support/SupportForm.tsx@@ -59,6 +59,7 @@ const SupportForm: FC<Props> = ({ setSentCategory }) => {[PRICING_TIER_PRODUCT_IDS.FREE]: 'Free',[PRICING_TIER_PRODUCT_IDS.PRO]: 'Pro',[PRICING_TIER_PRODUCT_IDS.PAYG]: 'Pro',+ [PRICING_TIER_PRODUCT_IDS.TEAM]: 'Team',[PRICING_TIER_PRODUCT_IDS.ENTERPRISE]: 'Enterprise',}diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsxindex e2ced0a184f..7a747d206d3 100644--- a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx@@ -23,7 +23,8 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder =const resourcesExceededLimits = getResourcesExceededLimits(usage)const projectHasNoLimits =ui.selectedProject?.subscription_tier === PRICING_TIER_PRODUCT_IDS.PAYG ||- ui.selectedProject?.subscription_tier === PRICING_TIER_PRODUCT_IDS.ENTERPRISE+ ui.selectedProject?.subscription_tier === PRICING_TIER_PRODUCT_IDS.ENTERPRISE ||+ ui.selectedProject?.subscription_tier === PRICING_TIER_PRODUCT_IDS.TEAMconst showOverUsageBadge =selectedProject?.subscription_tier !== undefined &&!projectHasNoLimits &&diff --git a/studio/components/ui/OveragesBanner/OveragesBanner.tsx b/studio/components/ui/OveragesBanner/OveragesBanner.tsxindex d12517d9ad8..56430ff1155 100644--- a/studio/components/ui/OveragesBanner/OveragesBanner.tsx+++ b/studio/components/ui/OveragesBanner/OveragesBanner.tsx@@ -30,7 +30,8 @@ const OveragesBanner: FC<Props> = ({ tier, minimal }) => {error ||(!isApproachingUsageLimits && !isOverUsageLimits) ||tier === PRICING_TIER_PRODUCT_IDS.PAYG ||- tier === PRICING_TIER_PRODUCT_IDS.ENTERPRISE+ tier === PRICING_TIER_PRODUCT_IDS.ENTERPRISE ||+ tier === PRICING_TIER_PRODUCT_IDS.TEAM) {return <></>}diff --git a/studio/hooks/queries/index.ts b/studio/hooks/queries/index.tsindex b93e9618493..4582c19b2fb 100644--- a/studio/hooks/queries/index.ts+++ b/studio/hooks/queries/index.ts@@ -7,6 +7,5 @@ export * from './useProfile'export * from './useProjectAuthConfig'export * from './useProjectSettings'export * from './useProjectSubscription'-export * from './useSubscriptionStats'export * from './useProjectUsage'export * from './useProjectPostgrestConfig'diff --git a/studio/hooks/queries/useSubscriptionStats.ts b/studio/hooks/queries/useSubscriptionStats.tsdeleted file mode 100644index e109b160077..00000000000--- a/studio/hooks/queries/useSubscriptionStats.ts+++ /dev/null@@ -1,29 +0,0 @@-import useSWR, { mutate } from 'swr'-import { get } from 'lib/common/fetch'-import { API_URL } from 'lib/constants'--export interface SubscriptionStats {- total_paid_projects: number- total_free_projects: number- total_active_free_projects: number- total_paused_free_projects: number- total_pro_projects: number- total_payg_projects: number-}--export function useSubscriptionStats() {- const url = `${API_URL}/profile/subscriptions`- const { data, error } = useSWR<any>(url, get)- const anyError = data?.error || error-- return {- total_paid_projects: data?.total_paid_projects ?? 0,- total_free_projects: data?.total_free_projects ?? 0,- total_active_free_projects: data?.total_active_free_projects ?? 0,- total_paused_free_projects: data?.total_paused_free_projects ?? 0,- total_pro_projects: data?.total_pro_projects ?? 0,- total_payg_projects: data?.total_payg_projects ?? 0,- isLoading: !anyError && !data,- isError: !!anyError,- }-}diff --git a/studio/lib/constants/infrastructure.ts b/studio/lib/constants/infrastructure.tsindex 827aac12039..5c4e675ec05 100644--- a/studio/lib/constants/infrastructure.ts+++ b/studio/lib/constants/infrastructure.ts@@ -30,6 +30,7 @@ export const PRICING_TIER_PRODUCT_IDS = {FREE: 'tier_free',PRO: 'tier_pro',PAYG: 'tier_payg',+ TEAM: 'tier_team',ENTERPRISE: 'tier_enterprise',}@@ -112,6 +113,7 @@ export const STRIPE_PRODUCT_IDS: { [x: string]: string } = {FREE: process?.env?.NEXT_PUBLIC_STRIPE_FREE_TIER_ID || 'prod_Ip4vqwv3EJ7Mi0',PRO: process?.env?.NEXT_PUBLIC_STRIPE_PRO_TIER_ID || 'prod_IsRLOp58Z7V4XN',PAYG: process?.env?.NEXT_PUBLIC_STRIPE_PAYG_TIER_ID || 'prod_JlTbw91xcM6NY4',+ TEAM: process?.env?.NEXT_PUBLIC_STRIPE_TEAM_TIER_ID || 'prod_MeUrsWN6pj0oXM',}export const DEFAULT_MINIMUM_PASSWORD_STRENGTH = 4diff --git a/studio/pages/api/props/org/[slug].tsx b/studio/pages/api/props/org/[slug].tsxindex 3f56758edeb..f0b13bf1b61 100644--- a/studio/pages/api/props/org/[slug].tsx+++ b/studio/pages/api/props/org/[slug].tsx@@ -1,6 +1,5 @@import { NextApiRequest, NextApiResponse } from 'next'import apiWrapper from 'lib/api/apiWrapper'-import { Member } from 'types'export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)@@ -27,6 +26,7 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {total_paid_projects: 0,total_free_projects: 0,total_pro_projects: 0,+ total_team_projects: 0,total_payg_projects: 0,},}diff --git a/studio/pages/new/[slug].tsx b/studio/pages/new/[slug].tsxindex 0578455f4f4..fb677f75a92 100644--- a/studio/pages/new/[slug].tsx+++ b/studio/pages/new/[slug].tsx@@ -25,7 +25,6 @@ import {useStore,useFlag,withAuth,- useSubscriptionStats,checkPermissions,useFreeProjectLimitCheck,} from 'hooks'@@ -47,7 +46,6 @@ const Wizard: NextPageWithLayout = () => {const projectCreationDisabled = useFlag('disableProjectCreationAndUpdate')const kpsEnabled = useFlag('initWithKps')- const subscriptionStats = useSubscriptionStats()const { membersExceededLimit, isLoading: isLoadingFreeProjectLimitCheck } =useFreeProjectLimitCheck(slug as string)@@ -74,10 +72,7 @@ const Wizard: NextPageWithLayout = () => {const hasMembersExceedingFreeTierLimit = (membersExceededLimit || []).length > 0const canCreateProject =- isAdmin &&- !subscriptionStats.isError &&- !subscriptionStats.isLoading &&- (!isSelectFreeTier || (isSelectFreeTier && !hasMembersExceedingFreeTierLimit))+ isAdmin && (!isSelectFreeTier || (isSelectFreeTier && !hasMembersExceedingFreeTierLimit))const canSubmit =projectName !== '' &&@@ -204,7 +199,6 @@ const Wizard: NextPageWithLayout = () => {hideHeaderStylingloading={!app.organizations.isInitialized ||- subscriptionStats.isLoading ||isLoadingFreeProjectLimitCheck}title={diff --git a/studio/pages/project/[ref]/settings/billing/update/index.tsx b/studio/pages/project/[ref]/settings/billing/update/index.tsxindex 70859ccf8dd..608bda83c06 100644--- a/studio/pages/project/[ref]/settings/billing/update/index.tsx+++ b/studio/pages/project/[ref]/settings/billing/update/index.tsx@@ -3,7 +3,7 @@ import { useRouter } from 'next/router'import { observer } from 'mobx-react-lite'import { Button, Modal } from 'ui'-import { useFreeProjectLimitCheck, useStore } from 'hooks'+import { useFlag, useFreeProjectLimitCheck, useStore } from 'hooks'import { get } from 'lib/common/fetch'import { API_URL, PRICING_TIER_PRODUCT_IDS, STRIPE_PRODUCT_IDS } from 'lib/constants'@@ -85,6 +85,8 @@ const BillingUpdate: NextPageWithLayout = () => {const onSelectPlan = (plan: any) => {if (plan.id === STRIPE_PRODUCT_IDS.PRO) {router.push(`/project/${projectRef}/settings/billing/update/pro`)+ } else if (plan.id === STRIPE_PRODUCT_IDS.TEAM) {+ router.push(`/project/${projectRef}/settings/billing/update/team`)} else if (plan.id === STRIPE_PRODUCT_IDS.FREE) {setSelectedPlan(plan)setShowConfirmDowngrade(true)@@ -109,12 +111,18 @@ const BillingUpdate: NextPageWithLayout = () => {)}+ const teamTierEnabled = useFlag('teamTier')++ const productTiers = (products?.tiers ?? []).filter(+ (tier) => teamTierEnabled || tier.id !== STRIPE_PRODUCT_IDS.TEAM+ )+return (<>- <div className="mx-auto my-10 max-w-6xl px-6">+ <div className={`mx-auto my-10 ${teamTierEnabled ? 'max-w-[90vw]' : 'max-w-[80vw]'}`}><PlanSelectionvisible={!selectedPlan || (selectedPlan && showConfirmDowngrade)}- tiers={products?.tiers ?? []}+ tiers={productTiers}currentPlan={subscription?.tier}onSelectPlan={onSelectPlan}/>diff --git a/studio/pages/project/[ref]/settings/billing/update/team.tsx b/studio/pages/project/[ref]/settings/billing/update/team.tsxnew file mode 100644index 00000000000..00590a7e98d--- /dev/null+++ b/studio/pages/project/[ref]/settings/billing/update/team.tsx@@ -0,0 +1,132 @@+import { useState, useEffect } from 'react'+import { observer } from 'mobx-react-lite'+import { useRouter } from 'next/router'++import { useStore, useFlag } from 'hooks'+import { get } from 'lib/common/fetch'+import { API_URL, PRICING_TIER_PRODUCT_IDS } from 'lib/constants'++import { NextPageWithLayout } from 'types'+import { BillingLayout } from 'components/layouts'+import Connecting from 'components/ui/Loading/Loading'+import { StripeSubscription } from 'components/interfaces/Billing'+import { PaymentMethod } from 'components/interfaces/Billing/Billing.types'+import { SubscriptionAddon } from 'components/interfaces/Billing/AddOns/AddOns.types'+import TeamUpgrade from 'components/interfaces/Billing/TeamUpgrade'++const BillingUpdateTeam: NextPageWithLayout = () => {+ const { ui } = useStore()+ const router = useRouter()++ const projectRef = ui.selectedProject?.ref+ const orgSlug = ui.selectedOrganization?.slug++ const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')++ const [subscription, setSubscription] = useState<StripeSubscription>()+ const [products, setProducts] = useState<{ tiers: any[]; addons: SubscriptionAddon[] }>()+ const [paymentMethods, setPaymentMethods] = useState<PaymentMethod[]>()+ const [isLoadingPaymentMethods, setIsLoadingPaymentMethods] = useState(false)++ const isEnterprise =+ subscription && subscription.tier.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.ENTERPRISE++ useEffect(() => {+ // User added a new payment method+ if (router.query.setup_intent && router.query.redirect_status) {+ ui.setNotification({ category: 'success', message: 'Successfully added new payment method' })+ }+ }, [])++ useEffect(() => {+ if (projectUpdateDisabled) {+ router.push(`/project/${projectRef}/settings/billing/update`)+ } else if (projectRef) {+ getStripeProducts()+ getSubscription()+ }+ }, [projectRef])++ useEffect(() => {+ if (orgSlug) {+ getPaymentMethods()+ }+ }, [orgSlug])++ useEffect(() => {+ if (isEnterprise) {+ router.push(`/project/${projectRef}/settings/billing/update/enterprise`)+ }+ }, [subscription])++ const getStripeProducts = async () => {+ try {+ const products = await get(`${API_URL}/stripe/products`)+ setProducts(products)+ } catch (error: any) {+ ui.setNotification({+ error,+ category: 'error',+ message: `Failed to get products: ${error.message}`,+ })+ }+ }++ const getPaymentMethods = async () => {+ const orgSlug = ui.selectedOrganization?.slug ?? ''+ try {+ setIsLoadingPaymentMethods(true)+ const { data: paymentMethods, error } = await get(+ `${API_URL}/organizations/${orgSlug}/payments`+ )+ if (error) throw error+ setIsLoadingPaymentMethods(false)+ setPaymentMethods(paymentMethods)+ } catch (error: any) {+ ui.setNotification({+ error,+ category: 'error',+ message: `Failed to get available payment methods: ${error.message}`,+ })+ }+ }++ const getSubscription = async () => {+ try {+ if (!ui.selectedProject?.subscription_id) {+ throw new Error('Unable to get subscription ID of project')+ }++ const subscription = await get(`${API_URL}/projects/${projectRef}/subscription`)+ if (subscription.error) throw subscription.error+ setSubscription(subscription)+ } catch (error: any) {+ ui.setNotification({+ error,+ category: 'error',+ message: `Failed to get subscription: ${error.message}`,+ })+ }+ }++ if (!products || !subscription || isEnterprise)+ return (+ <div className="flex h-full w-full items-center justify-center">+ <Connecting />+ </div>+ )++ return (+ <TeamUpgrade+ products={products}+ currentSubscription={subscription}+ isLoadingPaymentMethods={isLoadingPaymentMethods}+ paymentMethods={paymentMethods || []}+ onSelectBack={() => router.push(`/project/${projectRef}/settings/billing/update`)}+ />+ )+}++BillingUpdateTeam.getLayout = (page) => <BillingLayout>{page}</BillingLayout>++export default observer(BillingUpdateTeam)diff --git a/studio/tests/pages/projects/LogsPreviewer.test.js b/studio/tests/pages/projects/LogsPreviewer.test.jsindex 0b8420e9c14..7d2f9e7ce45 100644--- a/studio/tests/pages/projects/LogsPreviewer.test.js+++ b/studio/tests/pages/projects/LogsPreviewer.test.js@@ -421,7 +421,7 @@ test('filters accept filterOverride', async () => {})})-describe.each(['FREE', 'PRO', 'ENTERPRISE'])('upgrade modal for %s', (key) => {+describe.each(['FREE', 'PRO', 'TEAM', 'ENTERPRISE'])('upgrade modal for %s', (key) => {beforeEach(() => {useProjectSubscription.mockReturnValue({subscription: {diff --git a/studio/tests/pages/projects/logs-query.test.js b/studio/tests/pages/projects/logs-query.test.jsindex 3ae3b637d34..8daa2301ca3 100644--- a/studio/tests/pages/projects/logs-query.test.js+++ b/studio/tests/pages/projects/logs-query.test.js@@ -151,7 +151,7 @@ test('query warnings', async () => {await screen.findByText('1 warning')})-describe.each(['FREE', 'PRO', 'ENTERPRISE'])('upgrade modal for %s', (key) => {+describe.each(['FREE', 'PRO', 'TEAM', 'ENTERPRISE'])('upgrade modal for %s', (key) => {beforeEach(() => {useProjectSubscription.mockReturnValue({subscription: {