-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: clearing orphaned files (#303)
- Loading branch information
1 parent
2d69cd5
commit 95a1c7f
Showing
3 changed files
with
103 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Button, Checkbox, Group, Modal, Text, Title } from '@mantine/core'; | ||
import { closeAllModals, openConfirmModal } from '@mantine/modals'; | ||
import { showNotification, updateNotification } from '@mantine/notifications'; | ||
import { CheckIcon, CrossIcon } from 'components/icons'; | ||
import useFetch from 'hooks/useFetch'; | ||
|
||
export default function ClearStorage({ open, setOpen, check, setCheck }) { | ||
const handleDelete = async (datasource: boolean, orphaned?: boolean) => { | ||
showNotification({ | ||
id: 'clear-uploads', | ||
title: 'Clearing...', | ||
message: '', | ||
loading: true, | ||
autoClose: false, | ||
}); | ||
|
||
const res = await useFetch('/api/admin/clear', 'POST', { datasource, orphaned }); | ||
|
||
if (res.error) { | ||
updateNotification({ | ||
id: 'clear-uploads', | ||
title: 'Error while clearing uploads', | ||
message: res.error, | ||
color: 'red', | ||
icon: <CrossIcon />, | ||
}); | ||
} else { | ||
updateNotification({ | ||
id: 'clear-uploads', | ||
title: 'Successfully cleared uploads', | ||
message: '', | ||
color: 'green', | ||
icon: <CheckIcon />, | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<Modal | ||
opened={open} | ||
onClose={() => setOpen(false)} | ||
title={<Title size='sm'>Are you sure you want to clear all uploads in the database?</Title>} | ||
> | ||
<Checkbox | ||
id='orphanedFiles' | ||
label='Clear only orphaned files?' | ||
description='Orphaned files are not owned by anyone. They can't be seen the dashboard by anyone.' | ||
checked={check} | ||
onChange={(e) => setCheck(e.currentTarget.checked)} | ||
/> | ||
<Group position='right' mt='md'> | ||
<Button | ||
onClick={() => { | ||
setOpen(() => false); | ||
}} | ||
> | ||
No | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
setOpen(false); | ||
openConfirmModal({ | ||
title: 'Do you want to clear storage too?', | ||
labels: { confirm: 'Yes', cancel: check ? 'Ok' : 'No' }, | ||
children: check && ( | ||
<Text size='sm' color='gray'> | ||
Due to clearing orphaned files, storage clearing will be unavailable. | ||
</Text> | ||
), | ||
confirmProps: { disabled: check }, | ||
onConfirm: () => { | ||
closeAllModals(); | ||
handleDelete(true); | ||
}, | ||
onCancel: () => { | ||
closeAllModals(); | ||
handleDelete(false, check); | ||
}, | ||
onClose: () => setCheck(false), | ||
}); | ||
}} | ||
> | ||
Yes | ||
</Button> | ||
</Group> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters