43 lines
2.7 KiB
JavaScript
43 lines
2.7 KiB
JavaScript
import { Button } from '@/components/ui/button'
|
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
|
import { Eye, Download, Share2, Pencil, FolderInput, Trash2, RotateCcw } from 'lucide-react'
|
|
|
|
const ActionButton = ({ icon: Icon, children, destructive = false, ...props }) => (
|
|
<Button variant="outline" className={`w-full min-w-0 justify-start gap-2 px-3 ${destructive ? 'text-destructive' : ''}`} {...props}>
|
|
<Icon className="size-4 shrink-0" /><span className="truncate">{children}</span>
|
|
</Button>
|
|
)
|
|
|
|
export default function ItemActionsDialog({ controller: c }) {
|
|
const { modal, setModal, action, handleAction, isTrash, view } = c
|
|
const rights = new Set(action?.permissions || [])
|
|
return (
|
|
<Dialog open={modal === 'actions'} onOpenChange={open => { if (!open) setModal(null) }}>
|
|
<DialogContent className="w-[calc(100vw-2rem)] max-h-[85dvh] min-w-0 overflow-y-auto sm:max-w-md">
|
|
<DialogHeader className="min-w-0 pr-9">
|
|
<DialogTitle className="min-w-0 break-all text-base leading-snug">{action?.name || 'Actions'}</DialogTitle>
|
|
<DialogDescription>Choisir une action sur cet élément.</DialogDescription>
|
|
</DialogHeader>
|
|
<div className="grid min-w-0 grid-cols-1 gap-2 min-[400px]:grid-cols-2">
|
|
{action && <>
|
|
{!isTrash && <ActionButton icon={Eye} onClick={() => handleAction('open')}>Ouvrir</ActionButton>}
|
|
{!action.is_folder && rights.has('download') && <ActionButton icon={Download} onClick={() => handleAction('download')}>Télécharger</ActionButton>}
|
|
{!isTrash && rights.has('share') && <ActionButton icon={Share2} onClick={() => handleAction('share')}>Partager</ActionButton>}
|
|
{!isTrash && rights.has('modify') && <>
|
|
<ActionButton icon={Pencil} onClick={() => handleAction('rename')}>Renommer</ActionButton>
|
|
<ActionButton icon={FolderInput} onClick={() => handleAction('move')}>Déplacer</ActionButton>
|
|
</>}
|
|
{!isTrash && view === 'shared' && action.share_root_id && <ActionButton icon={Trash2} destructive onClick={() => handleAction('remove-share')}>Retirer de mes partages</ActionButton>}
|
|
{!isTrash && view !== 'shared' && rights.has('delete') && <ActionButton icon={Trash2} destructive onClick={() => handleAction('trash')}>Corbeille</ActionButton>}
|
|
{rights.has('delete') && isTrash && <>
|
|
<ActionButton icon={RotateCcw} onClick={() => handleAction('restore')}>Restaurer</ActionButton>
|
|
<ActionButton icon={Trash2} destructive onClick={() => handleAction('confirmdelete')}>Supprimer</ActionButton>
|
|
</>}
|
|
</>}
|
|
</div>
|
|
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|