Skip to content

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

Hook up pause project endpoint and polish pausing/restoring flow UI

Joshen Lim104e03fe3469
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx
index dce757a3efd..55394312d63 100644
--- a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx
+++ b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx
@@ -1,27 +1,23 @@
import { FC } from 'react'
+import { Badge, IconLoader, IconPauseCircle } from '@supabase/ui'
-import { Badge, Button, IconClock } from '@supabase/ui'
import { Project } from 'types'
import CardButton from 'components/ui/CardButton'
+import { PROJECT_STATUS } from 'lib/constants'
interface Props {
project: Project
- paused: boolean
- onSelectRestore?: () => void
- onSelectDelete?: () => void
rewriteHref?: string
}
-const ProjectCard: FC<Props> = ({
- project,
- paused,
- onSelectRestore,
- onSelectDelete,
- rewriteHref,
-}) => {
+const ProjectCard: FC<Props> = ({ project, rewriteHref }) => {
const { name, ref: projectRef } = project
const desc = `${project.cloud_provider} | ${project.region}`
+ const isPausing = project.status === PROJECT_STATUS.GOING_DOWN
+ const isPaused = project.status === PROJECT_STATUS.INACTIVE
+ const isRestoring = project.status === PROJECT_STATUS.RESTORING
+
return (
<li className="col-span-1">
<CardButton
@@ -35,35 +31,36 @@ const ProjectCard: FC<Props> = ({
footer={
<div className="flex items-end justify-between">
<span className="text-scale-900 text-sm lowercase">{desc}</span>
- {paused && (
+ {isRestoring ? (
+ <div className="grow text-right">
+ <Badge color="brand">
+ <div className="flex items-center gap-2">
+ <IconLoader className="animate-spin" size={14} strokeWidth={2} />
+ <span className="truncate">Restoring</span>
+ </div>
+ </Badge>
+ </div>
+ ) : isPausing ? (
<div className="grow text-right">
<Badge color="scale">
<div className="flex items-center gap-2">
- <IconClock size={14} strokeWidth={2} />
- <span className="truncate">Project paused</span>
+ <IconLoader className="animate-spin" size={14} strokeWidth={2} />
+ <span className="truncate">Pausing</span>
</div>
</Badge>
</div>
+ ) : isPaused ? (
+ <div className="grow text-right">
+ <Badge color="scale">
+ <div className="flex items-center gap-2">
+ <IconPauseCircle size={14} strokeWidth={2} />
+ <span className="truncate">Paused</span>
+ </div>
+ </Badge>
+ </div>
+ ) : (
+ <></>
)}
-
- {/*<div className="flex items-center gap-2">
- <div className="flex items-center gap-2">
- <Button
- size="tiny"
- type="primary"
- onClick={() => onSelectRestore && onSelectRestore()}
- >
- Restore
- </Button>
- <Button
- size="tiny"
- type="default"
- onClick={() => onSelectDelete && onSelectDelete()}
- >
- Delete
- </Button>
- </div>
- </div>*/}
</div>
}
></CardButton>
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectList.tsx b/studio/components/interfaces/Home/ProjectList/ProjectList.tsx
index 7417a804e2c..3664536aee5 100644
--- a/studio/components/interfaces/Home/ProjectList/ProjectList.tsx
+++ b/studio/components/interfaces/Home/ProjectList/ProjectList.tsx
@@ -1,26 +1,19 @@
import { FC } from 'react'
-import { Button, IconLoader, IconPlus, Loading } from '@supabase/ui'
+import { Button, IconPlus } from '@supabase/ui'
import { useRouter } from 'next/router'
import { observer } from 'mobx-react-lite'
import { useStore } from 'hooks'
import { Organization, Project } from 'types'
import { makeRandomString } from 'lib/helpers'
-import { PROJECT_STATUS } from 'lib/constants'
import ProjectCard from './ProjectCard'
import ShimmeringCard from './ShimmeringCard'
interface Props {
- onSelectRestore: (project: Project) => void
- onSelectDelete: (project: Project) => void
rewriteHref?: (projectRef: string) => string
}
-const ProjectList: FC<Props> = ({
- onSelectRestore = () => {},
- onSelectDelete = () => {},
- rewriteHref,
-}) => {
+const ProjectList: FC<Props> = ({ rewriteHref }) => {
const router = useRouter()
const { app } = useStore()
const { organizations, projects } = app
@@ -38,17 +31,17 @@ const ProjectList: FC<Props> = ({
<div className="space-y-3" key={makeRandomString(5)}>
<h4 className="text-lg">{name}</h4>
{isLoadingProjects ? (
- <ul className="grid gap-4 mx-auto grid-cols-1 sm:grid-cols-1 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 ">
+ <ul className="mx-auto grid grid-cols-1 gap-4 sm:grid-cols-1 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 ">
<ShimmeringCard />
<ShimmeringCard />
</ul>
) : (
- <ul className="grid gap-4 mx-auto grid-cols-1 sm:grid-cols-1 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 ">
+ <ul className="mx-auto grid grid-cols-1 gap-4 sm:grid-cols-1 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 ">
{!isLoadingProjects && isEmpty && (
- <div className="max-w-4xl text-center col-span-4 space-y-4 border-2 border-gray-300 border-dashed rounded-lg p-6">
+ <div className="col-span-4 max-w-4xl space-y-4 rounded-lg border-2 border-dashed border-gray-300 p-6 text-center">
<div className="space-y-1">
<p>No projects</p>
- <p className="text-sm text-scale-1100">
+ <p className="text-scale-1100 text-sm">
Get started by creating a new project.
</p>
</div>
@@ -63,10 +56,7 @@ const ProjectList: FC<Props> = ({
<ProjectCard
key={makeRandomString(5)}
project={project}
- paused={project.status === PROJECT_STATUS.INACTIVE}
rewriteHref={rewriteHref ? rewriteHref(project.ref) : undefined}
- onSelectDelete={() => onSelectDelete(project)}
- onSelectRestore={() => onSelectRestore(project)}
/>
))}
</ul>
diff --git a/studio/components/interfaces/Settings/General/DeleteProjectButton.tsx b/studio/components/interfaces/Settings/General/DeleteProjectButton.tsx
new file mode 100644
index 00000000000..1515b85f309
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/DeleteProjectButton.tsx
@@ -0,0 +1,68 @@
+import { FC, useState } from 'react'
+import { useRouter } from 'next/router'
+import { Button } from '@supabase/ui'
+
+import { useStore } from 'hooks'
+import { API_URL } from 'lib/constants'
+import { delete_ } from 'lib/common/fetch'
+import TextConfirmModal from 'components/ui/Modals/TextConfirmModal'
+import { Project } from 'types'
+
+interface Props {
+ project: Project
+ type?: 'danger' | 'default'
+}
+
+const DeleteProjectButton: FC<Props> = ({ project, type = 'danger' }) => {
+ const router = useRouter()
+ const { ui, app } = useStore()
+
+ const [isOpen, setIsOpen] = useState(false)
+ const [loading, setLoading] = useState(false)
+
+ const toggle = () => {
+ if (loading) return
+ setIsOpen(!isOpen)
+ }
+
+ async function handleDeleteProject() {
+ setLoading(true)
+ try {
+ const response = await delete_(`${API_URL}/projects/${project.ref}`)
+ if (response.error) throw response.error
+ app.onProjectDeleted(response)
+ ui.setNotification({ category: 'success', message: `Successfully deleted ${project.name}` })
+ router.push(`/`)
+ } catch (error: any) {
+ setLoading(false)
+ ui.setNotification({
+ category: 'error',
+ message: `Failed to delete project ${project.name}: ${error.message}`,
+ })
+ }
+ }
+
+ return (
+ <>
+ <div className="flex items-center">
+ <Button onClick={toggle} type={type}>
+ Delete project
+ </Button>
+ </div>
+ <TextConfirmModal
+ visible={isOpen}
+ loading={loading}
+ title={`Confirm deletion of ${project?.name}`}
+ confirmPlaceholder="Type the project name in here"
+ alert="This action cannot be undone."
+ text={`This will permanently delete the ${project?.name} project and all of its data.`}
+ confirmString={project?.name}
+ confirmLabel="I understand, delete this project"
+ onConfirm={handleDeleteProject}
+ onCancel={toggle}
+ />
+ </>
+ )
+}
+
+export default DeleteProjectButton
diff --git a/studio/components/interfaces/Settings/General/PauseProjectButton.tsx b/studio/components/interfaces/Settings/General/PauseProjectButton.tsx
new file mode 100644
index 00000000000..5d19c10b5e0
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/PauseProjectButton.tsx
@@ -0,0 +1,65 @@
+import { FC, useState } from 'react'
+import { useRouter } from 'next/router'
+import { observer } from 'mobx-react-lite'
+import { Button, IconPause } from '@supabase/ui'
+
+import { useStore } from 'hooks'
+import { post } from 'lib/common/fetch'
+import { API_URL, PROJECT_STATUS } from 'lib/constants'
+import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
+
+interface Props {
+ projectId: number
+ projectRef: string
+}
+
+const PauseProjectButton: FC<Props> = observer(({ projectRef, projectId }) => {
+ const { ui, app } = useStore()
+ const router = useRouter()
+ const [loading, setLoading] = useState(false)
+ const [isModalOpen, setIsModalOpen] = useState(false)
+
+ const openModal = () => setIsModalOpen(true)
+ const closeModal = () => setIsModalOpen(false)
+
+ const requestPauseProject = async () => {
+ setLoading(true)
+ const res = await post(`${API_URL}/projects/${projectRef}/pause`, {})
+
+ if (res.error) {
+ ui.setNotification({
+ error: res.error,
+ category: 'error',
+ message: 'Failed to pause project',
+ })
+ setLoading(false)
+ } else {
+ app.onProjectPaused(projectId)
+ app.onProjectStatusUpdated(projectId, PROJECT_STATUS.GOING_DOWN)
+
+ ui.setNotification({ category: 'success', message: 'Pausing project' })
+ router.push(`/project/${projectRef}`)
+ }
+ closeModal()
+ }
+
+ return (
+ <>
+ <ConfirmModal
+ danger
+ visible={isModalOpen}
+ title="Pause this project?"
+ description="Are you sure you want to pause this project? It will not be accessible until you unpause it."
+ buttonLabel="Pause project"
+ buttonLoadingLabel="Pausing project"
+ onSelectCancel={closeModal}
+ onSelectConfirm={requestPauseProject}
+ />
+ <Button type="default" icon={<IconPause />} onClick={openModal} loading={loading}>
+ Pause Project
+ </Button>
+ </>
+ )
+})
+
+export default PauseProjectButton
diff --git a/studio/components/interfaces/Settings/General/RestartServerButton.tsx b/studio/components/interfaces/Settings/General/RestartServerButton.tsx
new file mode 100644
index 00000000000..b981b68d0ad
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/RestartServerButton.tsx
@@ -0,0 +1,63 @@
+import { FC, useState } from 'react'
+import { useRouter } from 'next/router'
+import { observer } from 'mobx-react-lite'
+import { Button, IconRefreshCcw } from '@supabase/ui'
+
+import { useStore } from 'hooks'
+import { post } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
+import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
+
+interface Props {
+ projectId: number
+ projectRef: string
+}
+
+const RestartServerButton: FC<Props> = observer(({ projectRef, projectId }) => {
+ const { ui, app } = useStore()
+ const router = useRouter()
+ const [loading, setLoading] = useState(false)
+ const [isModalOpen, setIsModalOpen] = useState(false)
+
+ const openModal = () => setIsModalOpen(true)
+ const closeModal = () => setIsModalOpen(false)
+
+ const requestServerRestart = async () => {
+ setLoading(true)
+ const res = await post(`${API_URL}/projects/${projectRef}/restart`, {})
+
+ if (res.error) {
+ ui.setNotification({
+ error: res.error,
+ category: 'error',
+ message: 'Unable to restart server',
+ })
+ setLoading(false)
+ } else {
+ app.onProjectPostgrestStatusUpdated(projectId, 'OFFLINE')
+ ui.setNotification({ category: 'success', message: 'Restarting server' })
+ router.push(`/project/${projectRef}`)
+ }
+ closeModal()
+ }
+
+ return (
+ <>
+ <ConfirmModal
+ danger
+ visible={isModalOpen}
+ title="Restart Server"
+ description={`Are you sure you want to restart the server? There will be a few minutes of downtime.`}
+ buttonLabel="Restart"
+ buttonLoadingLabel="Restarting"
+ onSelectCancel={closeModal}
+ onSelectConfirm={requestServerRestart}
+ />
+ <Button type="default" icon={<IconRefreshCcw />} onClick={openModal} loading={loading}>
+ Restart server
+ </Button>
+ </>
+ )
+})
+
+export default RestartServerButton
diff --git a/studio/components/interfaces/Settings/General/index.ts b/studio/components/interfaces/Settings/General/index.ts
new file mode 100644
index 00000000000..ad686684336
--- /dev/null
+++ b/studio/components/interfaces/Settings/General/index.ts
@@ -0,0 +1,6 @@
+import PauseProjectButton from './PauseProjectButton'
+import RestartServerButton from './RestartServerButton'
+
+import DeleteProjectButton from './DeleteProjectButton'
+
+export { PauseProjectButton, RestartServerButton, DeleteProjectButton }
diff --git a/studio/components/layouts/ProjectLayout/PausingState.tsx b/studio/components/layouts/ProjectLayout/PausingState.tsx
new file mode 100644
index 00000000000..bcf4e83ea60
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/PausingState.tsx
@@ -0,0 +1,46 @@
+import { FC } from 'react'
+import { Badge, IconLoader, IconCircle } from '@supabase/ui'
+import { Project } from 'types'
+
+interface Props {
+ project: Project
+}
+
+const PausingState: FC<Props> = ({ project }) => {
+ return (
+ <div className="mx-auto my-16 w-full max-w-7xl space-y-16">
+ <div className="mx-6 space-y-16">
+ <div className="flex flex-col space-y-4 lg:flex-row lg:items-center lg:space-y-0 lg:space-x-6">
+ <h1 className="text-3xl">{project.name}</h1>
+ <div>
+ <Badge color="gray">
+ <div className="flex items-center gap-2">
+ <IconLoader className="animate-spin" size={12} />
+ <span>Pausing project</span>
+ </div>
+ </Badge>
+ </div>
+ </div>
+ <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-[380px] gap-4">
+ <div className="relative mx-auto max-w-[300px]">
+ <div className="absolute flex h-full w-full items-center justify-center">
+ <IconLoader className="animate-spin" size={20} strokeWidth={2} />
+ </div>
+ <IconCircle className="text-scale-900" size={50} strokeWidth={1.5} />
+ </div>
+ <p className="text-center">Pausing {project.name}</p>
+ <p className="text-scale-1100 mt-4 text-center text-sm">
+ You may restore your project anytime thereafter, and your data will be restored to
+ when it was initially paused.
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ )
+}
+
+export default PausingState
diff --git a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
index d154b8db2a7..15b9292cd35 100644
--- a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
+++ b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
@@ -10,6 +10,7 @@ import NavigationBar from './NavigationBar/NavigationBar'
import ProductMenuBar from './ProductMenuBar'
import LayoutHeader from './LayoutHeader'
import ConnectingState from './ConnectingState'
+import PausingState from './PausingState'
import BuildingState from './BuildingState'
interface Props {
@@ -110,12 +111,15 @@ const ContentWrapper: FC<ContentWrapperProps> = observer(({ isLoading, children
const isProjectBuilding = [PROJECT_STATUS.COMING_UP, PROJECT_STATUS.RESTORING].includes(
ui.selectedProject?.status ?? ''
)
+ const isProjectPausing = ui.selectedProject?.status === PROJECT_STATUS.GOING_DOWN
const isProjectOffline = ui.selectedProject?.postgrestStatus === 'OFFLINE'
return (
<>
{isLoading || ui.selectedProject === undefined ? (
<Connecting />
+ ) : isProjectPausing ? (
+ <PausingState project={ui.selectedProject} />
) : requiresPostgrestConnection && isProjectOffline ? (
<ConnectingState project={ui.selectedProject} />
) : requiresDbConnection && isProjectBuilding ? (
diff --git a/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx b/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
index 2dfab00d30c..f8ff7b1e4d6 100644
--- a/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
+++ b/studio/components/layouts/ProjectLayout/ProjectPausedState.tsx
@@ -1,22 +1,20 @@
import { FC, useState } from 'react'
+import { useRouter } from 'next/router'
import { Button, IconAlertCircle, IconPauseCircle } from '@supabase/ui'
import { Project } from 'types'
-import Link from '@supabase/ui/dist/cjs/components/Typography/Link'
import { useStore, useSubscriptionStats } from 'hooks'
-import { DEFAULT_FREE_PROJECTS_LIMIT } from 'lib/constants'
import { post } from 'lib/common/fetch'
-import { API_URL, PROJECT_STATUS } from 'lib/constants'
-import { useRouter } from 'next/router'
+import { API_URL, PROJECT_STATUS, DEFAULT_FREE_PROJECTS_LIMIT } from 'lib/constants'
+import { DeleteProjectButton } from 'components/interfaces/Settings/General'
+import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
interface Props {
project: Project
}
const ProjectPausedState: FC<Props> = ({ project }) => {
- const [isSubmitting, setIsSubmitting] = useState(false)
const router = useRouter()
- const { ref } = router.query
const { ui, app } = useStore()
const subscriptionStats = useSubscriptionStats()
const {
@@ -26,69 +24,68 @@ const ProjectPausedState: FC<Props> = ({ project }) => {
} = subscriptionStats
const freeProjectsLimit = ui.profile?.free_project_limit ?? DEFAULT_FREE_PROJECTS_LIMIT
- const restoreProject = async (project: Project) => {
- app.onProjectUpdated({ ...project, status: PROJECT_STATUS.RESTORING })
+ const [isSubmitting, setIsSubmitting] = useState(false)
+ const [showConfirmRestore, setShowConfirmRestore] = useState(false)
+
+ const onConfirmRestore = async () => {
await post(`${API_URL}/projects/${project.ref}/restore`, {})
- //router.reload()
+ app.onProjectUpdated({ ...project, status: PROJECT_STATUS.RESTORING })
+ ui.setNotification({ category: 'success', message: 'Restoring project' })
}
return (
<>
<div className="mx-auto mt-8 mb-16 w-full max-w-7xl">
- <div className="mx-6">
- <div className="bg-scale-300 border-scale-400 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="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
- onClick={() => restoreProject(project)}
- size="small"
- loading={isSubmitting}
- type="primary"
- >
- Restore
- </Button>
+ <div className="flex items-center justify-center gap-4">
+ <Button
+ size="tiny"
+ type="primary"
+ loading={isSubmitting}
+ onClick={() => setShowConfirmRestore(true)}
+ >
+ Restore project
+ </Button>
- <Link href={`/project/${ref}/settings/general`}>
- <Button
- // onClick={}
- size="small"
- loading={isSubmitting}
- type="default"
- tabIndex={-1}
- >
- <a>Delete</a>
- </Button>
- </Link>
- </div>
+ <DeleteProjectButton project={project} type="default" />
+ </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>
+ {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>
- ) : (
- <p className="text-scale-900 mt-4 text-sm">
- Restore this project and get back to building the next big thing!
- </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>
+ <ConfirmModal
+ visible={showConfirmRestore}
+ title="Restore this project"
+ description="Confirm to restore this project? Your project's data will be restored to when it was initially paused."
+ buttonLabel="Restore project"
+ buttonLoadingLabel="Restoring project"
+ onSelectCancel={() => setShowConfirmRestore(false)}
+ onSelectConfirm={onConfirmRestore}
+ />
</>
)
}
diff --git a/studio/pages/index.tsx b/studio/pages/index.tsx
index f486c606f7d..542247844aa 100644
--- a/studio/pages/index.tsx
+++ b/studio/pages/index.tsx
@@ -1,57 +1,20 @@
-import { useEffect, useState } from 'react'
+import { useEffect } from 'react'
import { observer } from 'mobx-react-lite'
import { NextRouter, useRouter } from 'next/router'
-import { isUndefined } from 'lodash'
-import { Typography } from '@supabase/ui'
-import { NextPageWithLayout, Project } from 'types'
+import { NextPageWithLayout } from 'types'
import { useStore, withAuth } from 'hooks'
import { auth } from 'lib/gotrue'
-import { post, delete_ } from 'lib/common/fetch'
-import { API_URL, IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
+import { IS_PLATFORM } from 'lib/constants'
import Connecting from 'components/ui/Loading'
import { AccountLayoutWithoutAuth } from 'components/layouts'
import Landing from 'components/interfaces/Home/Landing'
import ProjectList from 'components/interfaces/Home/ProjectList'
import OrganizationDropdown from 'components/to-be-cleaned/Dropdown/OrganizationDropdown'
-import TextConfirmModal from 'components/ui/Modals/TextConfirmModal'
const Home: NextPageWithLayout = () => {
- const { app, ui } = useStore()
-
- const router = useRouter()
-
- const [isDeletingProject, setIsDeletingProject] = useState<boolean>(false)
- const [selectedProjectToDelete, setSelectedProjectToDelete] = useState<Project>()
-
- const onSelectDeleteProject = async (project: Project) => {
- setSelectedProjectToDelete(project)
- setIsDeletingProject(false)
- }
-
- const onDeleteProject = async (project?: Project) => {
- if (!project) return
- setIsDeletingProject(true)
- const response = await delete_(`${API_URL}/projects/${project.ref}`)
-
- if (response.error) {
- return ui.setNotification({ category: 'error', message: response.error.message })
- }
-
- app.onProjectDeleted(response)
- ui.setNotification({ category: 'success', message: `Deleted ${project.name} successfully!` })
-
- setIsDeletingProject(false)
- setSelectedProjectToDelete(undefined)
- }
-
- // [Terry: make sure to remove when we're done. Restoring doesn't happen from here anymore]
- const onRestoreProject = async (project: Project) => {
- app.onProjectUpdated({ ...project, status: PROJECT_STATUS.RESTORING })
- await post(`${API_URL}/projects/${project.ref}/restore`, {})
- router.push(`/project/${project.ref}`)
- }
+ const { app } = useStore()
return (
<>
@@ -71,32 +34,10 @@ const Home: NextPageWithLayout = () => {
</div>
)}
<div className="my-8 space-y-8">
- <ProjectList
- onSelectDelete={onSelectDeleteProject}
- onSelectRestore={onRestoreProject}
- />
+ <ProjectList />
</div>
</div>
)}
- <TextConfirmModal
- visible={!isUndefined(selectedProjectToDelete)}
- title="Are you absolutely sure?"
- alert="Deleting this project will also remove your database. Make sure you have made a backup if you want to keep your data."
- text={
- <span key="confirm-text">
- This action <Typography.Text strong>cannot</Typography.Text> be undone. This will
- permanently delete the{' '}
- <Typography.Text strong>{selectedProjectToDelete?.name}</Typography.Text> project and
- all of its data.
- </span>
- }
- loading={isDeletingProject}
- confirmLabel="Confirm delete"
- confirmPlaceholder="Type in name of project"
- confirmString={selectedProjectToDelete?.name ?? ''}
- onCancel={() => setSelectedProjectToDelete(undefined)}
- onConfirm={() => onDeleteProject(selectedProjectToDelete)}
- />
</>
)
}
diff --git a/studio/pages/project/[ref]/index.tsx b/studio/pages/project/[ref]/index.tsx
index 51a7f98ea37..b62411ce8c8 100644
--- a/studio/pages/project/[ref]/index.tsx
+++ b/studio/pages/project/[ref]/index.tsx
@@ -1,12 +1,13 @@
import { observer } from 'mobx-react-lite'
-import { Badge, IconPauseCircle, Typography } from '@supabase/ui'
+import { Typography } from '@supabase/ui'
+
import { useStore } from 'hooks'
+import { NextPageWithLayout } from 'types'
+import { IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
+import { ProjectLayoutWithAuth } from 'components/layouts'
import { ExampleProject, ClientLibrary } from 'components/interfaces/Home'
import { CLIENT_LIBRARIES, EXAMPLE_PROJECTS } from 'components/interfaces/Home/Home.constants'
-import { IS_PLATFORM } from 'lib/constants'
-import { ProjectLayoutWithAuth } from 'components/layouts'
import ProjectUsageSection from 'components/interfaces/Home/ProjectUsageSection'
-import { NextPageWithLayout } from 'types'
import ProjectPausedState from 'components/layouts/ProjectLayout/ProjectPausedState'
const Home: NextPageWithLayout = () => {
@@ -22,21 +23,11 @@ const Home: NextPageWithLayout = () => {
<div className="mx-auto my-16 w-full max-w-7xl space-y-16">
<div className="mx-6 flex items-center space-x-6">
<h1 className="text-3xl">{projectName}</h1>
- {project?.status == 'INACTIVE' && (
- <div className="mt-2">
- <Badge color="gray">
- <div className="flex items-center gap-2">
- <IconPauseCircle size={15} />
- <span>Project paused</span>
- </div>
- </Badge>
- </div>
- )}
</div>
- {project && project?.status == 'INACTIVE' && <ProjectPausedState project={project} />}
+ {project?.status === PROJECT_STATUS.INACTIVE && <ProjectPausedState project={project} />}
- {IS_PLATFORM && project?.status !== 'INACTIVE' && <ProjectUsageSection />}
+ {IS_PLATFORM && project?.status !== PROJECT_STATUS.INACTIVE && <ProjectUsageSection />}
<div className="space-y-8">
<div className="mx-6">
diff --git a/studio/pages/project/[ref]/settings/general.tsx b/studio/pages/project/[ref]/settings/general.tsx
index 9ba24330c9c..b10c3c43263 100644
--- a/studio/pages/project/[ref]/settings/general.tsx
+++ b/studio/pages/project/[ref]/settings/general.tsx
@@ -1,20 +1,22 @@
-import { FC, useState } from 'react'
-import { useRouter } from 'next/router'
import { observer } from 'mobx-react-lite'
import { toJS } from 'mobx'
import { projects } from 'stores/jsonSchema'
import { AutoField } from 'uniforms-bootstrap4'
-import { Alert, Button, Input, IconRefreshCcw, IconPause } from '@supabase/ui'
+import { Alert, Input } from '@supabase/ui'
import { API_URL } from 'lib/constants'
import { pluckJsonSchemaFields, pluckObjectFields } from 'lib/helpers'
-import { post, delete_ } from 'lib/common/fetch'
+import { post } from 'lib/common/fetch'
import { useStore } from 'hooks'
import { SettingsLayout } from 'components/layouts'
+import {
+ RestartServerButton,
+ PauseProjectButton,
+ DeleteProjectButton,
+} from 'components/interfaces/Settings/General'
+
import Panel from 'components/ui/Panel'
-import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
import SchemaFormPanel from 'components/to-be-cleaned/forms/SchemaFormPanel'
-import TextConfirmModal from 'components/ui/Modals/TextConfirmModal'
import { NextPageWithLayout } from 'types'
const ProjectSettings: NextPageWithLayout = () => {
@@ -33,98 +35,6 @@ ProjectSettings.getLayout = (page) => <SettingsLayout title="General">{page}</Se
export default observer(ProjectSettings)
-interface RestartServerButtonProps {
- projectId: number
- projectRef: string
-}
-const RestartServerButton: FC<RestartServerButtonProps> = observer(({ projectRef, projectId }) => {
- const { ui, app } = useStore()
- const router = useRouter()
- const [loading, setLoading] = useState(false)
- const [isModalOpen, setIsModalOpen] = useState(false)
-
- const openModal = () => setIsModalOpen(true)
- const closeModal = () => setIsModalOpen(false)
-
- const requestServerRestart = async () => {
- setLoading(true)
- try {
- await post(`${API_URL}/projects/${projectRef}/restart`, {})
- app.onProjectPostgrestStatusUpdated(projectId, 'OFFLINE')
- ui.setNotification({ category: 'success', message: 'Restarting server' })
- router.push(`/project/${projectRef}`)
- } catch (error) {
- ui.setNotification({ error, category: 'error', message: 'Unable to restart server' })
- setLoading(false)
- }
- closeModal()
- }
-
- return (
- <>
- <ConfirmModal
- danger
- visible={isModalOpen}
- title="Restart Server"
- description={`Are you sure you want to restart the server? There will be a few minutes of downtime.`}
- buttonLabel="Restart"
- buttonLoadingLabel="Restarting"
- onSelectCancel={closeModal}
- onSelectConfirm={requestServerRestart}
- />
- <Button type="default" icon={<IconRefreshCcw />} onClick={openModal} loading={loading}>
- Restart server
- </Button>
- </>
- )
-})
-
-interface PauseProjectButtonProps {
- projectId: number
- projectRef: string
-}
-const PauseProjectButton: FC<PauseProjectButtonProps> = observer(({ projectRef, projectId }) => {
- const { ui, app } = useStore()
- const router = useRouter()
- const [loading, setLoading] = useState(false)
- const [isModalOpen, setIsModalOpen] = useState(false)
-
- const openModal = () => setIsModalOpen(true)
- const closeModal = () => setIsModalOpen(false)
-
- const requestPauseProject = async () => {
- setLoading(true)
- try {
- await post(`${API_URL}/projects/${projectRef}/restart`, {})
- app.onProjectPostgrestStatusUpdated(projectId, 'OFFLINE')
- ui.setNotification({ category: 'success', message: 'Restarting server' })
- router.push(`/project/${projectRef}`)
- } catch (error) {
- ui.setNotification({ error, category: 'error', message: 'Unable to restart server' })
- setLoading(false)
- }
- closeModal()
- }
-
- return (
- <>
- <ConfirmModal
- danger
- visible={isModalOpen}
- title="Pause this project?"
- description={`Are you sure you want to pause this project? It will not be accessible until you unpause it.`}
- buttonLabel="Pause project"
- buttonLoadingLabel="Pausing project"
- onSelectCancel={closeModal}
- onSelectConfirm={requestPauseProject}
- />
- <Button type="default" icon={<IconPause />} onClick={openModal} loading={loading}>
- Pause Project
- </Button>
- </>
- )
-})
-
const GeneralSettings = observer(() => {
const { app, ui } = useStore()
const project = ui.selectedProject
@@ -182,8 +92,8 @@ const GeneralSettings = observer(() => {
<div className="flex w-full items-center justify-between">
<div>
<p>Restart server</p>
- <div style={{ maxWidth: '420px' }}>
- <p className="text-sm opacity-50">
+ <div className="max-w-[420px]">
+ <p className="text-scale-1100 text-sm">
Your project will not be available for a few minutes.
</p>
</div>
@@ -195,8 +105,8 @@ const GeneralSettings = observer(() => {
<div className="flex w-full items-center justify-between">
<div>
<p>Pause project</p>
- <div style={{ maxWidth: '420px' }}>
- <p className="text-sm opacity-50">
+ <div className="max-w-[420px]">
+ <p className="text-scale-1100 text-sm">
Your project will not be accessible while it is paused.
</p>
</div>
@@ -207,76 +117,26 @@ const GeneralSettings = observer(() => {
</Panel>
</section>
- <section>
- <Panel title={<p className="uppercase">Danger Zone</p>}>
- <Panel.Content>
- <Alert
- variant="danger"
- withIcon
- title="Deleting this project will also remove your database."
- >
- <div className="flex flex-col">
- <p className="mb-4 block">
- Make sure you have made a backup if you want to keep your data.
- </p>
- <ProjectDeleteModal project={project} />
- </div>
- </Alert>
- </Panel.Content>
- </Panel>
- </section>
+ {project !== undefined && (
+ <section>
+ <Panel title={<p className="uppercase">Danger Zone</p>}>
+ <Panel.Content>
+ <Alert
+ variant="danger"
+ withIcon
+ title="Deleting this project will also remove your database."
+ >
+ <div className="flex flex-col">
+ <p className="mb-4 block">
+ Make sure you have made a backup if you want to keep your data.
+ </p>
+ <DeleteProjectButton project={project} />
+ </div>
+ </Alert>
+ </Panel.Content>
+ </Panel>
+ </section>
+ )}
</article>
)
})
-
-const ProjectDeleteModal = ({ project }: any) => {
- const router = useRouter()
- const { ui, app } = useStore()
-
- const [isOpen, setIsOpen] = useState(false)
- const [loading, setLoading] = useState(false)
-
- const toggle = () => {
- if (loading) return
- setIsOpen(!isOpen)
- }
-
- async function handleDeleteProject() {
- setLoading(true)
- try {
- const response = await delete_(`${API_URL}/projects/${project.ref}`)
- if (response.error) throw response.error
- app.onProjectDeleted(response)
- ui.setNotification({ category: 'success', message: `Successfully deleted ${project.name}` })
- router.push(`/`)
- } catch (error: any) {
- setLoading(false)
- ui.setNotification({
- category: 'error',
- message: `Failed to delete project ${project.name}: ${error.message}`,
- })
- }
- }
-
- return (
- <>
- <div className="mt-2">
- <Button onClick={toggle} type="danger">
- Delete Project
- </Button>
- </div>
- <TextConfirmModal
- visible={isOpen}
- loading={loading}
- title={`Confirm deletion of ${project?.name}`}
- confirmPlaceholder="Type the project name in here"
- alert="This action cannot be undone."
- text={`This will permanently delete the ${project?.name} project and all of its data.`}
- confirmString={project?.name}
- confirmLabel="I understand, delete this project"
- onConfirm={handleDeleteProject}
- onCancel={toggle}
- />
- </>
- )
-}
diff --git a/studio/pages/project/_/[[...routeSlug]].tsx b/studio/pages/project/_/[[...routeSlug]].tsx
index b18f770153a..c63e4e74c9d 100644
--- a/studio/pages/project/_/[[...routeSlug]].tsx
+++ b/studio/pages/project/_/[[...routeSlug]].tsx
@@ -11,14 +11,14 @@ interface Props {}
const Header: FC<Props> = () => {
return (
- <div className="p-3 border-b dark:border-dark">
- <div className="space-x-2 flex items-center">
+ <div className="dark:border-dark border-b p-3">
+ <div className="flex items-center space-x-2">
<Link href="/">
<a>
<img
src="/img/supabase-logo.svg"
alt="Supabase"
- className="border dark:border-dark rounded p-1 hover:border-white"
+ className="dark:border-dark rounded border p-1 hover:border-white"
style={{ height: 24 }}
/>
</a>
@@ -50,14 +50,10 @@ const GenericProjectPage: NextPage = () => {
return (
<div>
<Header />
- <div className="py-8 w-full max-w-5xl mx-auto">
+ <div className="mx-auto w-full max-w-5xl py-8">
<h3 className="text-2xl">Select a project to continue</h3>
<div className="my-6 space-y-8">
- <ProjectList
- rewriteHref={urlRewriterFactory(routeSlug)}
- onSelectDelete={() => {}}
- onSelectRestore={() => {}}
- />
+ <ProjectList rewriteHref={urlRewriterFactory(routeSlug)} />
</div>
</div>
</div>
diff --git a/studio/stores/app/AppStore.ts b/studio/stores/app/AppStore.ts
index e66507d00af..6b436e9ddb9 100644
--- a/studio/stores/app/AppStore.ts
+++ b/studio/stores/app/AppStore.ts
@@ -2,7 +2,8 @@ import { cloneDeep } from 'lodash'
import { values } from 'mobx'
import { Organization, Project } from 'types'
-import { API_URL } from 'lib/constants'
+import { API_URL, PROJECT_STATUS } from 'lib/constants'
+import { getWithTimeout } from 'lib/common/fetch'
import { IRootStore } from '../RootStore'
import DatabaseStore, { IDatabaseStore } from './DatabaseStore'
import OrganizationStore from './OrganizationStore'
@@ -12,9 +13,10 @@ export interface IAppStore {
projects: IProjectStore
organizations: OrganizationStore
database: IDatabaseStore
- onProjectCreated: (project: any) => void
- onProjectUpdated: (project: any) => void
- onProjectDeleted: (project: any) => void
+ onProjectCreated: (project: Project) => void
+ onProjectUpdated: (project: Project) => void
+ onProjectDeleted: (project: Project) => void
+ onProjectPaused: (projectId: number) => void
onProjectStatusUpdated: (projectId: number, value: string) => void
onProjectPostgrestStatusUpdated: (projectId: number, value: 'OFFLINE' | 'ONLINE') => void
onOrgAdded: (org: any) => void
@@ -76,6 +78,24 @@ export default class AppStore implements IAppStore {
}
}
+ // At global store level so that it can continue checking while the user
+ // is doing something else outside of the project page
+ async onProjectPaused(projectId: number) {
+ const checkProjectInactive = async () => {
+ const projectRef = this.projects.data[projectId]?.ref
+ const projectStatus = await getWithTimeout(`${API_URL}/projects/${projectRef}/status`, {
+ timeout: 2000,
+ })
+ if (projectStatus.status === PROJECT_STATUS.INACTIVE) {
+ this.onProjectStatusUpdated(projectId, PROJECT_STATUS.INACTIVE)
+ } else {
+ setTimeout(() => checkProjectInactive(), 5000)
+ }
+ }
+
+ setTimeout(() => checkProjectInactive(), 5000)
+ }
+
onProjectStatusUpdated(projectId: number, value: string) {
const clone = cloneDeep(this.projects.data[projectId])
clone.status = value
diff --git a/studio/stores/app/ProjectStore.ts b/studio/stores/app/ProjectStore.ts
index 6c972a972ac..e741da8f6e2 100644
--- a/studio/stores/app/ProjectStore.ts
+++ b/studio/stores/app/ProjectStore.ts
@@ -48,6 +48,7 @@ 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