Skip to content

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

Fix and polish state to prevent restoration if already hit free active project limit

Joshen Limc6e16f845dc4
diff --git a/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx b/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
index f8ff7b1e4d6..841d5dfae66 100644
--- a/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
+++ b/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
@@ -1,6 +1,6 @@
import { FC, useState } from 'react'
import { useRouter } from 'next/router'
-import { Button, IconAlertCircle, IconPauseCircle } from '@supabase/ui'
+import { Alert, Button, IconAlertCircle, IconPauseCircle } from '@supabase/ui'
import { Project } from 'types'
import { useStore, useSubscriptionStats } from 'hooks'
@@ -14,7 +14,6 @@ interface Props {
}
const ProjectPausedState: FC<Props> = ({ project }) => {
- const router = useRouter()
const { ui, app } = useStore()
const subscriptionStats = useSubscriptionStats()
const {
@@ -24,8 +23,16 @@ const ProjectPausedState: FC<Props> = ({ project }) => {
} = subscriptionStats
const freeProjectsLimit = ui.profile?.free_project_limit ?? DEFAULT_FREE_PROJECTS_LIMIT
+ console.log('ProjectPausedState', {
+ totalFreeProjects,
+ totalActiveFreeProjects,
+ totalPausedFreeProjects,
+ freeProjectsLimit,
+ })
+
const [isSubmitting, setIsSubmitting] = useState(false)
const [showConfirmRestore, setShowConfirmRestore] = useState(false)
+ const hasExceedActiveFreeProjectsLimit = totalActiveFreeProjects >= freeProjectsLimit
const onConfirmRestore = async () => {
await post(`${API_URL}/projects/${project.ref}/restore`, {})
@@ -35,45 +42,46 @@ const ProjectPausedState: FC<Props> = ({ project }) => {
return (
<>
- <div className="mx-auto mt-8 mb-16 w-full max-w-7xl">
- <div className="bg-scale-300 border-scale-400 mx-6 flex h-[500px] items-center justify-center rounded border p-8">
- <div className="grid w-[420px] gap-4">
- <div className="mx-auto flex max-w-[300px] items-center justify-center space-x-4 lg:space-x-8">
- <IconPauseCircle className="text-scale-1100" size={50} strokeWidth={1.5} />
- </div>
+ <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="bg-scale-300 border-scale-400 mx-6 flex h-[500px] items-center justify-center rounded border p-8">
+ <div className="grid w-[420px] gap-4">
+ <div className="mx-auto flex max-w-[300px] items-center justify-center space-x-4 lg:space-x-8">
+ <IconPauseCircle className="text-scale-1100" size={50} strokeWidth={1.5} />
+ </div>
- <p className="text-center">This project is paused.</p>
+ <p className="text-center">This project is paused.</p>
- <div className="flex items-center justify-center gap-4">
- <Button
- size="tiny"
- type="primary"
- loading={isSubmitting}
- onClick={() => setShowConfirmRestore(true)}
- >
- Restore project
- </Button>
+ <div className="flex items-center justify-center gap-4">
+ <Button
+ size="tiny"
+ type="primary"
+ loading={isSubmitting}
+ disabled={hasExceedActiveFreeProjectsLimit}
+ onClick={() => setShowConfirmRestore(true)}
+ >
+ Restore project
+ </Button>
+ <DeleteProjectButton project={project} type="default" />
+ </div>
- <DeleteProjectButton project={project} type="default" />
+ {!hasExceedActiveFreeProjectsLimit && (
+ <p className="text-scale-1000 mt-4 text-sm">
+ Restore this project and get back to building the next big thing!
+ </p>
+ )}
</div>
-
- {totalActiveFreeProjects > totalFreeProjects ? (
- <div className="mt-4 flex gap-4 border-t pt-8">
- <IconAlertCircle className="text-red-900" size={35} strokeWidth={2} />
- <div>
- <p className="text-md">
- Your account can only have <u>{freeProjectsLimit} free projects.</u>
- </p>
- <p className="text-scale-900 mt-2 text-sm">
- To restore this project you'll need to pause or delete an existing free project.
- </p>
- </div>
- </div>
- ) : (
- <p className="text-scale-900 mt-4 text-sm">
- Restore this project and get back to building the next big thing!
- </p>
- )}
</div>
</div>
</div>
diff --git a/studio/stores/app/ProjectStore.ts b/studio/stores/app/ProjectStore.ts
index e741da8f6e2..6c972a972ac 100644
--- a/studio/stores/app/ProjectStore.ts
+++ b/studio/stores/app/ProjectStore.ts
@@ -48,7 +48,6 @@ export default class ProjectStore extends PostgresMetaInterface<Project> {
const url = `${this.url}/${projectRef}`
const headers = constructHeaders(this.headers)
const response = await get(url, { headers })
- console.log('Fetch project detail', projectRef, response)
if (!response.error) {
const project = response as Project