mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 05:27:38 +00:00
feat(ui): add delete confirmation dialog for file list and cards
This commit is contained in:
@@ -5,17 +5,6 @@ import {
|
||||
ContextMenuSeparator,
|
||||
} from '@/ui/components/ui/context-menu'
|
||||
import { Download, Edit, FolderPlus, Trash2, UploadCloud, History, FileText } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '../ui/alert-dialog'
|
||||
|
||||
interface FileBrowserContextMenuProps {
|
||||
item: AssetInfo | null
|
||||
@@ -52,14 +41,11 @@ export function FileBrowserContextMenu({
|
||||
isShareView,
|
||||
onRemoveFromShare,
|
||||
}: FileBrowserContextMenuProps) {
|
||||
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false)
|
||||
|
||||
const allItems = [...folders, ...files]
|
||||
const selectedItems = allItems.filter((i) => selectedIds.has(i.id!))
|
||||
const isItemSelected = item && selectedIds.has(item.id!)
|
||||
const itemsToModify = isItemSelected ? selectedItems : item ? [item] : []
|
||||
const itemsToDelete = itemsToModify
|
||||
const deleteCount = itemsToDelete.length
|
||||
const itemsToRestore = itemsToModify
|
||||
|
||||
const handleRename = () => {
|
||||
@@ -69,7 +55,7 @@ export function FileBrowserContextMenu({
|
||||
}
|
||||
|
||||
const handleDelete = () => {
|
||||
setIsDeleteDialogOpen(true)
|
||||
onDelete(itemsToDelete)
|
||||
}
|
||||
|
||||
const handleDownload = () => {
|
||||
@@ -194,28 +180,6 @@ export function FileBrowserContextMenu({
|
||||
return (
|
||||
<>
|
||||
{contextMenuContent}
|
||||
<AlertDialog open={isDeleteDialogOpen} onOpenChange={setIsDeleteDialogOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
You are about to delete {deleteCount} item(s). Deleted items can be recovered for 30
|
||||
days before being permanently deleted.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => {
|
||||
onDelete(itemsToDelete)
|
||||
setIsDeleteDialogOpen(false)
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,16 @@ import { FileListItem } from './file-list-item'
|
||||
import { FolderCard } from './folder-card'
|
||||
import { Button } from '../ui/button'
|
||||
import { ContextMenu, ContextMenuTrigger } from '../ui/context-menu'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '../ui/alert-dialog'
|
||||
import { useFileActions } from './use-file-actions'
|
||||
|
||||
interface FileBrowserProps {
|
||||
@@ -110,6 +120,9 @@ export function FileBrowser({
|
||||
handleDownload,
|
||||
handleAction,
|
||||
onRenameSubmit,
|
||||
isDeleteDialogOpen,
|
||||
setIsDeleteDialogOpen,
|
||||
confirmDelete,
|
||||
} = useFileActions({
|
||||
teamId,
|
||||
projectId,
|
||||
@@ -680,6 +693,28 @@ export function FileBrowser({
|
||||
onChange={handleFileChange}
|
||||
/>
|
||||
{renderContent()}
|
||||
|
||||
<AlertDialog open={isDeleteDialogOpen} onOpenChange={setIsDeleteDialogOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete Asset?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Deleted items can be recovered for 30 days before being permanently deleted.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => {
|
||||
confirmDelete()
|
||||
}}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ export function useFileActions({
|
||||
selectedIds,
|
||||
}: UseFileActionsProps) {
|
||||
const [editingItemId, setEditingItemId] = useState<string | null>(null)
|
||||
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false)
|
||||
const [itemsToDelete, setItemsToDelete] = useState<AssetInfo[]>([])
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const $createFolder = client.api.teams[':teamId'].folders.$post
|
||||
@@ -113,9 +115,9 @@ export function useFileActions({
|
||||
setEditingItemId(item.id!)
|
||||
}
|
||||
|
||||
const handleDelete = (items: AssetInfo[]) => {
|
||||
const fileIds = items.filter((i) => i.type === 'file').map((i) => i.id!)
|
||||
const folderIds = items.filter((i) => i.type === 'folder').map((i) => i.id!)
|
||||
const confirmDelete = () => {
|
||||
const fileIds = itemsToDelete.filter((i) => i.type === 'file').map((i) => i.id!)
|
||||
const folderIds = itemsToDelete.filter((i) => i.type === 'folder').map((i) => i.id!)
|
||||
|
||||
if (fileIds.length > 0) {
|
||||
deleteFiles(
|
||||
@@ -142,6 +144,14 @@ export function useFileActions({
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
setIsDeleteDialogOpen(false)
|
||||
setItemsToDelete([])
|
||||
}
|
||||
|
||||
const handleDelete = (items: AssetInfo[]) => {
|
||||
setItemsToDelete(items)
|
||||
setIsDeleteDialogOpen(true)
|
||||
}
|
||||
|
||||
const handleRestore = (items: AssetInfo[]) => {
|
||||
@@ -269,5 +279,9 @@ export function useFileActions({
|
||||
handleNewFolder,
|
||||
handleAction,
|
||||
onRenameSubmit,
|
||||
isDeleteDialogOpen,
|
||||
setIsDeleteDialogOpen,
|
||||
itemsToDelete,
|
||||
confirmDelete,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user