import { useCallback, useState } from 'react' import { useParams } from 'react-router-dom' import { useDispatch } from 'react-redux' import { Button, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, } from '@chakra-ui/react' import { useSWRConfig } from 'swr' import cx from 'classnames' import FileAPI, { List } from '@/client/api/file' import useFileListSearchParams from '@/hooks/use-file-list-params' import { useAppSelector } from '@/store/hook' import { deleteModalDidClose, selectionUpdated } from '@/store/ui/files' const FileDelete = () => { const { mutate } = useSWRConfig() const { fileId } = useParams() const dispatch = useDispatch() const selection = useAppSelector((state) => state.ui.files.selection) const isModalOpen = useAppSelector( (state) => state.ui.files.isDeleteModalOpen, ) const [loading, setLoading] = useState(false) const fileListSearchParams = useFileListSearchParams() const handleDelete = useCallback(async () => { try { setLoading(true) await FileAPI.batchDelete({ ids: selection }) await mutate(`/files/${fileId}/list?${fileListSearchParams}`) dispatch(selectionUpdated([])) dispatch(deleteModalDidClose()) } finally { setLoading(false) } }, [selection, fileId, fileListSearchParams, mutate, dispatch]) return ( dispatch(deleteModalDidClose())} closeOnOverlayClick={false} > {selection.length > 1 ? ( Delete {selection.length} Item(s) ) : ( Delete Item )} {selection.length > 1 ? ( Are you sure you would like to delete ({selection.length}) item(s)? ) : ( Are you sure you would like to delete this item? )}
) } export default FileDelete