Files
supabase/apps/studio/components/interfaces/Settings/General/Infrastructure/PauseProjectButton.tsx
T
Joshen Lim a057c951ea Make edge functions page accessible on coming up (#42549)
## Context

Related prior work was making edge functions page accessible while
project is restoring - however the status of the project gets flipped to
COMING_UP while it's restoring hence why the functions page was still
inaccessible.

## Changes involved

- Update `NavigationBar.utils` to have edge functions link to
`/functions` irregardless of project status
- (Unrelated) Disable (with tooltip) deploy new function CTA on edge
functions page if project is not active
<img width="403" height="108" alt="image"
src="https://github.com/user-attachments/assets/88479247-999b-4d41-a444-6705f8c3993e"
/>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Deploy Edge Function button now disables and shows a tooltip when the
project is inactive to make deployment status clear.

* **Bug Fixes**
* Edge Functions link now points consistently to the functions view
regardless of project build state.

* **Refactor**
* Consolidated project-active check and reorganized related UI wiring to
standardize inactive-state handling across settings and controls.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-09 16:56:23 +08:00

104 lines
3.5 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useSetProjectStatus } from 'data/projects/project-detail-query'
import { useProjectPauseMutation } from 'data/projects/project-pause-mutation'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import {
useIsAwsK8sCloudProvider,
useIsProjectActive,
useSelectedProjectQuery,
} from 'hooks/misc/useSelectedProject'
import { PROJECT_STATUS } from 'lib/constants'
import { Pause } from 'lucide-react'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { toast } from 'sonner'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
const PauseProjectButton = () => {
const router = useRouter()
const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
const { setProjectStatus } = useSetProjectStatus()
const isProjectActive = useIsProjectActive()
const [isModalOpen, setIsModalOpen] = useState(false)
const projectRef = project?.ref ?? ''
const isPaused = project?.status === PROJECT_STATUS.INACTIVE
const { can: canPauseProject } = useAsyncCheckPermissions(
PermissionAction.INFRA_EXECUTE,
'queue_jobs.projects.pause'
)
const isAwsK8s = useIsAwsK8sCloudProvider()
const isFreePlan = organization?.plan.id === 'free'
const isBranch = Boolean(project?.parent_project_ref)
const isPaidAndNotAwsK8s = !isBranch && !isFreePlan && !isAwsK8s
const { mutate: pauseProject, isPending: isPausing } = useProjectPauseMutation({
onSuccess: (_, variables) => {
setProjectStatus({ ref: variables.ref, status: PROJECT_STATUS.PAUSING })
toast.success('Pausing project...')
router.push(`/project/${projectRef}`)
},
})
const requestPauseProject = () => {
if (!canPauseProject) {
return toast.error('You do not have the required permissions to pause this project')
}
pauseProject({ ref: projectRef })
}
const buttonDisabled =
isPaidAndNotAwsK8s || project === undefined || isPaused || !canPauseProject || !isProjectActive
return (
<>
<ButtonTooltip
type="default"
icon={<Pause />}
onClick={() => setIsModalOpen(true)}
loading={isPausing}
disabled={buttonDisabled}
tooltip={{
content: {
side: 'bottom',
text: isPaused
? 'Your project is already paused'
: !canPauseProject
? 'You need additional permissions to pause this project'
: !isProjectActive
? 'Unable to pause project as project is not active'
: isPaidAndNotAwsK8s
? 'Projects on a paid plan will always be running'
: undefined,
},
}}
>
Pause project
</ButtonTooltip>
<ConfirmationModal
variant={'destructive'}
visible={isModalOpen}
loading={isPausing}
title="Pause this project?"
confirmLabel="Pause project"
confirmLabelLoading="Pausing project"
onCancel={() => setIsModalOpen(false)}
onConfirm={requestPauseProject}
>
<p className="text-foreground-light text-sm">
Are you sure you want to pause this project? It will not be accessible until you unpause
it.
</p>
</ConfirmationModal>
</>
)
}
export default PauseProjectButton