Skip to content

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

Route backt to main branch, if deleting a branch that user is currently on

Joshen Limfb8c68007bd7
diff --git a/studio/components/interfaces/BranchManagement/BranchManagement.tsx b/studio/components/interfaces/BranchManagement/BranchManagement.tsx
index f2e3f37db6e..cbe3798f39b 100644
--- a/studio/components/interfaces/BranchManagement/BranchManagement.tsx
+++ b/studio/components/interfaces/BranchManagement/BranchManagement.tsx
@@ -15,9 +15,11 @@ import CreateBranchSidePanel from './CreateBranchSidePanel'
import PreviewBranches from './PreviewBranches'
import PullRequests from './PullRequests'
import UpdateBranchSidePanel from './UpdateBranchSidePanel'
+import { useRouter } from 'next/router'
const BranchManagement = () => {
const { ui } = useStore()
+ const router = useRouter()
const { ref } = useParams()
const projectDetails = useSelectedProject()
@@ -34,8 +36,17 @@ const BranchManagement = () => {
const { mutate: deleteBranch, isLoading: isDeleting } = useBranchDeleteMutation({
onSuccess: () => {
+ if (selectedBranchToDelete?.project_ref === ref) {
+ ui.setNotification({
+ category: 'success',
+ message:
+ 'Successfully deleted branch. You are now currently on the main branch of your project.',
+ })
+ router.push(`/project/${projectRef}/branches`)
+ } else {
+ ui.setNotification({ category: 'success', message: 'Successfully deleted branch' })
+ }
setSelectedBranchToDelete(undefined)
- ui.setNotification({ category: 'success', message: 'Successfully deleted branch' })
},
})