🐛(frontend) fix empty left panel after deleting root doc

When we were deleting a root document, the left panel
was getting empty. It was because the panel thought that
it was a child document and was trying clear
dynamically the panel.
Now, we are checking if the document is a root or not,
if it is a root we just redirect to the homepage.
This commit is contained in:
Anthony LC
2025-07-25 12:55:29 +02:00
parent 3ff6d2541c
commit 8c9380c356
3 changed files with 15 additions and 16 deletions

View File

@@ -15,15 +15,15 @@ import { useRemoveDoc } from '../api/useRemoveDoc';
import { Doc } from '../types';
interface ModalRemoveDocProps {
onClose: () => void;
doc: Doc;
afterDelete?: (doc: Doc) => void;
onClose: () => void;
onSuccess?: (doc: Doc) => void;
}
export const ModalRemoveDoc = ({
onClose,
doc,
afterDelete,
onClose,
onSuccess,
}: ModalRemoveDocProps) => {
const { toast } = useToastProvider();
const { t } = useTranslation();
@@ -35,19 +35,17 @@ export const ModalRemoveDoc = ({
error,
} = useRemoveDoc({
onSuccess: () => {
toast(t('The document has been deleted.'), VariantType.SUCCESS, {
duration: 4000,
});
if (afterDelete) {
afterDelete(doc);
return;
}
if (pathname === '/') {
if (onSuccess) {
onSuccess(doc);
} else if (pathname === '/') {
onClose();
} else {
void push('/');
}
toast(t('The document has been deleted.'), VariantType.SUCCESS, {
duration: 4000,
});
},
});

View File

@@ -125,7 +125,7 @@ export const DocTreeItemActions = ({
},
});
const afterDelete = () => {
const onSuccessDelete = () => {
if (parentId) {
void router.push(`/docs/${parentId}`).then(() => {
setTimeout(() => {
@@ -133,7 +133,7 @@ export const DocTreeItemActions = ({
}, 100);
});
} else if (doc.id === treeContext?.root?.id && !parentId) {
void router.push(`/docs/`);
void router.push(`/`);
} else if (treeContext && treeContext.root) {
void router.push(`/docs/${treeContext.root.id}`).then(() => {
setTimeout(() => {
@@ -193,7 +193,7 @@ export const DocTreeItemActions = ({
<ModalRemoveDoc
onClose={deleteModal.onClose}
doc={doc}
afterDelete={afterDelete}
onSuccess={onSuccessDelete}
/>
)}
</Box>