diff --git a/client/src/features/page/queries/page.ts b/client/src/features/page/queries/page.ts index cc01a0c8..1fa8482e 100644 --- a/client/src/features/page/queries/page.ts +++ b/client/src/features/page/queries/page.ts @@ -7,6 +7,7 @@ import { updatePage, } from '@/features/page/services/page-service'; import { IPage } from '@/features/page/types/page.types'; +import { notifications } from '@mantine/notifications'; const RECENT_CHANGES_KEY = ['recentChanges']; @@ -41,5 +42,8 @@ export function useUpdatePageMutation() { export function useDeletePageMutation() { return useMutation({ mutationFn: (pageId: string) => deletePage(pageId), + onSuccess: () => { + notifications.show({ title: 'Page deleted successfully' }); + }, }); } diff --git a/client/src/features/page/tree/hooks/use-persistence.ts b/client/src/features/page/tree/hooks/use-persistence.ts index 1a7f36be..e40708c2 100644 --- a/client/src/features/page/tree/hooks/use-persistence.ts +++ b/client/src/features/page/tree/hooks/use-persistence.ts @@ -8,16 +8,19 @@ import { } from 'react-arborist'; import { useAtom } from 'jotai'; import { treeDataAtom } from '@/features/page/tree/atoms/tree-data-atom'; -import { createPage, deletePage, movePage } from '@/features/page/services/page-service'; +import { movePage } from '@/features/page/services/page-service'; import { v4 as uuidv4 } from 'uuid'; import { IMovePage } from '@/features/page/types/page.types'; import { useNavigate } from 'react-router-dom'; import { TreeNode } from '@/features/page/tree/types'; -import { useUpdatePageMutation } from '@/features/page/queries/page'; +import { useCreatePageMutation, useDeletePageMutation, useUpdatePageMutation } from '@/features/page/queries/page'; export function usePersistence() { const [data, setData] = useAtom(treeDataAtom); + const createPageMutation = useCreatePageMutation(); const updatePageMutation = useUpdatePageMutation(); + const deletePageMutation = useDeletePageMutation(); + const navigate = useNavigate(); const tree = useMemo(() => new SimpleTree(data), [data]); @@ -75,7 +78,7 @@ export function usePersistence() { } try { - await createPage(payload); + await createPageMutation.mutateAsync(payload); navigate(`/p/${payload.id}`); } catch (error) { console.error('Error creating the page:', error); @@ -89,7 +92,8 @@ export function usePersistence() { setData(tree.data); try { - await deletePage(args.ids[0]); + await deletePageMutation.mutateAsync(args.ids[0]); + navigate('/home'); } catch (error) { console.error('Error deleting page:', error); } diff --git a/client/src/main.tsx b/client/src/main.tsx index 56dd627b..e6506045 100644 --- a/client/src/main.tsx +++ b/client/src/main.tsx @@ -18,7 +18,7 @@ root.render( - + diff --git a/client/src/pages/page/page.tsx b/client/src/pages/page/page.tsx index b8ff467f..f11ffccf 100644 --- a/client/src/pages/page/page.tsx +++ b/client/src/pages/page/page.tsx @@ -20,7 +20,7 @@ export default function Page() { return
Loading...
; } - if (isError) { + if (isError || !data) { // TODO: fix this return
Error fetching page data.
; }