11import Link from 'next/link' ;
2- import { Button , Dialog } from '@headlessui/react' ;
3- import { Transition , TransitionChild , DialogPanel , DialogTitle } from '@headlessui/react' ;
4- import { Fragment , useState } from 'react' ;
2+ import { Button } from '@headlessui/react' ;
3+ import { Transition } from '@headlessui/react' ;
4+ import { useState } from 'react' ;
55import { useDocuments } from '@/contexts/DocumentContext' ;
66import { PDFIcon , EPUBIcon } from '@/components/icons/Icons' ;
7+ import { ConfirmDialog } from '@/components/ConfirmDialog' ;
78
89type DocumentToDelete = {
910 id : string ;
@@ -21,7 +22,6 @@ export function DocumentList() {
2122 isEPUBLoading,
2223 } = useDocuments ( ) ;
2324
24- const [ isDeleteDialogOpen , setIsDeleteDialogOpen ] = useState ( false ) ;
2525 const [ documentToDelete , setDocumentToDelete ] = useState < DocumentToDelete | null > ( null ) ;
2626
2727 const handleDelete = async ( ) => {
@@ -33,7 +33,6 @@ export function DocumentList() {
3333 } else {
3434 await removeEPUB ( documentToDelete . id ) ;
3535 }
36- setIsDeleteDialogOpen ( false ) ;
3736 setDocumentToDelete ( null ) ;
3837 } catch ( err ) {
3938 console . error ( 'Failed to remove document:' , err ) ;
@@ -101,10 +100,7 @@ export function DocumentList() {
101100 </ div >
102101 </ Link >
103102 < Button
104- onClick = { ( ) => {
105- setDocumentToDelete ( { id : doc . id , name : doc . name , type : doc . type } ) ;
106- setIsDeleteDialogOpen ( true ) ;
107- } }
103+ onClick = { ( ) => setDocumentToDelete ( { id : doc . id , name : doc . name , type : doc . type } ) }
108104 className = "ml-4 p-2 text-muted hover:text-red-500 rounded-lg hover:bg-red-50 transition-colors"
109105 aria-label = "Delete document"
110106 >
@@ -117,70 +113,15 @@ export function DocumentList() {
117113 ) ) }
118114 </ div >
119115
120- < Transition appear show = { isDeleteDialogOpen } as = { Fragment } >
121- < Dialog
122- as = "div"
123- className = "relative z-50"
124- onClose = { ( ) => setIsDeleteDialogOpen ( false ) }
125- >
126- < TransitionChild
127- as = { Fragment }
128- enter = "ease-out duration-300"
129- enterFrom = "opacity-0"
130- enterTo = "opacity-100"
131- leave = "ease-in duration-200"
132- leaveFrom = "opacity-100"
133- leaveTo = "opacity-0"
134- >
135- < div className = "fixed inset-0 bg-black bg-opacity-25" />
136- </ TransitionChild >
137-
138- < div className = "fixed inset-0 overflow-y-auto" >
139- < div className = "flex min-h-full items-center justify-center p-4 text-center" >
140- < TransitionChild
141- as = { Fragment }
142- enter = "ease-out duration-300"
143- enterFrom = "opacity-0 scale-95"
144- enterTo = "opacity-100 scale-100"
145- leave = "ease-in duration-200"
146- leaveFrom = "opacity-100 scale-100"
147- leaveTo = "opacity-0 scale-95"
148- >
149- < DialogPanel className = "w-full max-w-md transform overflow-hidden rounded-2xl bg-background p-6 text-left align-middle shadow-xl transition-all" >
150- < DialogTitle
151- as = "h3"
152- className = "text-lg font-medium leading-6 text-foreground"
153- >
154- Delete Document
155- </ DialogTitle >
156- < div className = "mt-2" >
157- < p className = "text-sm text-muted" >
158- Are you sure you want to delete < span className = 'font-bold' > { documentToDelete ?. name } </ span > ? This action cannot be undone.
159- </ p >
160- </ div >
161-
162- < div className = "mt-4 flex justify-end space-x-3" >
163- < Button
164- type = "button"
165- className = "inline-flex justify-center rounded-md border border-transparent bg-base px-4 py-2 text-sm font-medium text-foreground hover:bg-base/80 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2"
166- onClick = { ( ) => setIsDeleteDialogOpen ( false ) }
167- >
168- Cancel
169- </ Button >
170- < Button
171- type = "button"
172- className = "inline-flex justify-center rounded-md border border-transparent bg-red-600 px-4 py-2 text-sm font-medium text-white hover:bg-red-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-red-500 focus-visible:ring-offset-2"
173- onClick = { handleDelete }
174- >
175- Delete
176- </ Button >
177- </ div >
178- </ DialogPanel >
179- </ TransitionChild >
180- </ div >
181- </ div >
182- </ Dialog >
183- </ Transition >
116+ < ConfirmDialog
117+ isOpen = { documentToDelete !== null }
118+ onClose = { ( ) => setDocumentToDelete ( null ) }
119+ onConfirm = { handleDelete }
120+ title = "Delete Document"
121+ message = { `Are you sure you want to delete ${ documentToDelete ?. name ? documentToDelete . name : 'this document' } ? This action cannot be undone.` }
122+ confirmText = "Delete"
123+ isDangerous = { true }
124+ />
184125 </ div >
185126 ) ;
186127}
0 commit comments