11'use client'
22
3- import { useCallback , useEffect , useRef } from 'react'
3+ import { useCallback , useEffect , useRef , useState } from 'react'
44import clsx from 'clsx'
55import { ChevronDown , ChevronRight , Folder , FolderOpen } from 'lucide-react'
6+ import {
7+ AlertDialog ,
8+ AlertDialogAction ,
9+ AlertDialogCancel ,
10+ AlertDialogContent ,
11+ AlertDialogDescription ,
12+ AlertDialogFooter ,
13+ AlertDialogHeader ,
14+ AlertDialogTitle ,
15+ } from '@/components/ui/alert-dialog'
616import { Tooltip , TooltipContent , TooltipTrigger } from '@/components/ui/tooltip'
717import { type FolderTreeNode , useFolderStore } from '@/stores/folders/store'
818import { FolderContextMenu } from '../../folder-context-menu/folder-context-menu'
@@ -27,6 +37,8 @@ export function FolderItem({
2737 onDrop,
2838} : FolderItemProps ) {
2939 const { expandedFolders, toggleExpanded, updateFolderAPI, deleteFolder } = useFolderStore ( )
40+ const [ showDeleteDialog , setShowDeleteDialog ] = useState ( false )
41+ const [ isDeleting , setIsDeleting ] = useState ( false )
3042
3143 const isExpanded = expandedFolders . has ( folder . id )
3244 const updateTimeoutRef = useRef < ReturnType < typeof setTimeout > | undefined > ( undefined )
@@ -69,83 +81,137 @@ export function FolderItem({
6981 }
7082
7183 const handleDelete = async ( folderId : string ) => {
72- if (
73- confirm (
74- `Are you sure you want to delete "${ folder . name } "? Child folders and workflows will be moved to the parent folder.`
75- )
76- ) {
77- try {
78- await deleteFolder ( folderId )
79- } catch ( error ) {
80- console . error ( 'Failed to delete folder:' , error )
81- }
84+ setShowDeleteDialog ( true )
85+ }
86+
87+ const confirmDelete = async ( ) => {
88+ setIsDeleting ( true )
89+ try {
90+ await deleteFolder ( folder . id )
91+ setShowDeleteDialog ( false )
92+ } catch ( error ) {
93+ console . error ( 'Failed to delete folder:' , error )
94+ } finally {
95+ setIsDeleting ( false )
8296 }
8397 }
8498
8599 if ( isCollapsed ) {
86100 return (
87- < Tooltip >
88- < TooltipTrigger asChild >
89- < div
90- className = 'group mx-auto flex h-8 w-8 cursor-pointer items-center justify-center'
91- onDragOver = { onDragOver }
92- onDragLeave = { onDragLeave }
93- onDrop = { onDrop }
94- onClick = { handleToggleExpanded }
95- >
101+ < >
102+ < Tooltip >
103+ < TooltipTrigger asChild >
96104 < div
97- className = { clsx (
98- 'flex h-4 w-4 items-center justify-center rounded transition-colors hover:bg-accent/50' ,
99- dragOver ? 'ring-2 ring-blue-500' : ''
100- ) }
105+ className = 'group mx-auto flex h-8 w-8 cursor-pointer items-center justify-center'
106+ onDragOver = { onDragOver }
107+ onDragLeave = { onDragLeave }
108+ onDrop = { onDrop }
109+ onClick = { handleToggleExpanded }
101110 >
102- { isExpanded ? (
103- < FolderOpen className = 'h-3 w-3 text-foreground/70 dark:text-foreground/60' />
104- ) : (
105- < Folder className = 'h-3 w-3 text-foreground/70 dark:text-foreground/60' />
106- ) }
111+ < div
112+ className = { clsx (
113+ 'flex h-4 w-4 items-center justify-center rounded transition-colors hover:bg-accent/50' ,
114+ dragOver ? 'ring-2 ring-blue-500' : ''
115+ ) }
116+ >
117+ { isExpanded ? (
118+ < FolderOpen className = 'h-3 w-3 text-foreground/70 dark:text-foreground/60' />
119+ ) : (
120+ < Folder className = 'h-3 w-3 text-foreground/70 dark:text-foreground/60' />
121+ ) }
122+ </ div >
107123 </ div >
108- </ div >
109- </ TooltipTrigger >
110- < TooltipContent side = 'right' >
111- < p > { folder . name } </ p >
112- </ TooltipContent >
113- </ Tooltip >
124+ </ TooltipTrigger >
125+ < TooltipContent side = 'right' >
126+ < p > { folder . name } </ p >
127+ </ TooltipContent >
128+ </ Tooltip >
129+
130+ { /* Delete Confirmation Dialog */ }
131+ < AlertDialog open = { showDeleteDialog } onOpenChange = { setShowDeleteDialog } >
132+ < AlertDialogContent >
133+ < AlertDialogHeader >
134+ < AlertDialogTitle > Are you sure you want to delete "{ folder . name } "?</ AlertDialogTitle >
135+ < AlertDialogDescription >
136+ Child folders and workflows will be moved to the parent folder.
137+ </ AlertDialogDescription >
138+ </ AlertDialogHeader >
139+ < AlertDialogFooter >
140+ < AlertDialogCancel disabled = { isDeleting } > Cancel</ AlertDialogCancel >
141+ < AlertDialogAction
142+ onClick = { confirmDelete }
143+ disabled = { isDeleting }
144+ className = 'bg-destructive text-destructive-foreground hover:bg-destructive/90'
145+ >
146+ { isDeleting ? 'Deleting...' : 'Delete' }
147+ </ AlertDialogAction >
148+ </ AlertDialogFooter >
149+ </ AlertDialogContent >
150+ </ AlertDialog >
151+ </ >
114152 )
115153 }
116154
117155 return (
118- < div className = 'group' onDragOver = { onDragOver } onDragLeave = { onDragLeave } onDrop = { onDrop } >
119- < div
120- className = 'flex cursor-pointer items-center rounded-md px-2 py-1.5 text-sm hover:bg-accent/50'
121- onClick = { handleToggleExpanded }
122- >
123- < div className = 'mr-1 flex h-4 w-4 items-center justify-center' >
124- { isExpanded ? < ChevronDown className = 'h-3 w-3' /> : < ChevronRight className = 'h-3 w-3' /> }
125- </ div >
156+ < >
157+ < div className = 'group' onDragOver = { onDragOver } onDragLeave = { onDragLeave } onDrop = { onDrop } >
158+ < div
159+ className = 'flex cursor-pointer items-center rounded-md px-2 py-1.5 text-sm hover:bg-accent/50'
160+ onClick = { handleToggleExpanded }
161+ >
162+ < div className = 'mr-1 flex h-4 w-4 items-center justify-center' >
163+ { isExpanded ? (
164+ < ChevronDown className = 'h-3 w-3' />
165+ ) : (
166+ < ChevronRight className = 'h-3 w-3' />
167+ ) }
168+ </ div >
126169
127- < div className = 'mr-2 flex h-4 w-4 flex-shrink-0 items-center justify-center' >
128- { isExpanded ? (
129- < FolderOpen className = 'h-4 w-4 text-foreground/70 dark:text-foreground/60' />
130- ) : (
131- < Folder className = 'h-4 w-4 text-foreground/70 dark:text-foreground/60' />
132- ) }
133- </ div >
170+ < div className = 'mr-2 flex h-4 w-4 flex-shrink-0 items-center justify-center' >
171+ { isExpanded ? (
172+ < FolderOpen className = 'h-4 w-4 text-foreground/70 dark:text-foreground/60' />
173+ ) : (
174+ < Folder className = 'h-4 w-4 text-foreground/70 dark:text-foreground/60' />
175+ ) }
176+ </ div >
177+
178+ < span className = 'flex-1 cursor-default select-none truncate text-muted-foreground' >
179+ { folder . name }
180+ </ span >
134181
135- < span className = 'flex-1 cursor-default select-none truncate text-muted-foreground' >
136- { folder . name }
137- </ span >
138-
139- < div className = 'flex items-center justify-center' onClick = { ( e ) => e . stopPropagation ( ) } >
140- < FolderContextMenu
141- folderId = { folder . id }
142- folderName = { folder . name }
143- onCreateWorkflow = { onCreateWorkflow }
144- onRename = { handleRename }
145- onDelete = { handleDelete }
146- />
182+ < div className = 'flex items-center justify-center' onClick = { ( e ) => e . stopPropagation ( ) } >
183+ < FolderContextMenu
184+ folderId = { folder . id }
185+ folderName = { folder . name }
186+ onCreateWorkflow = { onCreateWorkflow }
187+ onRename = { handleRename }
188+ onDelete = { handleDelete }
189+ />
190+ </ div >
147191 </ div >
148192 </ div >
149- </ div >
193+
194+ { /* Delete Confirmation Dialog */ }
195+ < AlertDialog open = { showDeleteDialog } onOpenChange = { setShowDeleteDialog } >
196+ < AlertDialogContent >
197+ < AlertDialogHeader >
198+ < AlertDialogTitle > Are you sure you want to delete "{ folder . name } "?</ AlertDialogTitle >
199+ < AlertDialogDescription >
200+ Child folders and workflows will be moved to the parent folder.
201+ </ AlertDialogDescription >
202+ </ AlertDialogHeader >
203+ < AlertDialogFooter >
204+ < AlertDialogCancel disabled = { isDeleting } > Cancel</ AlertDialogCancel >
205+ < AlertDialogAction
206+ onClick = { confirmDelete }
207+ disabled = { isDeleting }
208+ className = 'bg-destructive text-destructive-foreground hover:bg-destructive/90'
209+ >
210+ { isDeleting ? 'Deleting...' : 'Delete' }
211+ </ AlertDialogAction >
212+ </ AlertDialogFooter >
213+ </ AlertDialogContent >
214+ </ AlertDialog >
215+ </ >
150216 )
151217}
0 commit comments