🐛(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

@@ -23,6 +23,7 @@ and this project adheres to
### Fixed ### Fixed
- 🐛(service-worker) Fix useOffline Maximum update depth exceeded #1196 - 🐛(service-worker) Fix useOffline Maximum update depth exceeded #1196
- 🐛(frontend) fix empty left panel after deleting root doc #1197
- 🐛(helm) charts generate invalid YAML for collaboration API / WS #890 - 🐛(helm) charts generate invalid YAML for collaboration API / WS #890
- 🐛(frontend) 401 redirection overridden #1214 - 🐛(frontend) 401 redirection overridden #1214

View File

@@ -15,15 +15,15 @@ import { useRemoveDoc } from '../api/useRemoveDoc';
import { Doc } from '../types'; import { Doc } from '../types';
interface ModalRemoveDocProps { interface ModalRemoveDocProps {
onClose: () => void;
doc: Doc; doc: Doc;
afterDelete?: (doc: Doc) => void; onClose: () => void;
onSuccess?: (doc: Doc) => void;
} }
export const ModalRemoveDoc = ({ export const ModalRemoveDoc = ({
onClose,
doc, doc,
afterDelete, onClose,
onSuccess,
}: ModalRemoveDocProps) => { }: ModalRemoveDocProps) => {
const { toast } = useToastProvider(); const { toast } = useToastProvider();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -35,19 +35,17 @@ export const ModalRemoveDoc = ({
error, error,
} = useRemoveDoc({ } = useRemoveDoc({
onSuccess: () => { onSuccess: () => {
toast(t('The document has been deleted.'), VariantType.SUCCESS, { if (onSuccess) {
duration: 4000, onSuccess(doc);
}); } else if (pathname === '/') {
if (afterDelete) {
afterDelete(doc);
return;
}
if (pathname === '/') {
onClose(); onClose();
} else { } else {
void push('/'); 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) { if (parentId) {
void router.push(`/docs/${parentId}`).then(() => { void router.push(`/docs/${parentId}`).then(() => {
setTimeout(() => { setTimeout(() => {
@@ -133,7 +133,7 @@ export const DocTreeItemActions = ({
}, 100); }, 100);
}); });
} else if (doc.id === treeContext?.root?.id && !parentId) { } else if (doc.id === treeContext?.root?.id && !parentId) {
void router.push(`/docs/`); void router.push(`/`);
} else if (treeContext && treeContext.root) { } else if (treeContext && treeContext.root) {
void router.push(`/docs/${treeContext.root.id}`).then(() => { void router.push(`/docs/${treeContext.root.id}`).then(() => {
setTimeout(() => { setTimeout(() => {
@@ -193,7 +193,7 @@ export const DocTreeItemActions = ({
<ModalRemoveDoc <ModalRemoveDoc
onClose={deleteModal.onClose} onClose={deleteModal.onClose}
doc={doc} doc={doc}
afterDelete={afterDelete} onSuccess={onSuccessDelete}
/> />
)} )}
</Box> </Box>