Skip to content

Commit 5af1da5

Browse files
committed
fixup! ✨(frontend) doc page when deleted
1 parent 84ce4f1 commit 5af1da5

File tree

7 files changed

+49
-21
lines changed

7 files changed

+49
-21
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/styles.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const cssEditor = (readonly: boolean, isDeletedDoc: boolean) => css`
130130
131131
${isDeletedDoc &&
132132
`
133-
a {
133+
.node-interlinkingLinkInline button {
134134
pointer-events: none;
135135
}
136136
`}

src/frontend/apps/impress/src/features/docs/doc-header/components/AlertRestore.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ export const AlertRestore = ({ doc }: { doc: Doc }) => {
8282
$gap="0.2rem"
8383
$theme="danger"
8484
$variation="600"
85+
$align="center"
8586
>
8687
<Icon
8788
iconName="undo"
8889
$theme="danger"
8990
$variation="600"
90-
$css="font-size: 18px !important;"
91+
$size="18px"
9192
variant="symbols-outlined"
9293
/>
9394
<Text $theme="danger" $variation="600" $size="s">

src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => {
153153
},
154154
},
155155
{
156-
label: t('Delete document'),
156+
label: t('Delete'),
157157
icon: 'delete',
158158
disabled: !doc.abilities.destroy,
159159
callback: () => {
@@ -238,7 +238,26 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => {
238238
<ModalExport onClose={() => setIsModalExportOpen(false)} doc={doc} />
239239
)}
240240
{isModalRemoveOpen && (
241-
<ModalRemoveDoc onClose={() => setIsModalRemoveOpen(false)} doc={doc} />
241+
<ModalRemoveDoc
242+
onClose={() => setIsModalRemoveOpen(false)}
243+
doc={doc}
244+
onSuccess={() => {
245+
const isTopParent = doc.id === treeContext?.root?.id;
246+
const parentId =
247+
treeContext?.treeData.getParentId(doc.id) ||
248+
treeContext?.root?.id;
249+
250+
if (isTopParent) {
251+
void router.push(`/`);
252+
} else if (parentId) {
253+
void router.push(`/docs/${parentId}`).then(() => {
254+
setTimeout(() => {
255+
treeContext?.treeData.deleteNode(doc.id);
256+
}, 100);
257+
});
258+
}
259+
}}
260+
/>
242261
)}
243262
{selectHistoryModal.isOpen && (
244263
<ModalSelectVersion

src/frontend/apps/impress/src/features/docs/doc-management/components/ModalRemoveDoc.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
VariantType,
66
useToastProvider,
77
} from '@openfun/cunningham-react';
8-
import { usePathname } from 'next/navigation';
98
import { useRouter } from 'next/router';
109
import { Trans, useTranslation } from 'react-i18next';
1110

@@ -30,7 +29,6 @@ export const ModalRemoveDoc = ({
3029
const { toast } = useToastProvider();
3130
const { t } = useTranslation();
3231
const { push } = useRouter();
33-
const pathname = usePathname();
3432
const {
3533
mutate: removeDoc,
3634
isError,
@@ -41,12 +39,12 @@ export const ModalRemoveDoc = ({
4139
onSuccess: () => {
4240
if (onSuccess) {
4341
onSuccess(doc);
44-
} else if (pathname === '/') {
45-
onClose();
4642
} else {
4743
void push('/');
4844
}
4945

46+
onClose();
47+
5048
toast(t('The document has been deleted.'), VariantType.SUCCESS, {
5149
duration: 4000,
5250
});
Lines changed: 11 additions & 2 deletions
Loading

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocSubPageItem.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const DocSubPageItem = (props: TreeViewNodeProps<Doc>) => {
3939
const treeContext = useTreeContext<Doc>();
4040
const { untitledDocument } = useTrans();
4141
const { node } = props;
42-
const { spacingsTokens } = useCunninghamTheme();
42+
const { spacingsTokens, colorsTokens } = useCunninghamTheme();
4343
const { isDesktop } = useResponsiveStore();
4444
const { t } = useTranslation();
4545

@@ -166,7 +166,11 @@ export const DocSubPageItem = (props: TreeViewNodeProps<Doc>) => {
166166
`}
167167
>
168168
<Box $width="16px" $height="16px">
169-
<DocIcon emoji={emoji} defaultIcon={<SubPageIcon />} $size="sm" />
169+
<DocIcon
170+
emoji={emoji}
171+
defaultIcon={<SubPageIcon color={colorsTokens['primary-400']} />}
172+
$size="sm"
173+
/>
170174
</Box>
171175

172176
<Box

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocTreeItemActions.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,13 @@ export const DocTreeItemActions = ({
126126
});
127127

128128
const onSuccessDelete = () => {
129-
if (parentId) {
130-
void router.push(`/docs/${parentId}`).then(() => {
131-
setTimeout(() => {
132-
treeContext?.treeData.deleteNode(doc.id);
133-
}, 100);
134-
});
135-
} else if (doc.id === treeContext?.root?.id && !parentId) {
129+
const isTopParent = doc.id === treeContext?.root?.id && !parentId;
130+
const parentIdComputed = parentId || treeContext?.root?.id;
131+
132+
if (isTopParent) {
136133
void router.push(`/`);
137-
} else if (treeContext && treeContext.root) {
138-
void router.push(`/docs/${treeContext.root.id}`).then(() => {
134+
} else if (parentIdComputed) {
135+
void router.push(`/docs/${parentIdComputed}`).then(() => {
139136
setTimeout(() => {
140137
treeContext?.treeData.deleteNode(doc.id);
141138
}, 100);

0 commit comments

Comments
 (0)