()
| 28 | // ==============================|| CHATFLOWS ||============================== // |
| 29 | |
| 30 | const Files = () => { |
| 31 | const { confirm } = useConfirm() |
| 32 | |
| 33 | const [isLoading, setLoading] = useState(true) |
| 34 | const { error, setError } = useError() |
| 35 | const [files, setFiles] = useState([]) |
| 36 | const [search, setSearch] = useState('') |
| 37 | |
| 38 | const getAllFilesApi = useApi(filesApi.getAllFiles) |
| 39 | |
| 40 | const dispatch = useDispatch() |
| 41 | |
| 42 | useNotifier() |
| 43 | const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args)) |
| 44 | const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args)) |
| 45 | |
| 46 | const onSearchChange = (event) => { |
| 47 | setSearch(event.target.value) |
| 48 | } |
| 49 | |
| 50 | function filterFiles(data) { |
| 51 | return ( |
| 52 | data.name.toLowerCase().indexOf(search.toLowerCase()) > -1 || |
| 53 | (data.category && data.category.toLowerCase().indexOf(search.toLowerCase()) > -1) |
| 54 | ) |
| 55 | } |
| 56 | |
| 57 | const handleDeleteFile = async (file) => { |
| 58 | const confirmPayload = { |
| 59 | title: `Delete`, |
| 60 | description: `Delete ${file.name}? This process cannot be undone.`, |
| 61 | confirmButtonName: 'Delete', |
| 62 | cancelButtonName: 'Cancel' |
| 63 | } |
| 64 | const isConfirmed = await confirm(confirmPayload) |
| 65 | |
| 66 | if (isConfirmed) { |
| 67 | try { |
| 68 | const deleteResponse = await filesApi.deleteFile(file.path) |
| 69 | if (deleteResponse?.data) { |
| 70 | enqueueSnackbar({ |
| 71 | message: 'File deleted', |
| 72 | options: { |
| 73 | key: new Date().getTime() + Math.random(), |
| 74 | variant: 'success', |
| 75 | action: (key) => ( |
| 76 | <Button style={{ color: 'white' }} onClick={() => closeSnackbar(key)}> |
| 77 | <IconX /> |
| 78 | </Button> |
| 79 | ) |
| 80 | } |
| 81 | }) |
| 82 | } |
| 83 | await getAllFilesApi.request() |
| 84 | } catch (error) { |
| 85 | setError(error) |
| 86 | enqueueSnackbar({ |
| 87 | message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data, |
nothing calls this directly
no test coverage detected