@@ -180,9 +180,14 @@ const PreviewBranchActions = ({
180180
181181 const { data } = useBranchQuery ( { projectRef, branchRef } )
182182 const isBranchActiveHealthy = data ?. status === 'ACTIVE_HEALTHY'
183+ const isPersistentBranch = branch . persistent
183184
184185 const [ showConfirmResetModal , setShowConfirmResetModal ] = useState ( false )
185186 const [ showBranchModeSwitch , setShowBranchModeSwitch ] = useState ( false )
187+ const [
188+ showPersistentBranchDeleteConfirmationModal ,
189+ setShowPersistentBranchDeleteConfirmationModal ,
190+ ] = useState ( false )
186191 const [ showEditBranchModal , setShowEditBranchModal ] = useState ( false )
187192
188193 const { mutate : resetBranch , isLoading : isResetting } = useBranchResetMutation ( {
@@ -210,6 +215,15 @@ const PreviewBranchActions = ({
210215 updateBranch ( { branchRef, projectRef, persistent : ! branch . persistent } )
211216 }
212217
218+ const onDeleteBranch = ( e : Event | React . MouseEvent < HTMLDivElement > ) => {
219+ if ( isPersistentBranch ) {
220+ setShowPersistentBranchDeleteConfirmationModal ( true )
221+ } else {
222+ e . stopPropagation ( )
223+ onSelectDeleteBranch ( )
224+ }
225+ }
226+
213227 return (
214228 < >
215229 < DropdownMenu >
@@ -307,14 +321,8 @@ const PreviewBranchActions = ({
307321 < DropdownMenuItemTooltip
308322 className = "gap-x-2"
309323 disabled = { ! canDeleteBranches }
310- onSelect = { ( e ) => {
311- e . stopPropagation ( )
312- onSelectDeleteBranch ( )
313- } }
314- onClick = { ( e ) => {
315- e . stopPropagation ( )
316- onSelectDeleteBranch ( )
317- } }
324+ onSelect = { onDeleteBranch }
325+ onClick = { onDeleteBranch }
318326 tooltip = { {
319327 content : {
320328 side : 'left' ,
@@ -373,6 +381,20 @@ const PreviewBranchActions = ({
373381 </ p >
374382 </ ConfirmationModal >
375383
384+ < ConfirmationModal
385+ variant = "warning"
386+ visible = { showPersistentBranchDeleteConfirmationModal }
387+ confirmLabel = { 'Switch to preview' }
388+ title = "Branch must be switched to preview before deletion"
389+ loading = { isUpdatingBranch }
390+ onCancel = { ( ) => setShowPersistentBranchDeleteConfirmationModal ( false ) }
391+ onConfirm = { onTogglePersistent }
392+ >
393+ < p className = "text-sm text-foreground-light" >
394+ You must switch the branch "{ branch . name } " to preview before deleting it.
395+ </ p >
396+ </ ConfirmationModal >
397+
376398 < EditBranchModal
377399 branch = { branch }
378400 visible = { showEditBranchModal }
0 commit comments