mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 21:59:16 +03:00
* fix: update Permission params * fix: upgrade check permission hook to support project level role * fix: usePermissionsLoaded * fix: Permission params can be undefined * Scaffold new access management UI * Add validation * Update roles view * Add tooltip * Add button to apply role to all projects * Update UI to select projects first instead of roles * Merge master update UI * Midway trying to implementation project level perms API * First pass implementating updating project level permissions * Add client side validation for assigning/removing roles * Midway implementing new invites * Integrate most of the project level permissions functionality * fix: filter out org-level permissions before checking * Add relevant UI guards in org level pages for project role POV * Minor refactors * Small refactors * More fixes * Moar refactors * More fixes * More fixes * Refactor update role logic and smack some test cases on it * Fixes * Fix type issue * Fix type * more fixes, refactors, adding checks... * MORE fixes * Add perms checking for replicas * Add ButtonTooltip component and use them to prevent repetition of pointer events auto for buttons with tooltips * Convert all buttons with tooltips to use ButtonTooltip * refactor * PRettier * Small fix * Remove commented out code in organization-invitation-accept-mutation * fix: switch to use the platform oauth authorizations routes * Add perms checking for org audit logs and org oauth apps * PRettier * Fix incorrect URL for oauth app flow * Fix incorrect URL for oauth app flow * Fix * Add perms checking for warehouse related UI * Update roles helper icon * remove unused lib * Update package lock... again * Update package lock... again * Smalllll update * Update some checks * Add gate for project level permissions * Last fix * update codegen * Update warehouse endpoint routes * Fix --------- Co-authored-by: phamhieu <phamhieu1998@gmail.com> Co-authored-by: Alaister Young <a@alaisteryoung.com>
102 lines
3.4 KiB
TypeScript
102 lines
3.4 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useQueryClient } from '@tanstack/react-query'
|
|
import { Pause } from 'lucide-react'
|
|
import { useRouter } from 'next/router'
|
|
import { useState } from 'react'
|
|
import toast from 'react-hot-toast'
|
|
|
|
import {
|
|
useIsProjectActive,
|
|
useProjectContext,
|
|
} from 'components/layouts/ProjectLayout/ProjectContext'
|
|
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
|
|
import { useProjectPauseMutation } from 'data/projects/project-pause-mutation'
|
|
import { setProjectStatus } from 'data/projects/projects-query'
|
|
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
|
|
import { useCheckPermissions, useSelectedOrganization } from 'hooks'
|
|
import { PROJECT_STATUS } from 'lib/constants'
|
|
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
|
|
const PauseProjectButton = () => {
|
|
const router = useRouter()
|
|
const queryClient = useQueryClient()
|
|
const { project } = useProjectContext()
|
|
const organization = useSelectedOrganization()
|
|
const isProjectActive = useIsProjectActive()
|
|
const [isModalOpen, setIsModalOpen] = useState(false)
|
|
|
|
const projectRef = project?.ref ?? ''
|
|
const isPaused = project?.status === PROJECT_STATUS.INACTIVE
|
|
const canPauseProject = useCheckPermissions(
|
|
PermissionAction.INFRA_EXECUTE,
|
|
'queue_jobs.projects.pause'
|
|
)
|
|
|
|
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug })
|
|
const isFreePlan = subscription?.plan.id === 'free'
|
|
|
|
const { mutate: pauseProject, isLoading: isPausing } = useProjectPauseMutation({
|
|
onSuccess: (res, variables) => {
|
|
setProjectStatus(queryClient, variables.ref, 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 =
|
|
!isFreePlan || 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'
|
|
: !isFreePlan
|
|
? '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
|