Skip to content

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

Update warning for unpausing a project when already exceeding limits

Joshen Lim11f6b8794669
diff --git a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx
index 964f7f7f13d..75ffad9ef82 100644
--- a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx
+++ b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx
@@ -15,7 +15,10 @@ import { Route } from 'components/ui/ui.types'
import { IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
export const generateProductRoutes = (ref?: string, project?: ProjectBase): Route[] => {
- const isProjectBuilding = project?.status !== PROJECT_STATUS.ACTIVE_HEALTHY
+ const isProjectBuilding = project?.status === PROJECT_STATUS.COMING_UP
+ const isProjectPaused = project?.status === PROJECT_STATUS.INACTIVE
+
+ const homeUrl = `/project/${ref}`
const buildingUrl = `/project/${ref}/building`
return [
@@ -29,13 +32,21 @@ export const generateProductRoutes = (ref?: string, project?: ProjectBase): Rout
preProcessor={(code) => code.replace(/svg/, 'svg class="m-auto text-color-inherit"')}
/>
),
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/editor`),
+ link:
+ ref &&
+ (isProjectPaused ? homeUrl : isProjectBuilding ? buildingUrl : `/project/${ref}/editor`),
},
{
key: 'auth',
label: 'Authentication',
icon: <IconUsers size={18} strokeWidth={2} />,
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/auth/users`),
+ link:
+ ref &&
+ (isProjectPaused
+ ? homeUrl
+ : isProjectBuilding
+ ? buildingUrl
+ : `/project/${ref}/auth/users`),
},
...(IS_PLATFORM
? [
@@ -43,7 +54,13 @@ export const generateProductRoutes = (ref?: string, project?: ProjectBase): Rout
key: 'storage',
label: 'Storage',
icon: <IconArchive size={18} strokeWidth={2} />,
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/storage/buckets`),
+ link:
+ ref &&
+ (isProjectPaused
+ ? homeUrl
+ : isProjectBuilding
+ ? buildingUrl
+ : `/project/${ref}/storage/buckets`),
},
]
: []),
@@ -57,13 +74,21 @@ export const generateProductRoutes = (ref?: string, project?: ProjectBase): Rout
preProcessor={(code) => code.replace(/svg/, 'svg class="m-auto text-color-inherit"')}
/>
),
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/sql`),
+ link:
+ ref &&
+ (isProjectPaused ? homeUrl : isProjectBuilding ? buildingUrl : `/project/${ref}/sql`),
},
{
key: 'database',
label: 'Database',
icon: <IconDatabase size={18} strokeWidth={2} />,
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/database/tables`),
+ link:
+ ref &&
+ (isProjectPaused
+ ? homeUrl
+ : isProjectBuilding
+ ? buildingUrl
+ : `/project/${ref}/database/tables`),
},
...(IS_PLATFORM
? [
@@ -71,7 +96,13 @@ export const generateProductRoutes = (ref?: string, project?: ProjectBase): Rout
key: 'functions',
label: 'Edge Functions',
icon: <IconCode size={18} strokeWidth={2} />,
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/functions`),
+ link:
+ ref &&
+ (isProjectPaused
+ ? homeUrl
+ : isProjectBuilding
+ ? buildingUrl
+ : `/project/${ref}/functions`),
},
]
: []),
@@ -79,7 +110,10 @@ export const generateProductRoutes = (ref?: string, project?: ProjectBase): Rout
}
export const generateOtherRoutes = (ref?: string, project?: ProjectBase): Route[] => {
- const isProjectBuilding = project?.status !== PROJECT_STATUS.ACTIVE_HEALTHY
+ const isProjectBuilding = project?.status === PROJECT_STATUS.COMING_UP
+ const isProjectPaused = project?.status === PROJECT_STATUS.INACTIVE
+
+ const homeUrl = `/project/${ref}`
const buildingUrl = `/project/${ref}/building`
return [
@@ -89,7 +123,13 @@ export const generateOtherRoutes = (ref?: string, project?: ProjectBase): Route[
key: 'logs-explorer',
label: 'Logs Explorer',
icon: <IconList size={18} strokeWidth={2} />,
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/logs-explorer`),
+ link:
+ ref &&
+ (isProjectPaused
+ ? homeUrl
+ : isProjectBuilding
+ ? buildingUrl
+ : `/project/${ref}/logs-explorer`),
},
]
: []),
@@ -99,7 +139,13 @@ export const generateOtherRoutes = (ref?: string, project?: ProjectBase): Route[
key: 'reports',
label: 'Reports',
icon: <IconBarChart size={18} strokeWidth={2} />,
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/reports`),
+ link:
+ ref &&
+ (isProjectPaused
+ ? homeUrl
+ : isProjectBuilding
+ ? buildingUrl
+ : `/project/${ref}/reports`),
},
]
: []),
@@ -107,7 +153,9 @@ export const generateOtherRoutes = (ref?: string, project?: ProjectBase): Route[
key: 'api',
label: 'API',
icon: <IconFileText size={18} strokeWidth={2} />,
- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/api`),
+ link:
+ ref &&
+ (isProjectPaused ? homeUrl : isProjectBuilding ? buildingUrl : `/project/${ref}/api`),
},
...(IS_PLATFORM
? [
diff --git a/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx b/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
index b344e3509f4..a6e40267b34 100644
--- a/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
+++ b/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
@@ -1,12 +1,12 @@
import { FC, useState } from 'react'
import * as Tooltip from '@radix-ui/react-tooltip'
-import { Alert, Button, IconPauseCircle } from 'ui'
+import { Modal, Button, IconPauseCircle } from 'ui'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { Project } from 'types'
-import { checkPermissions, useStore, useSubscriptionStats, useFlag } from 'hooks'
+import { checkPermissions, useStore, useFlag, useFreeProjectLimitCheck } from 'hooks'
import { post } from 'lib/common/fetch'
-import { API_URL, PROJECT_STATUS, DEFAULT_FREE_PROJECTS_LIMIT } from 'lib/constants'
+import { API_URL, PROJECT_STATUS } from 'lib/constants'
import { DeleteProjectButton } from 'components/interfaces/Settings/General'
import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
@@ -16,16 +16,17 @@ interface Props {
const ProjectPausedState: FC<Props> = ({ project }) => {
const { ui, app } = useStore()
- const subscriptionStats = useSubscriptionStats()
- const { total_active_free_projects: totalActiveFreeProjects } = subscriptionStats
- const freeProjectsLimit = ui.profile?.free_project_limit ?? DEFAULT_FREE_PROJECTS_LIMIT
+ const isOwner = ui.selectedOrganization?.is_owner
+ const orgSlug = ui.selectedOrganization?.slug
- const enablePermissions = useFlag('enablePermissions')
const kpsEnabled = useFlag('initWithKps')
- const isOwner = ui.selectedOrganization?.is_owner
+ const enablePermissions = useFlag('enablePermissions')
const [showConfirmRestore, setShowConfirmRestore] = useState(false)
- const hasExceedActiveFreeProjectsLimit = totalActiveFreeProjects >= freeProjectsLimit
+ const [showFreeProjectLimitWarning, setShowFreeProjectLimitWarning] = useState(false)
+
+ const { membersExceededLimit } = useFreeProjectLimitCheck(orgSlug)
+ const hasMembersExceedingFreeTierLimit = (membersExceededLimit || []).length > 0
const canResumeProject = enablePermissions
? checkPermissions(PermissionAction.INFRA_EXECUTE, 'queue_jobs.projects.initialize_or_resume')
@@ -33,12 +34,12 @@ const ProjectPausedState: FC<Props> = ({ project }) => {
const onSelectRestore = () => {
if (!canResumeProject) {
- return ui.setNotification({
+ ui.setNotification({
category: 'error',
message: 'You do not have the required permissions to restore this project',
})
- }
- setShowConfirmRestore(true)
+ } else if (hasMembersExceedingFreeTierLimit) setShowFreeProjectLimitWarning(true)
+ else setShowConfirmRestore(true)
}
const onConfirmRestore = async () => {
@@ -50,17 +51,6 @@ const ProjectPausedState: FC<Props> = ({ project }) => {
return (
<>
<div className="space-y-4">
- {hasExceedActiveFreeProjectsLimit && (
- <div className="mx-6">
- <Alert
- withIcon
- variant="warning"
- title={`Your account can only have ${freeProjectsLimit} active free projects`}
- >
- To restore this project you'll need to pause or delete an existing free project.
- </Alert>
- </div>
- )}
<div className="mx-auto mb-16 w-full max-w-7xl">
<div className="mx-6 flex h-[500px] items-center justify-center rounded border border-scale-400 bg-scale-300 p-8">
<div className="grid w-[420px] gap-4">
@@ -76,7 +66,7 @@ const ProjectPausedState: FC<Props> = ({ project }) => {
<Button
size="tiny"
type="primary"
- disabled={hasExceedActiveFreeProjectsLimit || !canResumeProject}
+ disabled={!canResumeProject}
onClick={onSelectRestore}
>
Restore project
@@ -101,11 +91,9 @@ const ProjectPausedState: FC<Props> = ({ project }) => {
<DeleteProjectButton type="default" />
</div>
- {!hasExceedActiveFreeProjectsLimit && (
- <p className="mt-4 text-sm text-scale-1000">
- Restore this project and get back to building the next big thing!
- </p>
- )}
+ <p className="mt-4 text-sm text-scale-1000">
+ Restore this project and get back to building the next big thing!
+ </p>
</div>
</div>
</div>
@@ -119,6 +107,49 @@ const ProjectPausedState: FC<Props> = ({ project }) => {
onSelectCancel={() => setShowConfirmRestore(false)}
onSelectConfirm={onConfirmRestore}
/>
+ <Modal
+ hideFooter
+ visible={showFreeProjectLimitWarning}
+ size="medium"
+ header="Your organization has members who have exceeded their free project limits"
+ onCancel={() => setShowFreeProjectLimitWarning(false)}
+ >
+ <div className="space-y-4 py-4">
+ <Modal.Content>
+ <div className="space-y-2">
+ <p className="text-sm text-scale-1100">
+ 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 text-sm text-scale-1100">
+ {(membersExceededLimit || []).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 text-scale-1100">
+ These members will need to either delete, pause, or upgrade one or more of these
+ projects before you're able to unpause this project.
+ </p>
+ </div>
+ </Modal.Content>
+ <Modal.Seperator />
+ <Modal.Content>
+ <div className="flex items-center gap-2">
+ <Button
+ htmlType="button"
+ type="default"
+ onClick={() => setShowFreeProjectLimitWarning(false)}
+ block
+ >
+ Understood
+ </Button>
+ </div>
+ </Modal.Content>
+ </div>
+ </Modal>
</>
)
}