The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update the warning message for exceeding free project limit based on updated logic from api on multiple owners and admin
Joshen Limbd46603fce8f
diff --git a/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsx b/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsxindex 506b50e2370..046f156a87d 100644--- a/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsx+++ b/studio/components/interfaces/Organization/NewProject/FreeProjectLimitWarning.tsx@@ -1,23 +1,37 @@import { FC } from 'react'import { IconAlertCircle } from 'ui'import InformationBox from 'components/ui/InformationBox'+import { MemberWithFreeProjectLimit } from 'hooks'interface Props {- limit: number+ members: MemberWithFreeProjectLimit[]}-const FreeProjectLimitWarning: FC<Props> = ({ limit }) => {+const FreeProjectLimitWarning: FC<Props> = ({ members }) => {return (<div className="mt-4"><InformationBoxicon={<IconAlertCircle className="text-scale-1200" size="large" strokeWidth={1.5} />}defaultVisibility={true}hideCollapse- title="Your account has reached its free project limit"+ title="The organization has members who have exceeded their free project limits"description={<div className="space-y-3"><p className="text-sm leading-normal">- {`Your account can only have up to ${limit} free projects - to create another free project, you'll need to delete or pause an existing free project first. Otherwise, you may create a project on the Pro tier instead.`}+ The following members have reached their maximum limits for the number of active free+ tier projects within organizations where they are an administrator or owner:+ </p>+ <ul className="list-disc pl-5">+ {members.map((member, idx: number) => (+ <li key={`member-${idx}`}>+ {member.username || member.primary_email} (Limit: {member.free_project_limit} free+ projects)+ </li>+ ))}+ </ul>+ <p className="text-sm leading-normal">+ These members will need to either delete, pause or upgrade one or more of these+ projects before you're able to create a free project within this organization.</p></div>}diff --git a/studio/hooks/queries/index.ts b/studio/hooks/queries/index.tsindex 2964ef05c56..53c6ca96435 100644--- a/studio/hooks/queries/index.ts+++ b/studio/hooks/queries/index.ts@@ -1,6 +1,7 @@export * from './useJwtSecretUpdateStatus'export * from './useOrganizationDetail'export * from './useOrganizationRoles'+export * from './useFreeProjectLimitCheck'export * from './usePermissions'export * from './useProfile'export * from './useProjectAuthConfig'diff --git a/studio/hooks/queries/useFreeProjectLimitCheck.ts b/studio/hooks/queries/useFreeProjectLimitCheck.tsnew file mode 100644index 00000000000..c56f45976f3--- /dev/null+++ b/studio/hooks/queries/useFreeProjectLimitCheck.ts@@ -0,0 +1,22 @@+import useSWR from 'swr'+import { get } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'++export interface MemberWithFreeProjectLimit {+ free_project_limit: number+ primary_email: string+ username: string+}++export function useFreeProjectLimitCheck(slug?: string) {+ const url = `${API_URL}/organizations/${slug}/members/reached-free-project-limit`+ const { data, error } = useSWR<any>(slug ? url : null, get)+ const anyError = data?.error || error++ return {+ members: anyError ? undefined : (data as MemberWithFreeProjectLimit[]),+ error: anyError,+ isLoading: !anyError && !data,+ isError: !!anyError,+ }+}diff --git a/studio/pages/new/[slug].tsx b/studio/pages/new/[slug].tsxindex 5785fe05861..a3c3475f4a2 100644--- a/studio/pages/new/[slug].tsx+++ b/studio/pages/new/[slug].tsx@@ -4,7 +4,7 @@ import { debounce, isUndefined, values } from 'lodash'import { toJS } from 'mobx'import { observer } from 'mobx-react-lite'import generator from 'generate-password'-import { Button, Listbox, IconUsers, Input, IconLoader, Alert } from 'ui'+import { Button, Listbox, IconUsers, Input, Alert } from 'ui'import { PermissionAction } from '@supabase/shared-types/out/constants'import { NextPageWithLayout } from 'types'@@ -19,10 +19,16 @@ import {PRICING_TIER_LABELS,PRICING_TIER_DEFAULT_KEY,PRICING_TIER_FREE_KEY,- DEFAULT_FREE_PROJECTS_LIMIT,PRICING_TIER_PRODUCT_IDS,} from 'lib/constants'-import { useStore, useFlag, withAuth, useSubscriptionStats, checkPermissions } from 'hooks'+import {+ useStore,+ useFlag,+ withAuth,+ useSubscriptionStats,+ checkPermissions,+ useFreeProjectLimitCheck,+} from 'hooks'import { WizardLayoutWithoutAuth } from 'components/layouts'import Panel from 'components/ui/Panel'@@ -43,6 +49,9 @@ const Wizard: NextPageWithLayout = () => {const projectCreationDisabled = useFlag('disableProjectCreationAndUpdate')const kpsEnabled = useFlag('initWithKps')const subscriptionStats = useSubscriptionStats()+ const { members, isLoading: isLoadingFreeProjectLimitCheck } = useFreeProjectLimitCheck(+ slug as string+ )const [projectName, setProjectName] = useState('')const [dbPass, setDbPass] = useState('')@@ -59,31 +68,29 @@ const Wizard: NextPageWithLayout = () => {const stripeCustomerId = currentOrg?.stripe_customer_idconst isOrganizationOwner = ui.selectedOrganization?.is_owner- const totalFreeProjects = subscriptionStats.total_active_free_projects- const freeProjectsLimit = ui.profile?.free_project_limit ?? DEFAULT_FREE_PROJECTS_LIMITconst availableRegions = getAvailableRegions()const isAdmin = enablePermissions? checkPermissions(PermissionAction.CREATE, 'projects'): isOrganizationOwner+ const isInvalidSlug = isUndefined(currentOrg)const isEmptyOrganizations = organizations.length <= 0 && app.organizations.isInitializedconst isEmptyPaymentMethod = paymentMethods ? !paymentMethods.length : false- const isOverFreeProjectLimit = totalFreeProjects >= freeProjectsLimit- const isInvalidSlug = isUndefined(currentOrg)const isSelectFreeTier = dbPricingTierKey === PRICING_TIER_FREE_KEY+ const hasMembersExceedingFreeTierLimit = (members || []).length > 0const canCreateProject =isAdmin &&!subscriptionStats.isError &&!subscriptionStats.isLoading &&- (!isSelectFreeTier || (isSelectFreeTier && !isOverFreeProjectLimit))+ (!isSelectFreeTier || (isSelectFreeTier && !hasMembersExceedingFreeTierLimit))const canSubmit =- projectName != '' &&+ projectName !== '' &&passwordStrengthScore >= DEFAULT_MINIMUM_PASSWORD_STRENGTH &&- dbRegion != '' &&- dbPricingTierKey != '' &&+ dbRegion !== '' &&+ dbPricingTierKey !== '' &&(isSelectFreeTier || (!isSelectFreeTier && !isEmptyPaymentMethod))const delayedCheckPasswordStrength = useRef(@@ -202,7 +209,11 @@ const Wizard: NextPageWithLayout = () => {return (<PanelhideHeaderStyling- loading={!app.organizations.isInitialized}+ loading={+ !app.organizations.isInitialized ||+ subscriptionStats.isLoading ||+ isLoadingFreeProjectLimitCheck+ }title={<div key="panel-title"><h3>Create a new project</h3>@@ -243,7 +254,12 @@ const Wizard: NextPageWithLayout = () => {</Panel.Content>) : (<>- <Panel.Content className="Form section-block--body has-inputs-centered space-y-4 border-t border-b border-panel-border-interior-light dark:border-panel-border-interior-dark">+ <Panel.Content+ className={[+ 'Form section-block--body has-inputs-centered space-y-4 border-t border-b',+ 'border-panel-border-interior-light dark:border-panel-border-interior-dark',+ ].join(' ')}+ >{organizations.length > 0 && (<Listboxlabel="Organization"@@ -266,9 +282,15 @@ const Wizard: NextPageWithLayout = () => {{!isAdmin && <NotOrganizationOwnerWarning />}</Panel.Content>+{canCreateProject && (<>- <Panel.Content className="Form section-block--body has-inputs-centered border-t border-b border-panel-border-interior-light dark:border-panel-border-interior-dark">+ <Panel.Content+ className={[+ 'Form section-block--body has-inputs-centered border-t border-b',+ 'border-panel-border-interior-light dark:border-panel-border-interior-dark',+ ].join(' ')}+ ><Inputid="project-name"layout="horizontal"@@ -335,6 +357,7 @@ const Wizard: NextPageWithLayout = () => {</Panel.Content></>)}+{isAdmin && (<Panel.Content className="Form section-block--body has-inputs-centered "><Listbox@@ -376,8 +399,8 @@ const Wizard: NextPageWithLayout = () => {})}</Listbox>- {isSelectFreeTier && isOverFreeProjectLimit && (- <FreeProjectLimitWarning limit={freeProjectsLimit} />+ {isSelectFreeTier && hasMembersExceedingFreeTierLimit && (+ <FreeProjectLimitWarning members={members || []} />)}{!isSelectFreeTier && isEmptyPaymentMethod && (@@ -385,13 +408,6 @@ const Wizard: NextPageWithLayout = () => {)}</Panel.Content>)}- {subscriptionStats.isLoading && (- <Panel.Content>- <div className="flex items-center justify-center py-10">- <IconLoader size={16} className="animate-spin" />- </div>- </Panel.Content>- )}</>)}</>